LogisticRegression#
- class skfda.ml.classification.LogisticRegression(max_features=5, penalty=None, C=1, solver='lbfgs', max_iter=100)[source]#
Logistic Regression classifier for functional data.
This class implements the sequential “greedy” algorithm for functional logistic regression proposed in Berrendero, Bueno-Larraz, and Cuevas[1].
Warning
For now, only binary classification for functional data with one dimensional domains is supported.
- Parameters:
n_features_to_select – Number of points (and coefficients) to be selected by the algorithm.
penalty (Literal['l1', 'l2', 'elasticnet', None]) – Penalty to use in the multivariate logistic regresion optimization problem. For more info check the parameter “penalty” in
sklearn.linear_model.LogisticRegression.C (float) – Inverse of the regularization parameter in the multivariate logistic regresion optimization problem. For more info check the parameter “C” in
sklearn.linear_model.LogisticRegression.solver (Solver) – Algorithm to use in the multivariate logistic regresion optimization problem. For more info check the parameter “solver” in
sklearn.linear_model.LogisticRegression.max_iter (int) – Maximum number of iterations taken for the solver to converge.
max_features (int)
- Attributes:
classes_ – A list containing the name of the classes
points_ – A list containing the selected points.
coef_ – A list containing the coefficient for each selected point.
intercept_ – Independent term.
Examples
>>> import skfda >>> from skfda.datasets import make_gaussian_process >>> from skfda.ml.classification import LogisticRegression >>> >>> n_samples = 2000 >>> n_features = 101 >>> >>> def mean_1(t): ... return (np.abs(t - 0.25) ... - 2 * np.abs(t - 0.5) ... + np.abs(t - 0.75)) >>> >>> X_0 = make_gaussian_process( ... n_samples=n_samples // 2, ... n_features=n_features, ... random_state=0, ... ) >>> X_1 = make_gaussian_process( ... n_samples=n_samples // 2, ... n_features=n_features, ... mean=mean_1, ... random_state=1, ... ) >>> X = skfda.concatenate((X_0, X_1)) >>> >>> y = np.zeros(n_samples) >>> y [n_samples // 2:] = 1 >>> lr = LogisticRegression(max_features=3) >>> _ = lr.fit(X[::2], y[::2]) >>> np.allclose(sorted(lr.points_), [0.25, 0.5, 0.75], rtol=1e-2) True >>> lr.score(X[1::2],y[1::2]) 0.768
- References:
Methods
fit(X, y)Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
predict(X)score(X, y[, sample_weight])Return accuracy on provided data and labels.
set_params(**params)Set the parameters of this estimator.
set_score_request(*[, sample_weight])Configure whether metadata should be requested to be passed to the
scoremethod.- get_metadata_routing()#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
routing – A
MetadataRequestencapsulating routing information.- Return type:
MetadataRequest
- get_params(deep=True)#
Get parameters for this estimator.
- score(X, y, sample_weight=None)[source]#
Return accuracy on provided data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Test samples.
y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True labels for X.
sample_weight (array-like of shape (n_samples,), default=None) – Sample weights.
- Returns:
score – Mean accuracy of
self.predict(X)w.r.t. y.- Return type:
- set_params(**params)#
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline). The latter have parameters of the form<component>__<parameter>so that it’s possible to update each component of a nested object.- Parameters:
**params (dict) – Estimator parameters.
- Returns:
self – Estimator instance.
- Return type:
estimator instance
- set_score_request(*, sample_weight='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.self (LogisticRegression)
- Returns:
self – The updated object.
- Return type: