Module tim_client.prediction_model

Expand source code
from typing import Dict, List
from pandas import DataFrame
import logging
from logging import Logger

from tim_client.helpers import dict_to_dataframe, aggregated_predictions_to_dataframes


class PredictionModel:
    """TIM model for Prediction."""

    __logger: Logger = None
    status: str = None
    request_uuid: str = None
    events: List[Dict] = None
    result_explanations: List[Dict] = None
    progress: float = None
    engine_result: str = None
    requested_configuration: Dict = None
    model: str = None
    data_offsets: List[Dict] = None
    predictors_importances: Dict = None
    prediction: DataFrame = None
    aggregated_predictions: List[Dict] = None
    raw_predictions: List[Dict] = None
    data_difficulty: float = None

    def __init__(self,
                 status: str,
                 request_uuid: str,
                 events: List[Dict] = None,
                 result_explanations: List[Dict] = None,
                 progress: float = None,
                 engine_result: str = None,
                 requested_configuration: Dict = None,
                 model: str = None,
                 data_offsets: List[Dict] = None,
                 predictors_importances: Dict = None,
                 prediction: DataFrame = None,
                 aggregated_predictions: List[Dict] = None,
                 raw_predictions: List[Dict] = None,
                 data_difficulty: float = None,
                 logger: Logger = None
                 ):
        self.status = status
        self.request_uuid = request_uuid
        self.events = events
        self.result_explanations = result_explanations
        self.progress = progress
        self.engine_result = engine_result
        self.requested_configuration = requested_configuration
        self.model = model
        self.data_offsets = data_offsets
        self.predictors_importances = predictors_importances
        self.prediction = prediction
        self.aggregated_predictions = aggregated_predictions
        self.raw_predictions = raw_predictions
        self.data_difficulty = data_difficulty
        
        if self.__logger is None:
            self.__logger = logging.getLogger(__name__)

    def __str__(self) -> str:
        return f'Prediction Model {self.request_uuid}: {self.status}'

    def get_model(self) -> str:
        """Return string representing encrypted TIM Model."""
        return self.model

    def get_prediction(self) -> DataFrame:
        """Return pandas DataFrame containing predicton values."""
        return self.prediction

    @classmethod
    def from_json(cls, data):
        return cls(
            status=data['status'] if 'status' in data else None,
            request_uuid=data['requestUUID'] if 'requestUUID' in data else None,
            events=data['events'] if 'events' in data else None,
            result_explanations=data['resultExplanations'] if 'resultExplanations' in data else None,
            progress=float(data['progress']) if 'progress' in data else None,
            engine_result=data['engineResult'] if 'engineResult' in data else None,
            requested_configuration=data['requestedConfiguration'] if 'requestedConfiguration' in data else None,
            model=data['model'] if 'model' in data else None,
            data_offsets=data['dataOffsets'] if 'dataOffsets' in data else None,
            predictors_importances=data['predictorsImportances'] if 'predictorsImportances' in data else None,
            prediction=dict_to_dataframe(data['prediction']['values'], {0: 'Timestamp', 1: 'Prediction'}) if 'prediction' in data and 'values' in data['prediction'] else None,
            aggregated_predictions=aggregated_predictions_to_dataframes(data['aggregatedPredictions']) if 'aggregatedPredictions' in data else None,
            raw_predictions=data['rawPredictions'] if 'rawPredictions' in data else None,
            data_difficulty=float(data['dataDifficulty']) if 'dataDifficulty' in data else None
        )

Classes

class PredictionModel (status: str, request_uuid: str, events: List[Dict] = None, result_explanations: List[Dict] = None, progress: float = None, engine_result: str = None, requested_configuration: Dict = None, model: str = None, data_offsets: List[Dict] = None, predictors_importances: Dict = None, prediction: pandas.core.frame.DataFrame = None, aggregated_predictions: List[Dict] = None, raw_predictions: List[Dict] = None, data_difficulty: float = None, logger: logging.Logger = None)

TIM model for Prediction.

