mojolearn.RidgeClassifier#
- class mojolearn.RidgeClassifier(alpha=1.0, *, fit_intercept=True, copy_X=True, max_iter=None, tol=0.0001, class_weight=None, solver='auto', positive=False, random_state=None)[source]#
Bases:
_LinearClassifierMixin,NumericModeMixinClassifier using ridge regression on -1/+1 targets.
Follows scikit-learn’s RidgeClassifier: each class becomes a -1/+1 target column (one column for a binary problem), fitted by ridge regression with a Cholesky solve. Only
solver='auto'or'cholesky'is accepted, andpositive=Trueraises ValueError.- Parameters:
alpha (float, default 1.0) – L2 regularization strength (>= 0).
fit_intercept (bool, default True) – Whether to fit an intercept.
copy_X (bool, default True) – Accepted for compatibility;
Xis never modified.max_iter (int or None, default None) – Accepted for compatibility; ignored by the direct solver.
tol (float, default 1e-4) – Accepted for compatibility; ignored by the direct solver.
class_weight (dict, ‘balanced’ or None, default None) – Per-class weights, multiplied into
sample_weight; ‘balanced’ weighs classes inversely to their frequency.solver ({‘auto’, ‘cholesky’}, default ‘auto’) – Both run the Cholesky solver.
positive (bool, default False) – Not supported: True raises ValueError.
random_state (int or None, default None) – Accepted for compatibility; ignored.
numeric_mode (str or None, default None) – Numeric mode for this model (
'identical','deterministic'or'fast', which runs on Apple GPUs only); None uses the process default (seemojolearn.set_numeric_mode()).
- Variables:
classes_ (array of shape (n_classes,)) – Class labels.
coef_ (float32 array of shape (1, n_features) or (n_classes, n_features)) – Weights; one row for a binary problem.
intercept_ (float32 array of shape (1,) or (n_classes,)) – Intercepts.
n_features_in_ (int) – Number of features seen in
fit.
Examples
>>> import numpy as np, mojolearn >>> rng = np.random.default_rng(0) >>> X = rng.random((1000, 8), dtype=np.float32) >>> y = (X[:, 0] > X[:, 1]).astype(np.int32) >>> model = mojolearn.RidgeClassifier(alpha=1.0).fit(X, y)
- __init__(alpha=1.0, *, fit_intercept=True, copy_X=True, max_iter=None, tol=0.0001, class_weight=None, solver='auto', positive=False, random_state=None)[source]#
Methods
decision_function(X)Signed distance of each sample to the separating hyperplane(s).
fit(X, y[, sample_weight])Fit the model.
get_params([deep])numeric_mode_used()The numeric mode this estimator runs in.
predict(X)Predict class labels.
score(X, y)Mean accuracy of
predict(X)againsty.set_params(**params)Set constructor parameters.
vendor_used()The GPU backend this estimator runs on.
- fit(X, y, sample_weight=None)[source]#
Fit the model.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Training data, converted to float32; values must be finite.
y (array-like of shape (n_samples,)) – Class labels; at least two classes.
sample_weight (array-like of shape (n_samples,) or float, optional) – Non-negative weights with a positive sum.
- Returns:
self (RidgeClassifier) – The fitted model.
- Raises:
ValueError – On an unsupported
solverorpositive=True, a negativealpha, a single class, invalid weights, or whenX'X + alpha Icannot be factored (rescaleXor raisealpha).