Skip to content

Commit 68236ab

Browse files
committed
Add decision_function to ElasticNet.
This allows to plug ElasticNet and Lasso into the multiclass estimators.
1 parent e3ed8e0 commit 68236ab

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

sklearn/linear_model/base.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
class LinearModel(BaseEstimator, RegressorMixin):
4242
"""Base class for Linear Models"""
4343

44-
def predict(self, X):
45-
"""Predict using the linear model
44+
def decision_function(self, X):
45+
"""Decision function of the linear model
4646
4747
Parameters
4848
----------
@@ -56,6 +56,20 @@ def predict(self, X):
5656
X = safe_asarray(X)
5757
return safe_sparse_dot(X, self.coef_.T) + self.intercept_
5858

59+
def predict(self, X):
60+
"""Predict using the linear model
61+
62+
Parameters
63+
----------
64+
X : numpy array of shape [n_samples, n_features]
65+
66+
Returns
67+
-------
68+
C : array, shape = [n_samples]
69+
Returns predicted values.
70+
"""
71+
return self.decision_function(X)
72+
5973
@staticmethod
6074
def _center_data(X, y, fit_intercept, normalize=False, copy=True):
6175
"""
@@ -250,7 +264,7 @@ def _validate_sample_weight(self, sample_weight, n_samples):
250264

251265
def _set_coef(self, coef_):
252266
"""Make sure that coef_ is fortran-style and 2d.
253-
267+
254268
Fortran-style memory layout is needed to ensure that computing
255269
the dot product between input ``X`` and ``coef_`` does not trigger
256270
a memory copy.

sklearn/linear_model/ridge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def fit(self, X, y, solver='auto'):
284284
return self
285285

286286
def decision_function(self, X):
287-
return Ridge.predict(self, X)
287+
return Ridge.decision_function(self, X)
288288

289289
def predict(self, X):
290290
"""Predict target values according to the fitted model.
@@ -569,7 +569,7 @@ def fit(self, X, y, sample_weight=1.0, class_weight=None):
569569
return self
570570

571571
def decision_function(self, X):
572-
return RidgeCV.predict(self, X)
572+
return RidgeCV.decision_function(self, X)
573573

574574
def predict(self, X):
575575
"""Predict target values according to the fitted model.

sklearn/linear_model/sparse/coordinate_descent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def fit(self, X, y):
105105
# return self for chaining fit and predict calls
106106
return self
107107

108-
def predict(self, X):
109-
"""Predict using the linear model
108+
def decision_function(self, X):
109+
"""Decision function of the linear model
110110
111111
Parameters
112112
----------

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy