Module markov.api.models.artifacts.base

Functions

def construct_df_from_sample_and_schema(sample, schema)

Construct a DataFrame using the given sample and schema.

Args

sample : str
The sample string.
schema : List[MarkovModelArtifactColumnSchema]
The schema for the DataFrame.

Returns

pd.DataFrame
The constructed DataFrame.
def infer_schema_and_samples_from_dataframe(df: pandas.core.frame.DataFrame)

Infer the column schema and construct samples for a Markov model artifact from a pandas DataFrame. Schema defines the name and type of columns used as input for the model artifact. Samples is a list of sample inputs for the model artifact. Multi-column samples are stored as csv_strings. For example let us say we are doing weather production where the input is: Humidity: 0.8 AirTemperature: 27.2 PreviousDayRainfall: 312 OtherSourcePrediction: "Rainfall"

Then schema will look like the following: [ {feature_name: "Humidity", feature_type: FP32}, {feature_name: "AirTemperature", feature_type: FP32}, {feature_name: "PreviousDayRainfall", feature_type: INT32}, {feature_name: "OtherSourcePrediction", feature_type: BYTES}, ]

The sample will look like the following: ['0.8,27.2,312,"Rainfall"']

Args

df : pd.DataFrame
The input pandas DataFrame for which the schema is to be inferred.

Returns

Tuple[List[MarkovModelArtifactColumnSchema], List]: - A list of MarkovModelArtifactColumnSchema representing the inferred column schema. - A list of samples for the model artifact. A maximum of 5 samples will be returned.

Classes

class MarkovBaseModelArtifact (name: str, schema=None, samples=None)

The Base class for implementing Model Artifacts in Markov. This class provides the framework to create model artifacts that can be peristed with Markov to: 1. Run as model apps 2. Load it later in client environment through markov python SDK

The model artifact contains references to: - Schema required to run the model - Sample inputs for the model - Dependent Code: The code paths that need to be initialized (run) to make sure the model can be deserialized in a separate environment - Pip requirements: The requirements needed to be installed to run the model

This class is built based on builder pattern

Ancestors

  • abc.ABC

Subclasses

Methods

def add_dependent_code(self, code_paths: List[str])

Add paths to dependent code that need to be initialized (run) to ensure the model can be deserialized in a separate environment. This method facilitates the inclusion of additional code dependencies required by the model artifact.

Args

code_paths : List[str]
List of paths to dependent code that needs to be initialized.

Returns

MarkovBaseModelArtifact
Returns the instance of the MarkovBaseModelArtifact for method chaining.
def add_pip_requirements(self, pip_requirements: List[str])

Add Pip requirements needed to run the model. Pip requirements are the external Python packages that need to be installed to ensure the proper execution of the model artifact. This method allows the user to specify and include additional requirements for the model.

Args

pip_requirements : List[str]
List of Pip requirements needed to run the model.

Returns

MarkovBaseModelArtifact
Returns the instance of the MarkovBaseModelArtifact for method chaining.
def add_sample(self, sample)
def add_samples(self, samples)
def add_schema(self, schema)
def register(self, model_id: str)

Register a virtual subclass of an ABC.

Returns the subclass, to allow usage as a class decorator.

def save(self)
class MarkovPredictor (name: str, model: Any, flavour: MarkovSupportedFlavours)

MarkovPredictor(name: str, model: Any, flavour: markov.api.models.artifacts.base.MarkovSupportedFlavours)

Class variables

var flavourMarkovSupportedFlavours
var model : Any
var name : str
class MarkovPyfunc (name: str, pyfunc: Any, additional_kwargs: Dict[str, Any] = None, code_paths: List[str] = None)

MarkovPyfunc(name: str, pyfunc: Any, additional_kwargs: Dict[str, Any] = None, code_paths: List[str] = None)

Class variables

var additional_kwargs : Dict[str, Any]
var code_paths : List[str]
var name : str
var pyfunc : Any
class MarkovSupportedFlavours (value, names=None, *, module=None, qualname=None, type=None, start=1)

An enumeration.

Ancestors

  • builtins.str
  • enum.Enum

Class variables

var LIGHTGBM : Final
var PYTORCH : Final
var SKLEARN : Final
var XGBOOST : Final
class MarkovTransformer (name: str, transformer: Any, flavour: MarkovSupportedFlavours)

MarkovTransformer(name: str, transformer: Any, flavour: markov.api.models.artifacts.base.MarkovSupportedFlavours)

Class variables

var flavourMarkovSupportedFlavours
var name : str
var transformer : Any