pyanno4rt.learning_model.frequentist._support_vector_machine

Support vector machine model.

Overview

Classes

SupportVectorMachineModel

Support vector machine model class.

Classes

class pyanno4rt.learning_model.frequentist._support_vector_machine.SupportVectorMachineModel(model_label, model_folder_path, dataset, preprocessing_steps, tune_space, tune_evaluations, tune_score, inspect_model, evaluate_model, display_options)[source]

Support vector machine model class.

This class enables building an individual preprocessing pipeline, fit the support vector machine model from the input data, inspect the model, make predictions with the model, and assess the predictive performance using multiple evaluation metrics.

The training process includes sequential model-based hyperparameter optimization with tree-structured Parzen estimators and stratified k-fold cross-validation for the objective function evaluation. Cross-validation is also applied to (optionally) inspect the validation feature importances and to generate out-of-folds predictions as a full reconstruction of the input labels for generalization assessment.

Parameters:
  • model_label (string) – Label for the support vector machine model to be used for file naming.

  • dataset (dict) – Dictionary with the raw data set, the label viewpoint, the label bounds, the feature values and names, and the label values and names after modulation. In a compact way, this represents the input data for the support vector machine model.

  • preprocessing_steps (tuple) –

    Sequence of labels associated with preprocessing algorithms which make up the preprocessing pipeline for the support vector machine model. Current available algorithm labels are:

    • transformers : ‘Equalizer’, ‘StandardScaler’, ‘Whitening’.

  • tune_space (dict) –

    Search space for the Bayesian hyperparameter optimization, including

    • ’C’ : inverse of the regularization strength;

    • ’kernel’ : kernel type for the support vector machine;

    • ’degree’ : degree of the polynomial kernel function;

    • ’gamma’ : kernel coefficient for RBF, polynomial and sigmoid kernel;

    • ’tol’ : tolerance for stopping criteria;

    • ’class_weight’ : weights associated with the classes.

  • tune_evaluations (int) – Number of evaluation steps (trials) for the Bayesian hyperparameter optimization.

  • tune_score (string) –

    Scoring function for the evaluation of the hyperparameter set candidates. Current available scorers are:

    • ’log_loss’ : negative log-likelihood score;

    • ’roc_auc_score’ : area under the ROC curve score.

  • tune_splits (int) – Number of splits for the stratified cross-validation within each hyperparameter optimization step.

  • inspect_model (bool) – Indicator for the inspection of the model, e.g. the feature importances.

  • evaluate_model (bool) – Indicator for the evaluation of the model, e.g. the model KPIs.

  • oof_splits (int) – Number of splits for the stratified cross-validation within the out-of-folds evaluation step of the support vector machine model.

preprocessor

Instance of the class DataPreprocessor, which holds methods to build the preprocessing pipeline, fit with the input features, transform the features, and derive the gradient of the preprocessing algorithms w.r.t the features.

Type:

object of class DataPreprocessor

features

Values of the input features.

Type:

ndarray

labels

Values of the input labels.

Type:

ndarray

configuration

Dictionary with information for the modeling, i.e., the dataset, the preprocessing, and the hyperparameter search space.

Type:

dict

model_path

Path for storing and retrieving the support vector machine model.

Type:

string

configuration_path

Path for storing and retrieving the configuration dictionary.

Type:

string

hyperparameter_path

Path for storing and retrieving the hyperparameter dictionary.

Type:

string

updated_model

Indicator for the update status of the model, triggers recalculating the model inspection and model evaluation classes.

Type:

bool

prediction_model

Instance of the class SVC, which holds methods to make predictions from the support vector machine model.

Type:

object of class SVC

inspector

Instance of the class ModelInspector, which holds methods to compute model inspection values, e.g. feature importances.

Type:

object of class ModelInspector

training_prediction

Array with the label predictions on the input data.

Type:

ndarray

oof_prediction

Array with the out-of-folds predictions on the input data.

Type:

ndarray

evaluator

Instance of the class ModelEvaluator, which holds methods to compute the evaluation metrics for a given array with label predictions.

Type:

object of class ModelEvaluator

Notes

Currently, the preprocessing pipeline for the model is restricted to transformations of the input feature values, e.g. scaling, dimensionality reduction or feature engineering. Transformations which affect the input labels in the same way, e.g. resampling or outlier removal, are not yet possible.

Overview

Methods

preprocess(features)

Preprocess the input feature vector with the built pipeline.

