Skip to content

Commit 2bd2d3d

Browse files
agoscinskiPicoCentauri
authored andcommitted
rename RidgeRegression2FoldCV -> Ridge2FoldCV
1 parent f48337f commit 2bd2d3d

File tree

8 files changed

+34
-36
lines changed

8 files changed

+34
-36
lines changed

docs/src/references/linear_models.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Orthogonal Regression
99
Ridge Regression with Two-fold Cross Validation
1010
-----------------------------------------------
1111

12-
.. autoclass:: skmatter.linear_model.RidgeRegression2FoldCV
12+
.. autoclass:: skmatter.linear_model.Ridge2FoldCV
1313

1414
PCovR
1515
-----

examples/regression/Ridge2FoldCVRegularization.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# %%
22

33
r"""
4-
RidgeRegression2FoldCV for data with low effective rank
4+
Ridge2FoldCV for data with low effective rank
55
=======================================================
66
In this notebook we explain in more detail how
7-
:class:`skmatter.linear_model.RidgeRegression2FoldCV` speeds up the
7+
:class:`skmatter.linear_model.Ridge2FoldCV` speeds up the
88
cross-validation optimizing the regularitzation parameter :param alpha: and
99
compare it with existing solution for that in scikit-learn
1010
:class:`slearn.linear_model.RidgeCV`.
11-
:class:`skmatter.linear_model.RidgeRegression2FoldCV` was designed to predict
11+
:class:`skmatter.linear_model.Ridge2FoldCV` was designed to predict
1212
efficiently feature matrices, but it can be also useful for the prediction
1313
single targets.
1414
"""
@@ -24,7 +24,7 @@
2424
from sklearn.metrics import mean_squared_error
2525
from sklearn.model_selection import KFold, train_test_split
2626

27-
from skmatter.linear_model import RidgeRegression2FoldCV
27+
from skmatter.linear_model import Ridge2FoldCV
2828

2929

3030
# %%
@@ -44,7 +44,7 @@
4444
# efficient leave-one-out CV (LOO CV) for its ridge regression which avoids
4545
# these repeated computations [loocv]_. Because we needed an efficient ridge that works
4646
# in predicting for the reconstruction measures in :py:mod:`skmatter.metrics`
47-
# we implemented with :class:`skmatter.linear_model.RidgeRegression2FoldCV` an
47+
# we implemented with :class:`skmatter.linear_model.Ridge2FoldCV` an
4848
# efficient 2-fold CV ridge regression that uses a singular value decomposition
4949
# (SVD) to reuse it for all regularization parameters :math:`\lambda`. Assuming
5050
# we have the standard regression problem optimizing the weight matrix in
@@ -75,7 +75,7 @@
7575
# \textrm{ prediction of }\mathbf{Y}\textrm{ for fold 2}
7676
# \end{align}
7777
#
78-
# The efficient 2-fold scheme in `RidgeRegression2FoldCV` reuses the matrices
78+
# The efficient 2-fold scheme in `Ridge2FoldCV` reuses the matrices
7979
#
8080
# .. math::
8181
#
@@ -107,11 +107,11 @@
107107
# 2 folds for train and validation split
108108
cv = KFold(n_splits=2, shuffle=True, random_state=SEED)
109109

