SVR

class hana_ml.algorithms.pal.svm.SVR(c=None, kernel='rbf', degree=None, gamma=None, coef_lin=None, coef_const=None, shrink=True, tol=None, evaluation_seed=None, thread_ratio=None, scale_info=None, scale_label=None, handle_missing=True, categorical_variable=None, category_weight=None, regression_eps=None, compression=None, max_bits=None, max_quantization_iter=None, resampling_method=None, fold_num=None, repeat_times=None, search_strategy=None, random_search_times=None, random_state=None, timeout=None, progress_indicator_id=None, param_values=None, param_range=None, reduction_rate=None, aggressive_elimination=None, onehot_min_frequency=None, onehot_max_categories=None)

Support Vector Machines (SVMs) refer to a family of supervised learning models using the concept of support vector.

Compared with many other supervised learning models, SVMs have the advantages in that the models produced by SVMs can be either linear or non-linear, where the latter is realized by a technique called Kernel Trick.

Like most supervised models, there are training phase and testing phase for SVMs. In the training phase, a function f(x):->y where f(∙) is a function (can be non-linear) mapping a sample onto a TARGET, is learnt. The training set consists of pairs denoted by {xi, yi}, where x denotes a sample represented by several attributes, and y denotes a TARGET (supervised information). In the testing phase, the learnt f(∙) is further used to map a sample with unknown TARGET onto its predicted TARGET.

SVR is another method for regression analysis. Compared with classical linear regression methods like least square regression, the regression function in SVR can be non-linear. In regression scenario, f(∙) refers to regression function, and TARGET refers to "response" represented by a real number.

Parameters:
cfloat, optional

Trade-off between training error and margin. Value range > 0.

Defaults to 100.0.

kernel{'linear', 'poly', 'rbf', 'sigmoid'}, optional

Specifies the kernel type to be used in the algorithm.

Defaults to 'rbf'.

degreeint, optional

Coefficient for the 'poly' kernel type. Value range >= 1.

Defaults to 3.

gammafloat, optional

Coefficient for the 'rbf' kernel type.

Defaults to 1.0/number of features in the dataset. Only valid when kernel is 'rbf'.

coef_linfloat, optional

Coefficient for the poly/sigmoid kernel type.

Defaults to 0.

coef_constfloat, optional

Coefficient for the poly/sigmoid kernel type.

Defaults to 0.

shrinkbool, optional

If True, use shrink strategy.

Defaults to True.

tolfloat, optional

Specifies the error tolerance in the training process. Value range > 0.

Defaults to 0.001.

evaluation_seedint, optional

The random seed in parameter selection. Value range >= 0.

Defaults to 0.

thread_ratiofloat, optional

Adjusts the percentage of available threads to use, from 0 to 1. A value of 0 indicates the use of a single thread, while 1 implies the use of all possible current threads. Values outside the range will be ignored and this function heuristically determines the number of threads to use.

Defaults to 0.0.

scale_info{'no', 'standardization', 'rescale'}, optional

Options:

  • 'no' : No scale.

  • 'standardization' : Transforms the data to have zero mean and unit variance.

  • 'rescale' : Rescales the range of the features to scale the range in [-1,1].

Defaults to 'standardization'.

scale_labelbool, optional

If True, standardize the label for SVR.

It is only applicable when the scale_info is 'standardization'.

Defaults to True.

handle_missingbool, optional

Whether to handle missing values:

  • False: No,

  • True: Yes.

Defaults to True.

categorical_variablestr or a list of str, optional

Specifies which INTEGER columns should be treated as categorical, with all other INTEGER columns treated as continuous.

No default value.

category_weightfloat, optional

Represents the weight of category attributes. Value range > 0.

Defaults to 0.707.

regression_epsfloat, optional

Epsilon width of tube for regression.

Defaults to 0.1.

compressionbool, optional

Specifies if the model is stored in compressed format.

Default value depends on the SAP HANA Version. Please refer to the corresponding documentation of SAP HANA PAL.

max_bitsint, optional

The maximum number of bits to quantize continuous features, equivalent to use \(2^{max\_bits}\) bins.

Must be less than 31.

Valid only when the value of compression is True.

Defaults to 12.

max_quantization_iterint, optional

The maximum iteration steps for quantization.

Valid only when the value of compression is True.

Defaults to 1000.

resampling_methodstr, optional

Specifies the resampling method for model evaluation or parameter selection.

  • 'cv'

  • 'cv_sha'

  • 'cv_hyperband'

  • 'bootstrap'

  • 'bootstrap_sha'

  • 'bootstrap_hyperband'

If no value is specified for this parameter, neither model evaluation nor parameter selection is activated.

No default value.

Note

Resampling methods that end with 'sha' or 'hyperband' are used for parameter selection only, not for model evaluation.

fold_numint, optional

Specifies the fold number for the cross validation method.

Mandatory and valid only when resampling_method is set to 'cv', 'cv_sha' or 'cv_hyperband'.

No default value.

repeat_timesint, optional

Specifies the number of repeat times for resampling.

Default to 1.

search_strategystr, optional

Specify the parameter search method:

  • 'grid'

  • 'random'

Mandatory when resampling method is set to 'cv_sha' or 'bootstrap_sha'.

Defaults to random and cannot be changed if resampling_method is set to 'cv_hyperband' or 'bootstrap_hyperband'; otherwise no default value, and parameter selection cannot be activated if not specified.

random_search_timesint, optional

Specifies the number of times to randomly select candidate parameters for selection.

Mandatory when search_strategy is set to 'random', or when resampling_method is set to 'cv_hyperband' or 'bootstrap_hyperband'.

No default value.

random_stateint, optional

Specifies the seed for random generation. Use system time when 0 is specified.

Default to 0.

timeoutint, optional

Specifies maximum running time for model evaluation or parameter selection, in seconds. No timeout when 0 is specified.

Default to 0.

progress_indicator_idstr, optional

Sets an ID of progress indicator for model evaluation or parameter selection. No progress indicator is active if no value is provided.

No default value.

param_valuesdict or list of tuple, optional

Sets the values of following parameters for model parameter selection:

gamma, c.

If input is list of tuple, then each tuple should contain exactly two elements:

  • 1st element is the parameter name(str type),

  • 2nd element is a list of valid values for that parameter.

Otherwise, if input is dict, then the key of each element should specify a parameter name, while the corresponding value specifies a list of values for that parameter.

A simple example for illustration:

[('c', [0.1, 0.2, 0.5]), ('gamma', [0.2, 0.6])]

or

{'c':[0.1, 0.2, 0.5], 'gamma':[0.2,0.6]}

Valid only when resampling_method and search_strategy are both specified.

No default value.

param_rangedict or list of tuple, optional

Sets the range of the following parameters for model parameter selection:

gamma, c.

If input is list of tuple, then each tuple should contain exactly two elements:

  • 1st element is the parameter name(str type),

  • 2nd element is a list that specifies the range of that parameter as [start, step, end].

Otherwise, if input is dict, then the key of each element must specify a parameter name, while the corresponding value specifies the range of that parameter.

Valid only when resampling_method and search_strategy are both specified.

No default value.

reduction_ratefloat, optional

Specifies reduction rate in SHA or Hyperband method.

For each round, the available parameter candidate size will be divided by value of this parameter. Thus valid value for this parameter must be greater than 1.0

Valid only when resampling_method is set to one of the following values: 'cv_sha', 'bootstrap_sha', 'cv_hyperband', 'bootstrap_hyperband'.

Defaults to 3.0.

aggressive_eliminationbool, optional

Specifies whether to apply aggressive elimination while using SHA method.

Aggressive elimination happens when the data size and parameters size to be searched does not match and there are still bunch of parameters to be searched while data size reaches its upper limits. If aggressive elimination is applied, lower bound of limit of data size will be used multiple times first to reduce number of parameters.

Valid only when resampling_method is set to 'cv_sha' or 'bootstrap_sha'.

Defaults to False.

onehot_min_frequencyint, optional

Specifies the minimum frequency below which a category will be considered infrequent.

Defaults to 1.

onehot_max_categoriesint, optional

Specifies an upper limit to the number of output features for each input feature. It includes the feature that combines infrequent categories.

Defaults to 0.

References

Three key functionalities are enabled in support vector regression(SVR), listed as follows:

Please refer to the links above for detailed description about each functionality together with relevant parameters.

Examples

Create a SVR instance and call the fit():