get_model(features, labels)

Get the support vector machine outcome prediction model by reading from the model file path, the datahub, or by training.

tune_hyperparameters(features, labels)

Tune the hyperparameters of the support vector machine model via sequential model-based optimization using the tree-structured Parzen estimator. As a variation, the objective function is evaluated based on a stratified k-fold cross-validation.

train(features, labels)

Train the support vector machine outcome prediction model.

predict(features)

Predict the label values from the feature values.

predict_oof(features, labels)

Predict the out-of-folds (OOF) labels using a stratified k-fold cross-validation.

inspect(features, labels, oof_folds)

.

evaluate(features, labels)

.

set_file_paths(base_path)

Set the paths for model, configuration and hyperparameter files.

read_model_from_file()

Read the support vector machine outcome prediction model from the model file path.

write_model_to_file(prediction_model)

Write the support vector machine outcome prediction model to the model file path.

read_configuration_from_file()

Read the configuration dictionary from the configuration file path.

write_configuration_to_file(configuration)

Write the configuration dictionary to the configuration file path.

read_hyperparameters_from_file()

Read the support vector machine outcome prediction model hyperparameters from the hyperparameter file path.

write_hyperparameters_to_file(hyperparameters)

Write the hyperparameter dictionary to the hyperparameter file path.

Members

preprocess(features)[source]

Preprocess the input feature vector with the built pipeline.

Parameters:

features (ndarray) – Array of input feature values.

Returns:

Array of transformed feature values.

Return type:

ndarray

get_model(features, labels)[source]

Get the support vector machine outcome prediction model by reading from the model file path, the datahub, or by training.

Returns:

Instance of the class SVC, which holds methods to make predictions from the support vector machine model.

Return type:

object of class SVC

tune_hyperparameters(features, labels)[source]

Tune the hyperparameters of the support vector machine model via sequential model-based optimization using the tree-structured Parzen estimator. As a variation, the objective function is evaluated based on a stratified k-fold cross-validation.

Returns:

tuned_hyperparameters – Dictionary with the hyperparameter names and values tuned via Bayesian hyperparameter optimization.

Return type:

dict

train(features, labels)[source]

Train the support vector machine outcome prediction model.

Returns:

prediction_model – Instance of the class SVC, which holds methods to make predictions from the support vector machine model.

Return type:

object of class SVC

predict(features)[source]

Predict the label values from the feature values.

Parameters:

features (ndarray) – Array of input feature values.

Returns:

Floating-point label prediction or array of label predictions.

Return type:

float or ndarray

predict_oof(features, labels)[source]

Predict the out-of-folds (OOF) labels using a stratified k-fold cross-validation.

Parameters:

oof_splits (int) – Number of splits for the stratified cross-validation.

Returns:

Array with the out-of-folds label predictions.

Return type:

ndarray

inspect(features, labels, oof_folds)[source]

.

evaluate(features, labels)[source]

.

set_file_paths(base_path)[source]

Set the paths for model, configuration and hyperparameter files.

Parameters:

base_path (string) – Base path from which to access the model files.

read_model_from_file()[source]

Read the support vector machine outcome prediction model from the model file path.

Returns:

Instance of the class SVC, which holds methods to make predictions from the support vector machine model.

Return type:

object of class SVC

write_model_to_file(prediction_model)[source]

Write the support vector machine outcome prediction model to the model file path.

Parameters:

prediction_model (object of class SVC) – Instance of the class SVC, which holds methods to make predictions from the support vector machine model.

read_configuration_from_file()[source]

Read the configuration dictionary from the configuration file path.

Returns:

Dictionary with information for the modeling, i.e., the dataset, the preprocessing steps, and the hyperparameter search space.

Return type:

dict

write_configuration_to_file(configuration)[source]

Write the configuration dictionary to the configuration file path.

Parameters:

configuration (dict) – Dictionary with information for the modeling, i.e., the dataset, the preprocessing steps, and the hyperparameter search space.

read_hyperparameters_from_file()[source]

Read the support vector machine outcome prediction model hyperparameters from the hyperparameter file path.

Returns:

Dictionary with the hyperparameter names and values for the support vector machine outcome prediction model.

Return type:

dict

write_hyperparameters_to_file(hyperparameters)[source]

Write the hyperparameter dictionary to the hyperparameter file path.

Parameters:

hyperparameters (dict) – Dictionary with the hyperparameter names and values for the support vector machine outcome prediction model.