Expand source code
class PredictionModel:
    """TIM model for Prediction."""

    __logger: Logger = None
    status: str = None
    request_uuid: str = None
    events: List[Dict] = None
    result_explanations: List[Dict] = None
    progress: float = None
    engine_result: str = None
    requested_configuration: Dict = None
    model: str = None
    data_offsets: List[Dict] = None
    predictors_importances: Dict = None
    prediction: DataFrame = None
    aggregated_predictions: List[Dict] = None
    raw_predictions: List[Dict] = None
    data_difficulty: float = None

    def __init__(self,
                 status: str,
                 request_uuid: str,
                 events: List[Dict] = None,
                 result_explanations: List[Dict] = None,
                 progress: float = None,
                 engine_result: str = None,
                 requested_configuration: Dict = None,
                 model: str = None,
                 data_offsets: List[Dict] = None,
                 predictors_importances: Dict = None,
                 prediction: DataFrame = None,
                 aggregated_predictions: List[Dict] = None,
                 raw_predictions: List[Dict] = None,
                 data_difficulty: float = None,
                 logger: Logger = None
                 ):
        self.status = status
        self.request_uuid = request_uuid
        self.events = events
        self.result_explanations = result_explanations
        self.progress = progress
        self.engine_result = engine_result
        self.requested_configuration = requested_configuration
        self.model = model
        self.data_offsets = data_offsets
        self.predictors_importances = predictors_importances
        self.prediction = prediction
        self.aggregated_predictions = aggregated_predictions
        self.raw_predictions = raw_predictions
        self.data_difficulty = data_difficulty
        
        if self.__logger is None:
            self.__logger = logging.getLogger(__name__)

    def __str__(self) -> str:
        return f'Prediction Model {self.request_uuid}: {self.status}'

    def get_model(self) -> str:
        """Return string representing encrypted TIM Model."""
        return self.model

    def get_prediction(self) -> DataFrame:
        """Return pandas DataFrame containing predicton values."""
        return self.prediction

    @classmethod
    def from_json(cls, data):
        return cls(
            status=data['status'] if 'status' in data else None,
            request_uuid=data['requestUUID'] if 'requestUUID' in data else None,
            events=data['events'] if 'events' in data else None,
            result_explanations=data['resultExplanations'] if 'resultExplanations' in data else None,
            progress=float(data['progress']) if 'progress' in data else None,
            engine_result=data['engineResult'] if 'engineResult' in data else None,
            requested_configuration=data['requestedConfiguration'] if 'requestedConfiguration' in data else None,
            model=data['model'] if 'model' in data else None,
            data_offsets=data['dataOffsets'] if 'dataOffsets' in data else None,
            predictors_importances=data['predictorsImportances'] if 'predictorsImportances' in data else None,
            prediction=dict_to_dataframe(data['prediction']['values'], {0: 'Timestamp', 1: 'Prediction'}) if 'prediction' in data and 'values' in data['prediction'] else None,
            aggregated_predictions=aggregated_predictions_to_dataframes(data['aggregatedPredictions']) if 'aggregatedPredictions' in data else None,
            raw_predictions=data['rawPredictions'] if 'rawPredictions' in data else None,
            data_difficulty=float(data['dataDifficulty']) if 'dataDifficulty' in data else None
        )

Class variables

var aggregated_predictions : List[Dict]
var data_difficulty : float
var data_offsets : List[Dict]
var engine_result : str
var events : List[Dict]
var model : str
var prediction : pandas.core.frame.DataFrame
var predictors_importances : Dict
var progress : float
var raw_predictions : List[Dict]
var request_uuid : str
var requested_configuration : Dict
var result_explanations : List[Dict]
var status : str

Static methods

def from_json(data)
Expand source code
@classmethod
def from_json(cls, data):
    return cls(
        status=data['status'] if 'status' in data else None,
        request_uuid=data['requestUUID'] if 'requestUUID' in data else None,
        events=data['events'] if 'events' in data else None,
        result_explanations=data['resultExplanations'] if 'resultExplanations' in data else None,
        progress=float(data['progress']) if 'progress' in data else None,
        engine_result=data['engineResult'] if 'engineResult' in data else None,
        requested_configuration=data['requestedConfiguration'] if 'requestedConfiguration' in data else None,
        model=data['model'] if 'model' in data else None,
        data_offsets=data['dataOffsets'] if 'dataOffsets' in data else None,
        predictors_importances=data['predictorsImportances'] if 'predictorsImportances' in data else None,
        prediction=dict_to_dataframe(data['prediction']['values'], {0: 'Timestamp', 1: 'Prediction'}) if 'prediction' in data and 'values' in data['prediction'] else None,
        aggregated_predictions=aggregated_predictions_to_dataframes(data['aggregatedPredictions']) if 'aggregatedPredictions' in data else None,
        raw_predictions=data['rawPredictions'] if 'rawPredictions' in data else None,
        data_difficulty=float(data['dataDifficulty']) if 'dataDifficulty' in data else None
    )

Methods

def get_model(self) -> str

Return string representing encrypted TIM Model.

Expand source code
def get_model(self) -> str:
    """Return string representing encrypted TIM Model."""
    return self.model
def get_prediction(self) -> pandas.core.frame.DataFrame

Return pandas DataFrame containing predicton values.

Expand source code
def get_prediction(self) -> DataFrame:
    """Return pandas DataFrame containing predicton values."""
    return self.prediction