quartic_sdk.model.tests

Submodules

Package Contents

Classes

Base

The base class which is used for creating all the required instances

BaseQuarticModel

A Base Class Model for Wrapping User Models into Quartic Deployments.

SupportedModel

Example Model used for testing model

ModelThatReturnsList

Example Model used for testing model

ModelThatReturnsNone

Example Model used for testing model

ModelThatReturnsString

Example Model used for testing model

SlowModel

Example Model used for testing model

ModelWithLog

Example Model used for testing model

ModelWithValidWindow

A Base Class Model for Wrapping User Models into Quartic Deployments.

ModelWithInValidWindow

A Base Class Model for Wrapping User Models into Quartic Deployments.

MockLoggingHandler

Mock logging handler to check for expected logs.

SupportedSpectralModel

Example Model used for testing spectral model

SpectralModelThatReturnsString

Example Model used for testing spectral model

SlowSpectralModel

Example Model used for testing spectral model

class quartic_sdk.model.tests.Base(body_json, api_helper)

The base class which is used for creating all the required instances of specific types

get(self, name)

Return the value of the given name attribute :param name: (string) The attribute name to be returned :return: The returned attribute value

__str__(self)

Return the stringifed version of the representation

__eq__(self, other)

Override equals to check equality of all attributes :param other: The other object, to which we are comparing :return: (bool) Whether they are equal

class quartic_sdk.model.tests.BaseQuarticModel(name: str, description: str = '', log_level: str = 'INFO')

A Base Class Model for Wrapping User Models into Quartic Deployments. User needs to inherit this class and override the predict method with all the post model training steps such as, preprocessing, prediction, postprocessing the pandas dataframe passed to :func: predict during real time prediction.

Note: Please do not overwrite method :func: save as it contains utilities to validate and deploy model to the Quartic AI Platform

name : Name of the model to be saved in Quartic AI Platform description : Description of the current model log_level : Log Level for logs created/executed during run time i.e. during real time predictions

name : Name of the model to be saved in Quartic AI Platform description : description of model log_level : Log level log : Logger instance which can be used to set run time logs ex: self.log.info(“Example Log”)

save : private save method to save deploy model to the Quartic AI Platform predict : abstract predict method which needs to overridden

class MyModel(BaseQuarticModel):
def __init__(self, model):

self.model = model super().__init__(‘MyModel’, ‘model description’, ‘INFO’)

def preprocess(self, input_df):

transformed_df = custom_transform(input_df) return transformed_df

def postprocess(self, input_df):

transformed_df = custom_transform_post(input_df) return transformed_df

def predict(self, input_df):

pre_transformed_df = self.preprocess(input_df) prediction_df = self.model.predict(pre_transformed_df) self.log.info(“Test Log”) return postprocess(prediction_df)[‘output_column’] # pandas Series

lr = LinearRegression() lr.train(input_data) my_model = MyModel(lr) my_model.save(‘my_model_output’, [Tag(‘A’), Tag(‘B’)], Tag(‘C’), input_data, None)

save(self, client, output_tag_name: str, feature_tags: List[int], target_tag: int, test_df: pandas.DataFrame, ml_node: int = None)
Parameters
  • client – Quartic APIClient

  • output_tag_name – name for Prediction output tag

  • feature_tags – Feature Tag ids used in the model

  • target_tag – Target tag id to specify the parent of current soft tag

  • test_df – Test input dataframe to validate input and prediction output in agreement with Quartic AI Platform

  • ml_node – Optional - Ml Node Id if deployment of model needs to be done to specific node

Returns

None on successfully storing the model to the Quartic AI Platform

abstract predict(self, input_df: pandas.DataFrame)pandas.Series

Abstract method for custom predict method :param input_df: Input Data frame for prediction :return: Returns pd

with_window(duration)

This is decorator method for window support User can decorate predict method with this decorator for window support :param duration: window duration in sec :return: None

moving_window_predict(self, input_df: pandas.DataFrame, previous_df: pandas.DataFrame)

This method calls predict for with window model along with respective window data for each row in input_df. :param input_df: input dataframe :param previous_df: previous dataframe for with window model :return: pandas series of predictions along with timestamps respective to input_df records

class quartic_sdk.model.tests.SupportedModel

Bases: quartic_sdk.model.BaseQuarticModel.BaseQuarticModel

Example Model used for testing model This is a valid model that can be save to quartic platform

predict(self, input_df: pandas.DataFrame)pandas.Series

Abstract method for custom predict method :param input_df: Input Data frame for prediction :return: Returns pd

class quartic_sdk.model.tests.ModelThatReturnsList

Bases: quartic_sdk.model.BaseQuarticModel.BaseQuarticModel

Example Model used for testing model This is a valid model that can be save to quartic platform

predict(self, input_df: pandas.DataFrame)pandas.Series

Abstract method for custom predict method :param input_df: Input Data frame for prediction :return: Returns pd

class quartic_sdk.model.tests.ModelThatReturnsNone

Bases: quartic_sdk.model.BaseQuarticModel.BaseQuarticModel

Example Model used for testing model This is a valid model that can be save to quartic platform

predict(self, input_df: pandas.DataFrame)pandas.Series

Abstract method for custom predict method :param input_df: Input Data frame for prediction :return: Returns pd

class quartic_sdk.model.tests.ModelThatReturnsString

Bases: quartic_sdk.model.BaseQuarticModel.BaseQuarticModel

Example Model used for testing model This is a invalid model whose predict function returns data of type string

post_transform(self, data)
predict(self, input_df: pandas.DataFrame)pandas.Series

Abstract method for custom predict method :param input_df: Input Data frame for prediction :return: Returns pd

