Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[MRG] Simplify linear models #2444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions sklearn/linear_model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ class LinearModel(six.with_metaclass(ABCMeta, BaseEstimator)):
def fit(self, X, y):
"""Fit model."""

def decision_function(self, X):
"""Decision function of the linear model.
def predict(self, X):
"""Predict using the linear model.

Parameters
----------
Expand All @@ -143,21 +143,6 @@ def decision_function(self, X):
return safe_sparse_dot(X, self.coef_.T,
dense_output=True) + self.intercept_

def predict(self, X):
"""Predict using the linear model

Parameters
----------
X : {array-like, sparse matrix}, shape = (n_samples, n_features)
Samples.

Returns
-------
C : array, shape = (n_samples,)
Returns predicted values.
"""
return self.decision_function(X)

_center_data = staticmethod(center_data)

def _set_intercept(self, X_mean, y_mean, X_std):
Expand Down
27 changes: 6 additions & 21 deletions sklearn/linear_model/coordinate_descent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import numpy as np
from scipy import sparse

from .base import LinearModel, _pre_fit
from .base import LinearModel, _pre_fit, SparseCoefMixin
from ..base import RegressorMixin
from .base import center_data
from ..utils import array2d, atleast2d_or_csc, deprecated
Expand Down Expand Up @@ -445,7 +445,7 @@ def enet_path(X, y, l1_ratio=0.5, eps=1e-3, n_alphas=100, alphas=None,
# ElasticNet model


class ElasticNet(LinearModel, RegressorMixin):
class ElasticNet(LinearModel, RegressorMixin, SparseCoefMixin):
"""Linear Model trained with L1 and L2 prior as regularizer

Minimizes the objective function::
Expand Down Expand Up @@ -625,27 +625,12 @@ def fit(self, X, y, coef_init=None):

@property
def sparse_coef_(self):
""" sparse representation of the fitted coef """
"""Sparse representation of the fitted coef_."""
warnings.warn("sparse_coef_ is deprecated and will be removed in 0.17."
" Call the sparsify method instead.",
DeprecationWarning)
return sparse.csr_matrix(self.coef_)

def decision_function(self, X):
"""Decision function of the linear model

Parameters
----------
X : numpy array or scipy.sparse matrix of shape (n_samples, n_features)

Returns
-------
T : array, shape = (n_samples,)
The predicted decision function
"""
if sparse.isspmatrix(X):
return np.ravel(safe_sparse_dot(self.coef_, X.T, dense_output=True)
+ self.intercept_)
else:
return super(ElasticNet, self).decision_function(X)


###############################################################################
# Lasso model
Expand Down
2 changes: 0 additions & 2 deletions sklearn/linear_model/tests/test_least_angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,6 @@ def test_multitarget():
for estimator in (linear_model.LassoLars(), linear_model.Lars()):
estimator.fit(X, Y)
Y_pred = estimator.predict(X)
Y_dec = estimator.decision_function(X)
assert_array_almost_equal(Y_pred, Y_dec)
alphas, active, coef, path = (estimator.alphas_, estimator.active_,
estimator.coef_, estimator.coef_path_)
for k in range(n_targets):
Expand Down