LinearSVR
Linear Support Vector Regression.
Similar to SVR with parameter kernel=’linear’, but implemented in terms of liblinear rather than libsvm, so it has more flexibility in the choice of penalties and loss functions and should scale better to large numbers of samples.
The main differences between LinearSVR
and SVR
lie in the loss function used by default, and in the handling of intercept regularization between those two implementations.
This class supports both dense and sparse input.
Read more in the User Guide.
Python Reference (opens in a new tab)
Constructors
constructor()
Signature
new LinearSVR(opts?: object): LinearSVR;
Parameters
Name | Type | Description |
---|---|---|
opts? | object | - |
opts.C? | number | Regularization parameter. The strength of the regularization is inversely proportional to C. Must be strictly positive. Default Value 1 |
opts.dual? | boolean | "auto" | Select the algorithm to either solve the dual or primal optimization problem. Prefer dual=false when n_samples > n_features. dual="auto" will choose the value of the parameter automatically, based on the values of n\_samples , n\_features and loss . If n\_samples < n\_features and optimizer supports chosen loss , then dual will be set to true , otherwise it will be set to false . Default Value true |
opts.epsilon? | number | Epsilon parameter in the epsilon-insensitive loss function. Note that the value of this parameter depends on the scale of the target variable y. If unsure, set epsilon=0 . Default Value 0 |
opts.fit_intercept? | boolean | Whether or not to fit an intercept. If set to true , the feature vector is extended to include an intercept term: \[x\_1, ..., x\_n, 1\] , where 1 corresponds to the intercept. If set to false , no intercept will be used in calculations (i.e. data is expected to be already centered). Default Value true |
opts.intercept_scaling? | number | When fit\_intercept is true , the instance vector x becomes \[x\_1, ..., x\_n, intercept\_scaling\] , i.e. a “synthetic” feature with a constant value equal to intercept\_scaling is appended to the instance vector. The intercept becomes intercept_scaling * synthetic feature weight. Note that liblinear internally penalizes the intercept, treating it like any other term in the feature vector. To reduce the impact of the regularization on the intercept, the intercept\_scaling parameter can be set to a value greater than 1; the higher the value of intercept\_scaling , the lower the impact of regularization on it. Then, the weights become \[w\_x\_1, ..., w\_x\_n, w\_intercept\*intercept\_scaling\] , where w\_x\_1, ..., w\_x\_n represent the feature weights and the intercept weight is scaled by intercept\_scaling . This scaling allows the intercept term to have a different regularization behavior compared to the other features. Default Value 1 |
opts.loss? | "epsilon_insensitive" | "squared_epsilon_insensitive" | Specifies the loss function. The epsilon-insensitive loss (standard SVR) is the L1 loss, while the squared epsilon-insensitive loss (‘squared_epsilon_insensitive’) is the L2 loss. Default Value 'epsilon_insensitive' |
opts.max_iter? | number | The maximum number of iterations to be run. Default Value 1000 |
opts.random_state? | number | Controls the pseudo random number generation for shuffling the data. Pass an int for reproducible output across multiple function calls. See Glossary. |
opts.tol? | number | Tolerance for stopping criteria. Default Value 0.0001 |
opts.verbose? | number | Enable verbose output. Note that this setting takes advantage of a per-process runtime setting in liblinear that, if enabled, may not work properly in a multithreaded context. Default Value 0 |
Returns
Defined in: generated/svm/LinearSVR.ts:29 (opens in a new tab)
Methods
dispose()
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Signature
dispose(): Promise<void>;
Returns
Promise
<void
>
Defined in: generated/svm/LinearSVR.ts:164 (opens in a new tab)
fit()
Fit the model according to the given training data.
Signature
fit(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike | Training vector, where n\_samples is the number of samples and n\_features is the number of features. |
opts.sample_weight? | ArrayLike | Array of weights that are assigned to individual samples. If not provided, then each sample is given unit weight. |
opts.y? | ArrayLike | Target vector relative to X. |
Returns
Promise
<any
>
Defined in: generated/svm/LinearSVR.ts:181 (opens in a new tab)
get_metadata_routing()
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Signature
get_metadata_routing(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.routing? | any | A MetadataRequest encapsulating routing information. |
Returns
Promise
<any
>
Defined in: generated/svm/LinearSVR.ts:230 (opens in a new tab)
init()
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Signature
init(py: PythonBridge): Promise<void>;
Parameters
Name | Type |
---|---|
py | PythonBridge |
Returns
Promise
<void
>
Defined in: generated/svm/LinearSVR.ts:115 (opens in a new tab)
predict()
Predict using the linear model.
Signature
predict(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | any | Samples. |
Returns
Promise
<any
>
Defined in: generated/svm/LinearSVR.ts:265 (opens in a new tab)
score()
Return the coefficient of determination of the prediction.
The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y\_true \- y\_pred)\*\* 2).sum()
and \(v\) is the total sum of squares ((y\_true \- y\_true.mean()) \*\* 2).sum()
. The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y
, disregarding the input features, would get a \(R^2\) score of 0.0.
Signature
score(opts: object): Promise<number>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.X? | ArrayLike [] | Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n\_samples, n\_samples\_fitted) , where n\_samples\_fitted is the number of samples used in the fitting for the estimator. |
opts.sample_weight? | ArrayLike | Sample weights. |
opts.y? | ArrayLike | True values for X . |
Returns
Promise
<number
>
Defined in: generated/svm/LinearSVR.ts:298 (opens in a new tab)
set_fit_request()
Request metadata passed to the fit
method.
Note that this method is only relevant if enable\_metadata\_routing=True
(see sklearn.set\_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Signature
set_fit_request(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight? | string | boolean | Metadata routing for sample\_weight parameter in fit . |
Returns
Promise
<any
>
Defined in: generated/svm/LinearSVR.ts:349 (opens in a new tab)
set_score_request()
Request metadata passed to the score
method.
Note that this method is only relevant if enable\_metadata\_routing=True
(see sklearn.set\_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Signature
set_score_request(opts: object): Promise<any>;
Parameters
Name | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight? | string | boolean | Metadata routing for sample\_weight parameter in score . |
Returns
Promise
<any
>
Defined in: generated/svm/LinearSVR.ts:386 (opens in a new tab)
Properties
_isDisposed
boolean
=false
Defined in: generated/svm/LinearSVR.ts:27 (opens in a new tab)
_isInitialized
boolean
=false
Defined in: generated/svm/LinearSVR.ts:26 (opens in a new tab)
_py
PythonBridge
Defined in: generated/svm/LinearSVR.ts:25 (opens in a new tab)
id
string
Defined in: generated/svm/LinearSVR.ts:22 (opens in a new tab)
opts
any
Defined in: generated/svm/LinearSVR.ts:23 (opens in a new tab)
Accessors
coef_
Weights assigned to the features (coefficients in the primal problem).
coef\_
is a readonly property derived from raw\_coef\_
that follows the internal memory layout of liblinear.
Signature
coef_(): Promise<ArrayLike[]>;
Returns
Promise
<ArrayLike
[]>
Defined in: generated/svm/LinearSVR.ts:421 (opens in a new tab)
feature_names_in_
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Signature
feature_names_in_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/svm/LinearSVR.ts:492 (opens in a new tab)
intercept_
Constants in decision function.
Signature
intercept_(): Promise<ArrayLike>;
Returns
Promise
<ArrayLike
>
Defined in: generated/svm/LinearSVR.ts:444 (opens in a new tab)
n_features_in_
Number of features seen during fit.
Signature
n_features_in_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/svm/LinearSVR.ts:467 (opens in a new tab)
n_iter_
Maximum number of iterations run across all classes.
Signature
n_iter_(): Promise<number>;
Returns
Promise
<number
>
Defined in: generated/svm/LinearSVR.ts:517 (opens in a new tab)
py
Signature
py(): PythonBridge;
Returns
PythonBridge
Defined in: generated/svm/LinearSVR.ts:102 (opens in a new tab)
Signature
py(pythonBridge: PythonBridge): void;
Parameters
Name | Type |
---|---|
pythonBridge | PythonBridge |
Returns
void
Defined in: generated/svm/LinearSVR.ts:106 (opens in a new tab)