class quartic_sdk.model.tests.SlowModel

Bases: quartic_sdk.model.BaseQuarticModel.BaseQuarticModel

Example Model used for testing model This is a invalid model whose predict function takes longer processing time than that is supported by Quartic

pre_transform(self, df)

A simple transformation that sleeps for x secs before returning same

predict(self, input_df: pandas.DataFrame)pandas.Series

sample prediction

class quartic_sdk.model.tests.ModelWithLog

Bases: quartic_sdk.model.BaseQuarticModel.BaseQuarticModel

Example Model used for testing model This is a invalid model whose predict function takes longer processing time than that is supported by Quartic

predict(self, input_df: pandas.DataFrame)pandas.Series

sample prediction

class quartic_sdk.model.tests.ModelWithValidWindow

Bases: quartic_sdk.model.BaseQuarticModel.BaseQuarticModel

A Base Class Model for Wrapping User Models into Quartic Deployments. User needs to inherit this class and override the predict method with all the post model training steps such as, preprocessing, prediction, postprocessing the pandas dataframe passed to :func: predict during real time prediction.

Note: Please do not overwrite method :func: save as it contains utilities to validate and deploy model to the Quartic AI Platform

name : Name of the model to be saved in Quartic AI Platform description : Description of the current model log_level : Log Level for logs created/executed during run time i.e. during real time predictions

name : Name of the model to be saved in Quartic AI Platform description : description of model log_level : Log level log : Logger instance which can be used to set run time logs ex: self.log.info(“Example Log”)

save : private save method to save deploy model to the Quartic AI Platform predict : abstract predict method which needs to overridden

class MyModel(BaseQuarticModel):
def __init__(self, model):

self.model = model super().__init__(‘MyModel’, ‘model description’, ‘INFO’)

def preprocess(self, input_df):

transformed_df = custom_transform(input_df) return transformed_df

def postprocess(self, input_df):

transformed_df = custom_transform_post(input_df) return transformed_df

def predict(self, input_df):

pre_transformed_df = self.preprocess(input_df) prediction_df = self.model.predict(pre_transformed_df) self.log.info(“Test Log”) return postprocess(prediction_df)[‘output_column’] # pandas Series

lr = LinearRegression() lr.train(input_data) my_model = MyModel(lr) my_model.save(‘my_model_output’, [Tag(‘A’), Tag(‘B’)], Tag(‘C’), input_data, None)

predict(self, input_df: pandas.DataFrame)pandas.Series

sample prediction

class quartic_sdk.model.tests.ModelWithInValidWindow

Bases: quartic_sdk.model.BaseQuarticModel.BaseQuarticModel

A Base Class Model for Wrapping User Models into Quartic Deployments. User needs to inherit this class and override the predict method with all the post model training steps such as, preprocessing, prediction, postprocessing the pandas dataframe passed to :func: predict during real time prediction.

Note: Please do not overwrite method :func: save as it contains utilities to validate and deploy model to the Quartic AI Platform

name : Name of the model to be saved in Quartic AI Platform description : Description of the current model log_level : Log Level for logs created/executed during run time i.e. during real time predictions

name : Name of the model to be saved in Quartic AI Platform description : description of model log_level : Log level log : Logger instance which can be used to set run time logs ex: self.log.info(“Example Log”)

save : private save method to save deploy model to the Quartic AI Platform predict : abstract predict method which needs to overridden

class MyModel(BaseQuarticModel):
def __init__(self, model):

self.model = model super().__init__(‘MyModel’, ‘model description’, ‘INFO’)

def preprocess(self, input_df):

transformed_df = custom_transform(input_df) return transformed_df

def postprocess(self, input_df):

transformed_df = custom_transform_post(input_df) return transformed_df

def predict(self, input_df):

pre_transformed_df = self.preprocess(input_df) prediction_df = self.model.predict(pre_transformed_df) self.log.info(“Test Log”) return postprocess(prediction_df)[‘output_column’] # pandas Series

lr = LinearRegression() lr.train(input_data) my_model = MyModel(lr) my_model.save(‘my_model_output’, [Tag(‘A’), Tag(‘B’)], Tag(‘C’), input_data, None)

predict(self, input_df: pandas.DataFrame)pandas.Series

sample prediction

class quartic_sdk.model.tests.MockLoggingHandler(*args, **kwargs)

Bases: logging.Handler

Mock logging handler to check for expected logs.

emit(self, record)

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

reset(self)
class quartic_sdk.model.tests.SupportedSpectralModel

Bases: quartic_sdk.model.BaseSpectralModel

Example Model used for testing spectral model This is a valid spectral model that can be saved to the Quartic AI Platform

predict(self, input_df: pandas.DataFrame)pandas.Series

Abstract method for custom predict method :param input_df: Input Data frame for prediction :return: Returns pd

class quartic_sdk.model.tests.SpectralModelThatReturnsString

Bases: quartic_sdk.model.BaseSpectralModel

Example Model used for testing spectral model This is a invalid spectral model whose predict function returns data of type string

post_transform(self, data)
predict(self, input_df: pandas.DataFrame)pandas.Series

Abstract method for custom predict method :param input_df: Input Data frame for prediction :return: Returns pd

class quartic_sdk.model.tests.SlowSpectralModel

Bases: quartic_sdk.model.BaseSpectralModel

Example Model used for testing spectral model This is a invalid spectral model whose predict function takes longer processing time than that is supported by the Quartic AI Platform

pre_transform(self, df)

A simple transformation that sleeps for x secs before returning same

predict(self, input_df: pandas.DataFrame)pandas.Series

sample prediction