8000 Merge branch 'obliquepr' of github.com:neurodata/scikit-learn into ob… · scikit-learn/scikit-learn@458220e · GitHub
[go: up one dir, main page]

Skip to content

Commit 458220e

Browse files
committed
Merge branch 'obliquepr' of github.com:neurodata/scikit-learn into obliquepr
2 parents 5aea4a0 + 7072ed2 commit 458220e

File tree

4 files changed

+53
-51
lines changed

4 files changed

+53
-51
lines changed

doc/modules/model_evaluation.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,7 +2196,7 @@ error (MAPE) estimated over :math:`n_{\text{samples}}` is defined as
21962196

21972197
.. math::
21982198
2199-
\text{MAPE}(y, \hat{y}) = \frac{1}{n_{\text{samples}}} \sum_{i=0}^{n_{\text{samples}}-1} \frac{{}\left| y_i - \hat{y}_i \right|}{max(\epsilon, \left| y_i \right|)}
2199+
\text{MAPE}(y, \hat{y}) = \frac{1}{n_{\text{samples}}} \sum_{i=0}^{n_{\text{samples}}-1} \frac{{}\left| y_i - \hat{y}_i \right|}{\max(\epsilon, \left| y_i \right|)}
22002200
22012201
where :math:`\epsilon` is an arbitrary small yet strictly positive number to
22022202
avoid undefined results when y is zero.
@@ -2267,7 +2267,7 @@ defined as
22672267

22682268
.. math::
22692269
2270-
\text{Max Error}(y, \hat{y}) = max(| y_i - \hat{y}_i |)
2270+
\text{Max Error}(y, \hat{y}) = \max(| y_i - \hat{y}_i |)
22712271
22722272
Here is a small example of usage of the :func:`max_error` function::
22732273

examples/ensemble/plot_bias_variance.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
predictions of the estimator differ from the predictions of the best possible
1313
estimator for the problem (i.e., the Bayes model). The variance term measures
1414
the variability of the predictions of the estimator when fit over different
15-
instances LS of the problem. Finally, the noise measures the irreducible part
15+
random instances of the same problem. Each problem instance is noted "LS", for
16+
"Learning Sample", in the following. Finally, the noise measures the irreducible part
1617
of the error which is due the variability in the data.
1718
1819
The upper left figure illustrates the predictions (in dark red) of a single

sklearn/inspection/_partial_dependence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ def _partial_dependence_brute(est, grid, features, X, response_method):
146146
else:
147147
raise ValueError("The estimator has no decision_function method.")
148148

149+
X_eval = X.copy()
149150
for new_values in grid:
150-
X_eval = X.copy()
151151
for i, variable in enumerate(features):
152152
if hasattr(X_eval, "iloc"):
153153
X_eval.iloc[:, variable] = new_values[i]

sklearn/random_projection.py

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,11 @@ def __init__(
305305
n_components="auto",
306306
*,
307307
eps=0.1,
308-
dense_output=False,
309308
compute_inverse_components=False,
310309
random_state=None,
311310
):
312311
self.n_components = n_components
313312
self.eps = eps
314-
self.dense_output = dense_output
315313
self.compute_inverse_components = compute_inverse_components
316314
self.random_state = random_state
317315

@@ -405,45 +403,11 @@ def fit(self, X, y=None):
405403
self.n_components_, n_features
406404
).astype(X.dtype, copy=False)
407405

408-
# Check contract
409-
assert self.components_.shape == (self.n_components_, n_features), (
410-
"An error has occurred the self.components_ matrix has "
411-
" not the proper shape."
412-
)
413-
414406
if self.compute_inverse_components:
415407
self.inverse_components_ = self._compute_inverse_components()
416408

417409
return self
418410

