SmartPredict
  • Documentation
  • OVERVIEW
    • Presentation
      • Key features
      • Who may benefit from its use
      • The SmartPredict Graphical User Interface (GUI)
        • The SmartPredict Modules
        • Focus on the Notebooks
        • Practical shortcuts
    • Prerequisites
  • Getting started
    • Getting started (Part1) : Iris classification project
      • Project description
      • Step 1. Create the project
      • Step 2. Upload the dataset
      • Step 3. Preprocess the dataset
      • Step 4. Build the flowchart
        • Set up the flowchart
        • Configure the modules
      • Step 5. Run the build
      • Step 6. Deploy the project
      • Step 7. Make inferences with our model
      • Conclusion
  • Getting started (Part 2): Predicting the passengers' survival in the Titanic shipwreck
    • Project description
    • Step 1. Create the project
    • Step 2. Upload the dataset
    • Step 3. Preprocess the dataset
    • Step 4. Build the flowchart
    • Step 5. Run the build
    • Step 6. Deploy the pipeline
    • Step 7. Make inferences with our pipeline
  • MODULE REFERENCE
    • CORE MODULES
      • Introduction
      • Basic Operations
        • Item Saver
      • Web Services
        • Web Service IN and OUT
      • Data retrieval
        • Data fetcher
        • Data frame loader/converter
        • Image data loader
      • Data preprocessing
        • Introduction
        • Array Reshaper
        • Generic Data Preprocessor
        • Missing data handler
        • Normalizer
        • One Hot Encoder
        • Ordinal Encoder
      • Data selection
        • Features selector
        • Generic data splitter
        • Labeled data splitter
      • Training and Prediction
        • Predictor DL models
        • Predictor ML models
        • Predictor ML models (Probabilistic models)
        • Trainer ML models
        • Trainer/Evaluator DL models
      • Evaluation and fine-tuning
        • Cross Validator for ML
        • Evaluator for ML models
      • Machine Learning algorithms
        • ML modules in SmartPredict
        • Decision Tree Regressor
        • KNeighbors Classifier
        • KNeighbors Regressors
        • Linear Regressor
        • Logistic Regressor
        • MLP Regressor
        • Naive Bayes Classifier
        • Random Forest Classifier
        • Random Forest Regressor
        • Support Vector Classifier
        • Support Vector Regressor
        • XGBoost Classifier
        • XGBoost Regressor
      • Deep learning algorithms
        • Dense Neural Network
        • Recurrent Neural Networks
      • Computer Vision
        • Convolutional Recurrent Networks
        • Fully Convolutional Neural Networks
        • Face detector
        • Image IO
        • Image matcher
        • Yolo
      • Natural Language Processing
        • Introduction
        • Text cleaner
        • Text vectorizer
      • Times Series processing
        • TS features selector
      • TensorFlow API
        • LSTM Layer
        • Dense Layer
      • Helpers
        • Data/Object Logger
        • Object Selector (5 ports)
      • Conclusion
  • CUSTOM MODULES
    • Function
    • Class
    • Use cases
Powered by GitBook
On this page

Was this helpful?

  1. CUSTOM MODULES

Class

This page explains how to design classes with SmartPredict.

PreviousFunctionNextUse cases

Last updated 5 years ago

Was this helpful?

Classes pack data and functionality. Insert your code into the code editor and save it as a new class.

Codes are done in Python. The official Python documentation provides a.

Class template

# ---------------------------------------------------
# Your import statements can be written here.
# All builtins python package can be imported.
# Popular libraries for ML like tensorflow, sklearn,
# pandas, nltk are also supported

# import tensorflow as tf
# import time
# other imports
# ---------------------------------------------------


from smart_predict.modules.base.custom import CustomModule


class MyCustomModule(CustomModule):
    """MyCustomModule.

    A custom module must inherit the class CustomModule."""

    #: This dictionary holds the property of your custom module
    p = {
        # Input specification, the keys of the dict are the inputs' name
        'in': {
            'input_1': {
                # Type of input data.
                'type': 'any',

                # Shown name.
                'name': 'Input 1',

                # Short description.
                'description': 'Default Input'
            }
        },

        # Output specification, the keys of the dict are the outputs' name
        'out': {
            'output_1': {
                # Type of output data.
                'type': 'any',

                # Shown name.
                'name': 'Output 1',

                # Short description.
                'description': 'Default Output'
            }
        },

        # Params specification, the keys of the dict are the name of the param.
        'params': {
            'param_1': {
                'label': 'Default Param',
                'type': 'str',
                'default': '',
                'input-type': 'text'
            }
        },

        # Other description of the module.
        'doc': {
            'author': 'John Doe',
            'framework': 'tensorflow, sk-learn',
            'description': 'lorem ipsum dolor sit amet.'
        },

        # Version.
        'version': '0.0'
    }

    def load(self):
        """Use this method to load your module.

        Load models, init objects, libraries..."""

    def run(self):
        """This method is called to run your module,

        Get input, read params, process data, set output."""

        # How to retrieve your input data.
        input_1_data = self.in_data['input_1']

        # How to retrieve your params value.
        param_1 = self.param['param_1']

        # How to process data.
        # Just write any number of methods you want and use them here.
        sample_out_data = self.sample_method(input_1_data, param_1)

        # Go to the definition of this method to see how to log.
        self.demo_log()

        # This is how to set output data.
        self.out_data['output_1'] = sample_out_data

    def sample_method(self, data, param):
        # This is an example of processing the data and producing the output
        sample_result = {
            'data': data,
            'param': param
        }
        return sample_result

    def demo_log(self):
        """You can use the `logger` property like any Logger created
        from python builtin logging module."""
        self.logger.debug('This is a debug')
        self.logger.debug(self.name)
        self.logger.debug(self.doc)
complete explanation of classes