>>> svr = SVR(kernel='linear', scale_info='standardization', scale_label=True, handle_missing=False)
>>> svr.fit(data=df_fit, key='ID', features=['F1', 'F2'])
>>> res = svr.predict(data=df_predict, key='ID', features=['F1', 'F2'])
>>> res.collect()
Attributes:
model_DataFrame

Model content.

stat_DataFrame

Statistics content.

Methods

create_model_state([model, function, ...])

Create PAL model state.

delete_model_state([state])

Delete PAL model state.

fit(data[, key, features, label, ...])

Fit the model to the training dataset.

get_model_metrics()

Get the model metrics.

get_score_metrics()

Get the score metrics.

predict(data[, key, features])

Predict dependent variable values based on a fitted model.

score(data[, key, features, label])

Returns the coefficient of determination R2 of the prediction.

set_model_state(state)

Set the model state by state information.

fit(data, key=None, features=None, label=None, categorical_variable=None)

Fit the model to the training dataset.

Parameters:
dataDataFrame

DataFrame containing the data.

keystr, optional

Name of the ID column.

If key is not provided, then:

  • if data is indexed by a single column, then key defaults to that index column;

  • otherwise, it is assumed that data contains no ID column.

featuresa list of str, optional

Names of the feature columns.

If features is not provided, it defaults to all the non-ID, non-label columns.

labelstr, optional

Name of the label column.

If label is not provided, it defaults to the last non-ID column.

categorical_variablestr or a list of str, optional

Specifies which INTEGER columns should be treated as categorical, with all other INTEGER columns treated as continuous.

No default value.

Returns:
A fitted object of class "SVR".
predict(data, key=None, features=None)

Predict dependent variable values based on a fitted model.

Parameters:
dataDataFrame

DataFrame containing the data.

keystr, optional

Name of the ID column.

Mandatory if data is not indexed, or the index of data contains multiple columns.

Defaults to the single index column of data if not provided.

featuresa list of str, optional

Names of the feature columns.

If features is not provided, it defaults to all the non-ID columns.

Returns:
DataFrame

Predict result, structured as follows:

  • ID column, with the same name and type as data1 's ID column.

  • SCORE, type NVARCHAR(100), prediction value.

  • PROBABILITY, type DOUBLE, prediction probability. Always NULL. This column is only used for SVC and SVRanking.

score(data, key=None, features=None, label=None)

Returns the coefficient of determination R2 of the prediction.

Parameters:
dataDataFrame

DataFrame containing the data.

keystr, optional

Name of the ID column.

Mandatory if data is not indexed, or the index of data contains multiple columns.

Defaults to the single index column of data if not provided.

featuresa list of str, optional

Names of the feature columns.

If features is not provided, it defaults to all the non-ID and non-label columns.

labelstr, optional

Name of the label column.

If label is not provided, it defaults to the last non-ID column.

Returns:
float

Returns the coefficient of determination R2 of the prediction.

create_model_state(model=None, function=None, pal_funcname='PAL_SVM', state_description=None, force=False)

Create PAL model state.

Parameters:
modelDataFrame, optional

Specify the model for AFL state.

Defaults to self.model_.

functionstr, optional

Specify the function in the unified API.

A placeholder parameter, not effective for SVM.

pal_funcnameint or str, optional

PAL function name.

Defaults to 'PAL_SVM'.

state_descriptionstr, optional

Description of the state as model container.

Defaults to None.

forcebool, optional

If True it will delete the existing state.

Defaults to False.

delete_model_state(state=None)

Delete PAL model state.

Parameters:
stateDataFrame, optional

Specified the state.

Defaults to self.state.

get_model_metrics()

Get the model metrics.

Returns:
DataFrame

The model metrics.

get_score_metrics()

Get the score metrics.

Returns:
DataFrame

The score metrics.

set_model_state(state)

Set the model state by state information.

Parameters:
state: DataFrame or dict

If state is DataFrame, it has the following structure:

  • NAME: VARCHAR(100), it mush have STATE_ID, HINT, HOST and PORT.

  • VALUE: VARCHAR(1000), the values according to NAME.

If state is dict, the key must have STATE_ID, HINT, HOST and PORT.

Inherited Methods from PALBase

Besides those methods mentioned above, the SVR class also inherits methods from PALBase class, please refer to PAL Base for more details.