mojolearn.LinearSVR#
- class mojolearn.LinearSVR(*, epsilon=0.0, penalty='l1', loss='epsilon_insensitive', C=1.0, fit_intercept=True, penalized_intercept=False, tol=0.0001, max_iter=1000, linesearch_max_iter=100, lbfgs_memory=5)[source]#
Bases:
_LinearSVMBaseLinear support vector regression.
Minimizes the epsilon-insensitive or squared epsilon-insensitive loss plus an l1 or l2 penalty (see the
mojolearn.svmmodule description for the objective). The intercept is never penalized.The default penalty is
'l1'(cuML’s default), which uses OWL-QN and gives exact zeros. scikit-learn’sLinearSVRis l2 only: passpenalty='l2'for its objective.Xis read as float32;ymust be one-dimensional. Invalid parameter values raiseValueError.- Parameters:
epsilon (float, default 0.0) – Width of the insensitive zone, finite and >= 0.
penalty ({‘l1’, ‘l2’}, default ‘l1’) – The regularization term.
loss ({‘epsilon_insensitive’, ‘squared_epsilon_insensitive’}, default ‘epsilon_insensitive’) – The data-fit loss.
C (float, default 1.0) – Inverse regularization strength, > 0.
fit_intercept (bool, default True) – Whether to fit an (unpenalized) intercept.
penalized_intercept (bool, default False) – Only False is supported; True raises
NotImplementedError.tol (float, default 1e-4) – Gradient tolerance, > 0.
max_iter (int, default 1000) – Maximum number of solver iterations.
linesearch_max_iter (int, default 100) – Maximum number of line-search steps per iteration.
lbfgs_memory (int, default 5) – Number of past updates kept by L-BFGS.
numeric_mode ({‘identical’, ‘fast’} or None, default None) – The numeric mode for this estimator; None uses the process default (see
mojolearn.set_numeric_mode).'fast'is for Apple GPUs.
- Variables:
coef_ (array of shape (n_features,), float32) – The fitted coefficients.
intercept_ (float) – The fitted intercept; 0.0 when
fit_interceptis False.n_iter_ (array of shape (1,), int64) – The number of solver iterations run.
objective_ (float) – The final value of the minimized objective.
retcode_ (int) – The solver’s return code, as on
LogisticRegression.n_features_in_ (int) – The number of features seen in
fit.input_copied_ (bool) – Whether
fithad to copyXto float32 C order.
Examples
>>> import numpy as np, mojolearn >>> rng = np.random.default_rng(0) >>> X = rng.random((1000, 8), dtype=np.float32) >>> y = X @ np.arange(8, dtype=np.float32) + 1.0 >>> model = mojolearn.LinearSVR(penalty="l2", epsilon=0.1).fit(X, y) >>> pred = model.predict(X)
- __init__(*, epsilon=0.0, penalty='l1', loss='epsilon_insensitive', C=1.0, fit_intercept=True, penalized_intercept=False, tol=0.0001, max_iter=1000, linesearch_max_iter=100, lbfgs_memory=5)[source]#
Methods
fit(X, y[, sample_weight])Fit the regressor.
get_params([deep])numeric_mode_used()The numeric mode this estimator runs in.
predict(X)Predict with the fitted model.
score(X, y)Return the coefficient of determination R^2 of the prediction.
set_params(**params)Set constructor parameters.
vendor_used()The GPU backend this estimator runs on.
- fit(X, y, sample_weight=None)[source]#
Fit the regressor.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Training data, read as float32.
y (array-like of shape (n_samples,)) – Target values. A 2-D
yor a length mismatch raisesValueError.sample_weight (None) – Must be None; weights raise
NotImplementedError.
- Returns:
self (LinearSVR) – The fitted estimator.
- predict(X)[source]#
Predict with the fitted model.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Samples, read as float32.
- Returns:
y_pred (array of shape (n_samples,), float32) –
X @ coef_ + intercept_.- Raises:
ValueError – If the model is not fitted, or
Xhas a different number of features than the training data.
- score(X, y)[source]#
Return the coefficient of determination R^2 of the prediction.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Test samples.
y (array-like of shape (n_samples,)) – True target values.
- Returns:
score (float) –
1 - SS_res / SS_tot, computed in float64. A constantyscores 0.0.