110-
skmatter_ridge_2foldcv_cutoff = RidgeRegression2FoldCV(
110+
skmatter_ridge_2foldcv_cutoff = Ridge2FoldCV(
111111
alphas=alphas, regularization_method="cutoff", cv=cv
112112
)
113113

114-
skmatter_ridge_2foldcv_tikhonov = RidgeRegression2FoldCV(
114+
skmatter_ridge_2foldcv_tikhonov = Ridge2FoldCV(
115115
alphas=alphas, regularization_method="tikhonov", cv=cv
116116
)
117117

@@ -318,13 +318,13 @@ def get_train_test_error(estimator):
318318

319319
cv = KFold(n_splits=2, shuffle=True, random_state=SEED)
320320

321-
skmatter_ridge_2foldcv_cutoff = RidgeRegression2FoldCV(
321+
skmatter_ridge_2foldcv_cutoff = Ridge2FoldCV(
322322
alphas=alphas,
323323
regularization_method="cutoff",
324324
cv=cv,
325325
)
326326

327-
skmatter_ridge_2foldcv_tikhonov = RidgeRegression2FoldCV(
327+
skmatter_ridge_2foldcv_tikhonov = Ridge2FoldCV(
328328
alphas=alphas,
329329
regularization_method="tikhonov",
330330
cv=cv,

src/skmatter/linear_model/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from ._base import OrthogonalRegression
2-
from ._ridge import RidgeRegression2FoldCV
2+
from ._ridge import Ridge2FoldCV
33

4-
__all__ = ["OrthogonalRegression", "RidgeRegression2FoldCV"]
4+
__all__ = ["OrthogonalRegression", "Ridge2FoldCV"]

src/skmatter/linear_model/_ridge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from sklearn.utils.validation import check_is_fitted
88

99

10-
class RidgeRegression2FoldCV(BaseEstimator, MultiOutputMixin, RegressorMixin):
10+
class Ridge2FoldCV(BaseEstimator, MultiOutputMixin, RegressorMixin):
1111
r"""Ridge regression with an efficient 2-fold cross-validation method using the SVD
1212
solver.
1313

src/skmatter/metrics/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
for the regression of the feature matrix `X_F'` (or sometimes called `Y` in the
1111
doc) from `X_F` (or sometimes called `X` in the doc) for transformations with
1212
different constraints (linear, orthogonal, locally-linear). By default a custom
13-
2-fold cross-validation :py:class:`skosmo.linear_model.RidgeRegression2FoldCV`
13+
2-fold cross-validation :py:class:`skosmo.linear_model.Ridge2FoldCV`
1414
is used to ensure the generalization of the transformation and efficiency of the
1515
computation, since we deal with a multi-target regression problem. Methods were
1616
applied to compare different forms of featurizations through different

src/skmatter/metrics/_reconstruction_measures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
from joblib import Parallel, delayed
33

4-
from ..linear_model import OrthogonalRegression, RidgeRegression2FoldCV
4+
from ..linear_model import OrthogonalRegression, Ridge2FoldCV
55
from ..model_selection import train_test_split
66
from ..preprocessing import StandardFlexibleScaler
77

@@ -597,7 +597,7 @@ def check_global_reconstruction_measures_input(
597597
scaler = StandardFlexibleScaler()
598598

599599
if estimator is None:
600-
estimator = RidgeRegression2FoldCV(
600+
estimator = Ridge2FoldCV(
601601
alphas=np.geomspace(1e-9, 0.9, 20),
602602
alpha_type="relative",
603603
regularization_method="cutoff",

tests/test_check_estimators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from skmatter.feature_selection import FPS as fFPS
66
from skmatter.feature_selection import PCovCUR as fPCovCUR
77
from skmatter.feature_selection import PCovFPS as fPCovFPS
8-
from skmatter.linear_model import RidgeRegression2FoldCV # OrthogonalRegression,
8+
from skmatter.linear_model import Ridge2FoldCV # OrthogonalRegression,
99
from skmatter.preprocessing import KernelNormalizer, StandardFlexibleScaler
1010

1111

@@ -17,7 +17,7 @@
1717
fFPS(),
1818
fPCovCUR(),
1919
fPCovFPS(),
20-
RidgeRegression2FoldCV(),
20+
Ridge2FoldCV(),
2121
KernelNormalizer(),
2222
StandardFlexibleScaler(),
2323
]

tests/test_linear_model.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sklearn.datasets import load_iris
66
from sklearn.utils import check_random_state, extmath
77

8-
from skmatter.linear_model import OrthogonalRegression, RidgeRegression2FoldCV
8+
from skmatter.linear_model import OrthogonalRegression, Ridge2FoldCV
99

1010

1111
class BaseTests(unittest.TestCase):
@@ -108,37 +108,35 @@ def setUpClass(cls):
108108
cls.ridge_regressions = []
109109

110110
def test_ridge_regression_2fold_regularization_method_raise_error(self):
111-
# tests if wrong regularization_method in RidgeRegression2FoldCV raises error
111+
# tests if wrong regularization_method in Ridge2FoldCV raises error
112112
with self.assertRaises(ValueError):
113-
RidgeRegression2FoldCV(
113+
Ridge2FoldCV(
114114
regularization_method="dummy",
115115
).fit(self.features_small, self.features_small)
116116

117117
def test_ridge_regression_2fold_alpha_type_raise_error(self):
118-
# tests if wrong alpha type in RidgeRegression2FoldCV raises error
118+
# tests if wrong alpha type in Ridge2FoldCV raises error
119119
with self.assertRaises(ValueError):
120-
RidgeRegression2FoldCV(
120+
Ridge2FoldCV(
121121
alpha_type="dummy",
122122
).fit(self.features_small, self.features_small)
123123

124124
def test_ridge_regression_2fold_relative_alpha_type_raise_error(self):
125125
# tests if an error is raised if alpha not in [0,1)
126126
with self.assertRaises(ValueError):
127-
RidgeRegression2FoldCV(alphas=[1], alpha_type="relative").fit(
127+
Ridge2FoldCV(alphas=[1], alpha_type="relative").fit(
128128
self.features_small, self.features_small
129129
)
130130

131131
with self.assertRaises(ValueError):
132-
RidgeRegression2FoldCV(alphas=[-0.1], alpha_type="relative").fit(
132+
Ridge2FoldCV(alphas=[-0.1], alpha_type="relative").fit(
133133
self.features_small, self.features_small
134134
)
135135

136136
def test_ridge_regression_2fold_iterable_cv(self):
137137
# tests if we can use iterable as cv parameter
138138
cv = [([0, 1, 2, 3], [4, 5, 6])]
139-
RidgeRegression2FoldCV(alphas=[1], cv=cv).fit(
140-
self.features_small, self.features_small
141-
)
139+
Ridge2FoldCV(alphas=[1], cv=cv).fit(self.features_small, self.features_small)
142140

143141
ridge_parameters = [
144142
["absolute_tikhonov", "absolute", "tikhonov"],
@@ -151,11 +149,11 @@ def test_ridge_regression_2fold_iterable_cv(self):
151149
def test_ridge_regression_2fold_cv_small_to_small(
152150
self, name, alpha_type, regularization_method
153151
):
154-
# tests if RidgeRegression2FoldCV can predict small features using small
152+
# tests if Ridge2FoldCV can predict small features using small
155153
# features with use_orthogonal_projector False
156154
err = np.linalg.norm(
157155
self.features_small
158-
- RidgeRegression2FoldCV(
156+
- Ridge2FoldCV(
159157
alphas=self.alphas,
160158
alpha_type=alpha_type,
161159
regularization_method=regularization_method,
@@ -169,7 +167,7 @@ def test_ridge_regression_2fold_cv_small_to_small(
169167

170168
@parameterized.expand(ridge_parameters)
171169
def test_ridge_regression_2fold_cv_small_to_large(
172-
# tests if RidgeRegression2FoldCV can predict large features using small
170+
# tests if Ridge2FoldCV can predict large features using small
173171
# features with use_orthogonal_projector False
174172
self,
175173
name,
@@ -178,7 +176,7 @@ def test_ridge_regression_2fold_cv_small_to_large(
178176
):
179177
err = np.linalg.norm(
180178
self.features_large
181-
- RidgeRegression2FoldCV(
179+
- Ridge2FoldCV(
182180
alphas=self.alphas,
183181
alpha_type=alpha_type,
184182
regularization_method=regularization_method,
@@ -196,7 +194,7 @@ def test_ridge_regression_2fold_regularization(
196194
self, name, alpha_type, regularization_method
197195
):
198196
# tests if the regularization in the CV split of
199-
# RidgeRegression2FoldCV does effect the results
197+
# Ridge2FoldCV does effect the results
200198

201199
# regularization parameters are chosen to match the singular values o
202200
# the features, thus each regularization parameter affects the minimized
@@ -207,8 +205,8 @@ def test_ridge_regression_2fold_regularization(
207205
if alpha_type == "relative":
208206
alphas = singular_values[1:][::-1] / singular_values[0]
209207

210-
# tests if RidgeRegression2FoldCV does do regularization correct
211-
ridge = RidgeRegression2FoldCV(
208+
# tests if Ridge2FoldCV does do regularization correct
209+
ridge = Ridge2FoldCV(
212210
alphas=alphas,
213211
alpha_type=alpha_type,
214212
regularization_method=regularization_method,

0 commit comments

Comments
 (0)