419-
def transform(self, X):
420-
"""Project the data by using matrix product with the random matrix.
421-
422-
Parameters
423-
----------
424-
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
425-
The input data to project into a smaller dimensional space.
426-
427-
Returns
428-
-------
429-
X_new : {ndarray, sparse matrix} of shape (n_samples, n_components)
430-
Projected array.
431-
"""
432-
check_is_fitted(self)
433-
X = self._validate_data(
434-
X, accept_sparse=["csr", "csc"], reset=False, dtype=[np.float64, np.float32]
435-
)
436-
437-
if X.shape[1] != self.components_.shape[1]:
438-
raise ValueError(
439-
"Impossible to perform projection:"
440-
"X at fit stage had a different number of features. "
441-
"(%s != %s)" % (X.shape[1], self.components_.shape[1])
442-
)
443-
444-
X_new = safe_sparse_dot(X, self.components_.T, dense_output=self.dense_output)
445-
return X_new
446-
447411
@property
448412
def _n_features_out(self):
449413
"""Number of transformed output features.
@@ -582,13 +546,12 @@ def __init__(
582546
super().__init__(
583547
n_components=n_components,
584548
eps=eps,
585-
dense_output=True,
586549
compute_inverse_components=compute_inverse_components,
587550
random_state=random_state,
588551
)
589552

590553
def _make_random_matrix(self, n_components, n_features):
591-
""" Generate the random projection matrix.
554+
"""Generate the random projection matrix.
592555
593556
Parameters
594557
----------
@@ -600,16 +563,34 @@ def _make_random_matrix(self, n_components, n_features):
600563
601564
Returns
602565
-------
603-
components : {ndarray, sparse matrix} of shape \
604-
(n_components, n_features)
605-
The generated random matrix. Sparse matrix will be of CSR format.
606-
566+
components : ndarray of shape (n_components, n_features)
567+
The generated random matrix.
607568
"""
608569
random_state = check_random_state(self.random_state)
609570
return _gaussian_random_matrix(
610571
n_components, n_features, random_state=random_state
611572
)
612573

574+
def transform(self, X):
575+
"""Project the data by using matrix product with the random matrix.
576+
577+
Parameters
578+
----------
579+
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
580+
The input data to project into a smaller dimensional space.
581+
582+
Returns
583+
-------
584+
X_new : ndarray of shape (n_samples, n_components)
585+
Projected array.
586+
"""
587+
check_is_fitted(self)
588+
X = self._validate_data(
589+
X, accept_sparse=["csr", "csc"], reset=False, dtype=[np.float64, np.float32]
590+
)
591+
592+
return X @ self.components_.T
593+
613594

614595
class SparseRandomProjection(BaseRandomProjection):
615596
"""Reduce dimensionality through sparse random projection.
@@ -759,15 +740,15 @@ def __init__(
759740
super().__init__(
760741
n_components=n_components,
761742
eps=eps,
762-
dense_output=dense_output,
763743
compute_inverse_components=compute_inverse_components,
764744
random_state=random_state,
765745
)
766746

747+
self.dense_output = dense_output
767748
self.density = density
768749

769750
def _make_random_matrix(self, n_components, n_features):
770-
""" Generate the random projection matrix
751+
"""Generate the random projection matrix
771752
772753
Parameters
773754
----------
@@ -779,13 +760,33 @@ def _make_random_matrix(self, n_components, n_features):
779760
780761
Returns
781762
-------
782-
components : {ndarray, sparse matrix} of shape \
783-
(n_components, n_features)
784-
DD87 The generated random matrix. Sparse matrix will be of CSR format.
763+
components : sparse matrix of shape (n_components, n_features)
764+
The generated random matrix in CSR format.
785765
786766
"""
787767
random_state = check_random_state(self.random_state)
788768
self.density_ = _check_density(self.density, n_features)
789769
return _sparse_random_matrix(
790770
n_components, n_features, density=self.density_, random_state=random_state
791771
)
772+
773+
def transform(self, X):
774+
"""Project the data by using matrix product with the random matrix.
775+
776+
Parameters
777+
----------
778+
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
779+
The input data to project into a smaller dimensional space.
780+
781+
Returns
782+
-------
783+
X_new : {ndarray, sparse matrix} of shape (n_samples, n_components)
784+
Projected array. It is a sparse matrix only when the input is sparse and
785+
`dense_output = False`.
786+
"""
787+
check_is_fitted(self)
788+
X = self._validate_data(
789+
X, accept_sparse=["csr", "csc"], reset=False, dtype=[np.float64, np.float32]
790+
)
791+
792+
return safe_sparse_dot(X, self.components_.T, dense_output=self.dense_output)

0 commit comments

Comments
 (0)
0