Introduction

This document helps the user to run prediction / inference on the classical Logistic Regression (LogReg) model using the Razorthink aiOS SDK.


Problem

Load the saved model and predict on test data and save the results.


Solution

Create an inference pipeline, to predict on test data. Create an instance of LogisticRegression class with following parameters and evaluate the model by running execute():

  • operation - predict.
  • x_data - Test data on which the model is to be predicted.
  • attribute - Column name for the predicted value.
  • path - Specify the path where the trained model is saved.
lr_model_predict = (LogisticRegression()
         .operation("predict")
         .x_data(train_data.out_x)
         .attribute("classes_")
         .path("lr_m1.sav"))

@inputs.atomic.generic("output_path", required=True)
@inputs.atomic.generic("numpy_array", required=True)
class NumpyToCsv(Block):
    def run(self, numpy_array, output_path):
        pd.DataFrame(numpy_array,columns=['Predictions']).to_csv(output_path)
        
csv_writer = (NumpyToCsv()
    .output_path(project_space_path("lr_pred_1.csv"))
    .numpy_array(lr_model_predict.predictions))

predict_pipeline = Pipeline(targets=[csv_writer])

predict_pipeline.show()


Executing the training pipeline in the Jupyter Notebooks.

predict_pipeline.execute()