code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def test_kernel_pca_feature_names_out(): """Check feature names out for KernelPCA.""" X, *_ = make_blobs(n_samples=100, n_features=4, random_state=0) kpca = KernelPCA(n_components=2).fit(X) names = kpca.get_feature_names_out() assert_array_equal([f"kernelpca{i}" for i in range(2)], names)
Check feature names out for KernelPCA.
test_kernel_pca_feature_names_out
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_kernel_pca.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_kernel_pca.py
BSD-3-Clause
def test_kernel_pca_inverse_correct_gamma(global_random_seed): """Check that gamma is set correctly when not provided. Non-regression test for #26280 """ rng = np.random.RandomState(global_random_seed) X = rng.random_sample((5, 4)) kwargs = { "n_components": 2, "random_state": ...
Check that gamma is set correctly when not provided. Non-regression test for #26280
test_kernel_pca_inverse_correct_gamma
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_kernel_pca.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_kernel_pca.py
BSD-3-Clause
def test_kernel_pca_pandas_output(): """Check that KernelPCA works with pandas output when the solver is arpack. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/27579 """ pytest.importorskip("pandas") X, _ = load_iris(as_frame=True, return_X_y=True) with sklearn...
Check that KernelPCA works with pandas output when the solver is arpack. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/27579
test_kernel_pca_pandas_output
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_kernel_pca.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_kernel_pca.py
BSD-3-Clause
def _beta_divergence_dense(X, W, H, beta): """Compute the beta-divergence of X and W.H for dense array only. Used as a reference for testing nmf._beta_divergence. """ WH = np.dot(W, H) if beta == 2: return squared_norm(X - WH) / 2 WH_Xnonzero = WH[X != 0] X_nonzero = X[X != 0] ...
Compute the beta-divergence of X and W.H for dense array only. Used as a reference for testing nmf._beta_divergence.
_beta_divergence_dense
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_nmf.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_nmf.py
BSD-3-Clause
def test_minibatch_nmf_negative_beta_loss(beta_loss): """Check that an error is raised if beta_loss < 0 and X contains zeros.""" rng = np.random.RandomState(0) X = rng.normal(size=(6, 5)) X[X < 0] = 0 nmf = MiniBatchNMF(beta_loss=beta_loss, random_state=0) msg = "When beta_loss <= 0 and X cont...
Check that an error is raised if beta_loss < 0 and X contains zeros.
test_minibatch_nmf_negative_beta_loss
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_nmf.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_nmf.py
BSD-3-Clause
def test_feature_names_out(): """Check feature names out for NMF.""" random_state = np.random.RandomState(0) X = np.abs(random_state.randn(10, 4)) nmf = NMF(n_components=3).fit(X) names = nmf.get_feature_names_out() assert_array_equal([f"nmf{i}" for i in range(3)], names)
Check feature names out for NMF.
test_feature_names_out
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_nmf.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_nmf.py
BSD-3-Clause
def test_lda_empty_docs(csr_container): """Test LDA on empty document (all-zero rows).""" Z = np.zeros((5, 4)) for X in [Z, csr_container(Z)]: lda = LatentDirichletAllocation(max_iter=750).fit(X) assert_almost_equal( lda.components_.sum(axis=0), np.ones(lda.components_.shape[1]) ...
Test LDA on empty document (all-zero rows).
test_lda_empty_docs
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_online_lda.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_online_lda.py
BSD-3-Clause
def test_dirichlet_expectation(): """Test Cython version of Dirichlet expectation calculation.""" x = np.logspace(-100, 10, 10000) expectation = np.empty_like(x) _dirichlet_expectation_1d(x, 0, expectation) assert_allclose(expectation, np.exp(psi(x) - psi(np.sum(x))), atol=1e-19) x = x.reshape(...
Test Cython version of Dirichlet expectation calculation.
test_dirichlet_expectation
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_online_lda.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_online_lda.py
BSD-3-Clause
def test_lda_feature_names_out(csr_container): """Check feature names out for LatentDirichletAllocation.""" n_components, X = _build_sparse_array(csr_container) lda = LatentDirichletAllocation(n_components=n_components).fit(X) names = lda.get_feature_names_out() assert_array_equal( [f"laten...
Check feature names out for LatentDirichletAllocation.
test_lda_feature_names_out
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_online_lda.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_online_lda.py
BSD-3-Clause
def test_lda_dtype_match(learning_method, global_dtype): """Check data type preservation of fitted attributes.""" rng = np.random.RandomState(0) X = rng.uniform(size=(20, 10)).astype(global_dtype, copy=False) lda = LatentDirichletAllocation( n_components=5, random_state=0, learning_method=learn...
Check data type preservation of fitted attributes.
test_lda_dtype_match
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_online_lda.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_online_lda.py
BSD-3-Clause
def test_lda_numerical_consistency(learning_method, global_random_seed): """Check numerical consistency between np.float32 and np.float64.""" rng = np.random.RandomState(global_random_seed) X64 = rng.uniform(size=(20, 10)) X32 = X64.astype(np.float32) lda_64 = LatentDirichletAllocation( n_c...
Check numerical consistency between np.float32 and np.float64.
test_lda_numerical_consistency
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_online_lda.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_online_lda.py
BSD-3-Clause
def test_pca_sparse( global_random_seed, svd_solver, sparse_container, n_components, density, scale ): """Check that the results are the same for sparse and dense input.""" # Set atol in addition of the default rtol to account for the very wide range of # result values (1e-8 to 1e0). atol = 1e-12 ...
Check that the results are the same for sparse and dense input.
test_pca_sparse
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_pca.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_pca.py
BSD-3-Clause
def test_sparse_pca_auto_arpack_singluar_values_consistency( global_random_seed, sparse_container ): """Check that "auto" and "arpack" solvers are equivalent for sparse inputs.""" random_state = np.random.RandomState(global_random_seed) X = sparse_container( sp.sparse.random( SPARSE_...
Check that "auto" and "arpack" solvers are equivalent for sparse inputs.
test_sparse_pca_auto_arpack_singluar_values_consistency
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_pca.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_pca.py
BSD-3-Clause
def test_pca_randomized_svd_n_oversamples(): """Check that exposing and setting `n_oversamples` will provide accurate results even when `X` as a large number of features. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/20589 """ rng = np.random.RandomState(0) n_...
Check that exposing and setting `n_oversamples` will provide accurate results even when `X` as a large number of features. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/20589
test_pca_randomized_svd_n_oversamples
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_pca.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_pca.py
BSD-3-Clause
def test_feature_names_out(): """Check feature names out for PCA.""" pca = PCA(n_components=2).fit(iris.data) names = pca.get_feature_names_out() assert_array_equal([f"pca{i}" for i in range(2)], names)
Check feature names out for PCA.
test_feature_names_out
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_pca.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_pca.py
BSD-3-Clause
def test_variance_correctness(copy): """Check the accuracy of PCA's internal variance calculation""" rng = np.random.RandomState(0) X = rng.randn(1000, 200) pca = PCA().fit(X) pca_var = pca.explained_variance_ / pca.explained_variance_ratio_ true_var = np.var(X, ddof=1, axis=0).sum() np.test...
Check the accuracy of PCA's internal variance calculation
test_variance_correctness
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_pca.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_pca.py
BSD-3-Clause
def test_spca_feature_names_out(SPCA): """Check feature names out for *SparsePCA.""" rng = np.random.RandomState(0) n_samples, n_features = 12, 10 X = rng.randn(n_samples, n_features) model = SPCA(n_components=4).fit(X) names = model.get_feature_names_out() estimator_name = SPCA.__name__.l...
Check feature names out for *SparsePCA.
test_spca_feature_names_out
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_sparse_pca.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_sparse_pca.py
BSD-3-Clause
def test_spca_early_stopping(global_random_seed): """Check that `tol` and `max_no_improvement` act as early stopping.""" rng = np.random.RandomState(global_random_seed) n_samples, n_features = 50, 10 X = rng.randn(n_samples, n_features) # vary the tolerance to force the early stopping of one of the...
Check that `tol` and `max_no_improvement` act as early stopping.
test_spca_early_stopping
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_sparse_pca.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_sparse_pca.py
BSD-3-Clause
def test_equivalence_components_pca_spca(global_random_seed): """Check the equivalence of the components found by PCA and SparsePCA. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/23932 """ rng = np.random.RandomState(global_random_seed) X = rng.randn(50, 4) n...
Check the equivalence of the components found by PCA and SparsePCA. Non-regression test for: https://github.com/scikit-learn/scikit-learn/issues/23932
test_equivalence_components_pca_spca
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_sparse_pca.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_sparse_pca.py
BSD-3-Clause
def test_sparse_pca_inverse_transform(global_random_seed): """Check that `inverse_transform` in `SparsePCA` and `PCA` are similar.""" rng = np.random.RandomState(global_random_seed) n_samples, n_features = 10, 5 X = rng.randn(n_samples, n_features) n_components = 2 spca = SparsePCA( n_c...
Check that `inverse_transform` in `SparsePCA` and `PCA` are similar.
test_sparse_pca_inverse_transform
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_sparse_pca.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_sparse_pca.py
BSD-3-Clause
def test_transform_inverse_transform_round_trip(SPCA, global_random_seed): """Check the `transform` and `inverse_transform` round trip with no loss of information. """ rng = np.random.RandomState(global_random_seed) n_samples, n_features = 10, 5 X = rng.randn(n_samples, n_features) n_compon...
Check the `transform` and `inverse_transform` round trip with no loss of information.
test_transform_inverse_transform_round_trip
python
scikit-learn/scikit-learn
sklearn/decomposition/tests/test_sparse_pca.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/decomposition/tests/test_sparse_pca.py
BSD-3-Clause
def _generate_bagging_indices( random_state, bootstrap_features, bootstrap_samples, n_features, n_samples, max_features, max_samples, ): """Randomly draw feature and sample indices.""" # Get valid random state random_state = check_random_state(random_state) # Draw indices ...
Randomly draw feature and sample indices.
_generate_bagging_indices
python
scikit-learn/scikit-learn
sklearn/ensemble/_bagging.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_bagging.py
BSD-3-Clause
def _parallel_build_estimators( n_estimators, ensemble, X, y, seeds, total_n_estimators, verbose, check_input, fit_params, ): """Private function used to build a batch of estimators within a job.""" # Retrieve settings n_samples, n_features = X.shape max_features = en...
Private function used to build a batch of estimators within a job.
_parallel_build_estimators
python
scikit-learn/scikit-learn
sklearn/ensemble/_bagging.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_bagging.py
BSD-3-Clause
def _parallel_predict_proba( estimators, estimators_features, X, n_classes, predict_params=None, predict_proba_params=None, ): """Private function used to compute (proba-)predictions within a job.""" n_samples = X.shape[0] proba = np.zeros((n_samples, n_classes)) for estimator, ...
Private function used to compute (proba-)predictions within a job.
_parallel_predict_proba
python
scikit-learn/scikit-learn
sklearn/ensemble/_bagging.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_bagging.py
BSD-3-Clause
def _parallel_predict_log_proba(estimators, estimators_features, X, n_classes, params): """Private function used to compute log probabilities within a job.""" n_samples = X.shape[0] log_proba = np.empty((n_samples, n_classes)) log_proba.fill(-np.inf) all_classes = np.arange(n_classes, dtype=int) ...
Private function used to compute log probabilities within a job.
_parallel_predict_log_proba
python
scikit-learn/scikit-learn
sklearn/ensemble/_bagging.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_bagging.py
BSD-3-Clause
def _parallel_decision_function(estimators, estimators_features, X, params): """Private function used to compute decisions within a job.""" return sum( estimator.decision_function(X[:, features], **params) for estimator, features in zip(estimators, estimators_features) )
Private function used to compute decisions within a job.
_parallel_decision_function
python
scikit-learn/scikit-learn
sklearn/ensemble/_bagging.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_bagging.py
BSD-3-Clause
def _parallel_predict_regression(estimators, estimators_features, X, params): """Private function used to compute predictions within a job.""" return sum( estimator.predict(X[:, features], **params) for estimator, features in zip(estimators, estimators_features) )
Private function used to compute predictions within a job.
_parallel_predict_regression
python
scikit-learn/scikit-learn
sklearn/ensemble/_bagging.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_bagging.py
BSD-3-Clause
def fit(self, X, y, sample_weight=None, **fit_params): """Build a Bagging ensemble of estimators from the training set (X, y). Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The training input samples. Sparse matrices are accepted only...
Build a Bagging ensemble of estimators from the training set (X, y). Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The training input samples. Sparse matrices are accepted only if they are supported by the base estimator. ...
fit
python
scikit-learn/scikit-learn
sklearn/ensemble/_bagging.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_bagging.py
BSD-3-Clause
def _fit( self, X, y, max_samples=None, max_depth=None, check_input=True, sample_weight=None, **fit_params, ): """Build a Bagging ensemble of estimators from the training set (X, y). Parameters ---------- X :...
Build a Bagging ensemble of estimators from the training set (X, y). Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The training input samples. Sparse matrices are accepted only if they are supported by the base estimato...
_fit
python
scikit-learn/scikit-learn
sklearn/ensemble/_bagging.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_bagging.py
BSD-3-Clause
def _get_estimator(self): """Resolve which estimator to return (default is DecisionTreeClassifier)""" if self.estimator is None: return DecisionTreeClassifier() return self.estimator
Resolve which estimator to return (default is DecisionTreeClassifier)
_get_estimator
python
scikit-learn/scikit-learn
sklearn/ensemble/_bagging.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_bagging.py
BSD-3-Clause
def predict(self, X, **params): """Predict class for X. The predicted class of an input sample is computed as the class with the highest mean predicted probability. If base estimators do not implement a ``predict_proba`` method, then it resorts to voting. Parameters ---...
Predict class for X. The predicted class of an input sample is computed as the class with the highest mean predicted probability. If base estimators do not implement a ``predict_proba`` method, then it resorts to voting. Parameters ---------- X : {array-like, sparse mat...
predict
python
scikit-learn/scikit-learn
sklearn/ensemble/_bagging.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_bagging.py
BSD-3-Clause
def predict_proba(self, X, **params): """Predict class probabilities for X. The predicted class probabilities of an input sample is computed as the mean predicted class probabilities of the base estimators in the ensemble. If base estimators do not implement a ``predict_proba`` ...
Predict class probabilities for X. The predicted class probabilities of an input sample is computed as the mean predicted class probabilities of the base estimators in the ensemble. If base estimators do not implement a ``predict_proba`` method, then it resorts to voting and the predict...
predict_proba
python
scikit-learn/scikit-learn
sklearn/ensemble/_bagging.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_bagging.py
BSD-3-Clause
def predict_log_proba(self, X, **params): """Predict class log-probabilities for X. The predicted class log-probabilities of an input sample is computed as the log of the mean predicted class probabilities of the base estimators in the ensemble. Parameters ---------- ...
Predict class log-probabilities for X. The predicted class log-probabilities of an input sample is computed as the log of the mean predicted class probabilities of the base estimators in the ensemble. Parameters ---------- X : {array-like, sparse matrix} of shape (n_sam...
predict_log_proba
python
scikit-learn/scikit-learn
sklearn/ensemble/_bagging.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_bagging.py
BSD-3-Clause
def decision_function(self, X, **params): """Average of the decision functions of the base classifiers. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The training input samples. Sparse matrices are accepted only if they ar...
Average of the decision functions of the base classifiers. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The training input samples. Sparse matrices are accepted only if they are supported by the base estimator. **params ...
decision_function
python
scikit-learn/scikit-learn
sklearn/ensemble/_bagging.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_bagging.py
BSD-3-Clause
def predict(self, X, **params): """Predict regression target for X. The predicted regression target of an input sample is computed as the mean predicted regression targets of the estimators in the ensemble. Parameters ---------- X : {array-like, sparse matrix} of shape ...
Predict regression target for X. The predicted regression target of an input sample is computed as the mean predicted regression targets of the estimators in the ensemble. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The tra...
predict
python
scikit-learn/scikit-learn
sklearn/ensemble/_bagging.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_bagging.py
BSD-3-Clause
def _fit_single_estimator( estimator, X, y, fit_params, message_clsname=None, message=None ): """Private function used to fit an estimator within a job.""" # TODO(SLEP6): remove if-condition for unrouted sample_weight when metadata # routing can't be disabled. if not _routing_enabled() and "sample_w...
Private function used to fit an estimator within a job.
_fit_single_estimator
python
scikit-learn/scikit-learn
sklearn/ensemble/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_base.py
BSD-3-Clause
def _set_random_states(estimator, random_state=None): """Set fixed random_state parameters for an estimator. Finds all parameters ending ``random_state`` and sets them to integers derived from ``random_state``. Parameters ---------- estimator : estimator supporting get/set_params Estim...
Set fixed random_state parameters for an estimator. Finds all parameters ending ``random_state`` and sets them to integers derived from ``random_state``. Parameters ---------- estimator : estimator supporting get/set_params Estimator with potential randomness managed by random_state ...
_set_random_states
python
scikit-learn/scikit-learn
sklearn/ensemble/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_base.py
BSD-3-Clause
def _validate_estimator(self, default=None): """Check the base estimator. Sets the `estimator_` attributes. """ if self.estimator is not None: self.estimator_ = self.estimator else: self.estimator_ = default
Check the base estimator. Sets the `estimator_` attributes.
_validate_estimator
python
scikit-learn/scikit-learn
sklearn/ensemble/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_base.py
BSD-3-Clause
def _make_estimator(self, append=True, random_state=None): """Make and configure a copy of the `estimator_` attribute. Warning: This method should be used to properly instantiate new sub-estimators. """ estimator = clone(self.estimator_) estimator.set_params(**{p: getatt...
Make and configure a copy of the `estimator_` attribute. Warning: This method should be used to properly instantiate new sub-estimators.
_make_estimator
python
scikit-learn/scikit-learn
sklearn/ensemble/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_base.py
BSD-3-Clause
def _partition_estimators(n_estimators, n_jobs): """Private function used to partition estimators between jobs.""" # Compute the number of jobs n_jobs = min(effective_n_jobs(n_jobs), n_estimators) # Partition estimators between jobs n_estimators_per_job = np.full(n_jobs, n_estimators // n_jobs, dty...
Private function used to partition estimators between jobs.
_partition_estimators
python
scikit-learn/scikit-learn
sklearn/ensemble/_base.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_base.py
BSD-3-Clause
def _get_n_samples_bootstrap(n_samples, max_samples): """ Get the number of samples in a bootstrap sample. Parameters ---------- n_samples : int Number of samples in the dataset. max_samples : int or float The maximum number of samples to draw from the total available: ...
Get the number of samples in a bootstrap sample. Parameters ---------- n_samples : int Number of samples in the dataset. max_samples : int or float The maximum number of samples to draw from the total available: - if float, this indicates a fraction of the total and sho...
_get_n_samples_bootstrap
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def _generate_unsampled_indices(random_state, n_samples, n_samples_bootstrap): """ Private function used to forest._set_oob_score function.""" sample_indices = _generate_sample_indices( random_state, n_samples, n_samples_bootstrap ) sample_counts = np.bincount(sample_indices, minlength=n_sam...
Private function used to forest._set_oob_score function.
_generate_unsampled_indices
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def _parallel_build_trees( tree, bootstrap, X, y, sample_weight, tree_idx, n_trees, verbose=0, class_weight=None, n_samples_bootstrap=None, missing_values_in_feature_mask=None, ): """ Private function used to fit a single tree in parallel.""" if verbose > 1: ...
Private function used to fit a single tree in parallel.
_parallel_build_trees
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def apply(self, X): """ Apply trees in the forest to X, return leaf indices. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, its dtype will be converted to ``dtype=np.float32``. If a sp...
Apply trees in the forest to X, return leaf indices. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, its dtype will be converted to ``dtype=np.float32``. If a sparse matrix is provided, it wil...
apply
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def decision_path(self, X): """ Return the decision path in the forest. .. versionadded:: 0.18 Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, its dtype will be converted to ``...
Return the decision path in the forest. .. versionadded:: 0.18 Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, its dtype will be converted to ``dtype=np.float32``. If a sparse matrix ...
decision_path
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def fit(self, X, y, sample_weight=None): """ Build a forest of trees from the training set (X, y). Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The training input samples. Internally, its dtype will be converted t...
Build a forest of trees from the training set (X, y). Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The training input samples. Internally, its dtype will be converted to ``dtype=np.float32``. If a sparse matrix is provid...
fit
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def _set_oob_score_and_attributes(self, X, y, scoring_function=None): """Compute and set the OOB score and attributes. Parameters ---------- X : array-like of shape (n_samples, n_features) The data matrix. y : ndarray of shape (n_samples, n_outputs) The t...
Compute and set the OOB score and attributes. Parameters ---------- X : array-like of shape (n_samples, n_features) The data matrix. y : ndarray of shape (n_samples, n_outputs) The target matrix. scoring_function : callable, default=None Scori...
_set_oob_score_and_attributes
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def _compute_oob_predictions(self, X, y): """Compute and set the OOB score. Parameters ---------- X : array-like of shape (n_samples, n_features) The data matrix. y : ndarray of shape (n_samples, n_outputs) The target matrix. Returns ----...
Compute and set the OOB score. Parameters ---------- X : array-like of shape (n_samples, n_features) The data matrix. y : ndarray of shape (n_samples, n_outputs) The target matrix. Returns ------- oob_pred : ndarray of shape (n_samples, n...
_compute_oob_predictions
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def _validate_X_predict(self, X): """ Validate X whenever one tries to predict, apply, predict_proba.""" check_is_fitted(self) if self.estimators_[0]._support_missing_values(X): ensure_all_finite = "allow-nan" else: ensure_all_finite = True X = va...
Validate X whenever one tries to predict, apply, predict_proba.
_validate_X_predict
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def feature_importances_(self): """ The impurity-based feature importances. The higher, the more important the feature. The importance of a feature is computed as the (normalized) total reduction of the criterion brought by that feature. It is also known as the Gini imp...
The impurity-based feature importances. The higher, the more important the feature. The importance of a feature is computed as the (normalized) total reduction of the criterion brought by that feature. It is also known as the Gini importance. Warning: impurity-based f...
feature_importances_
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def _accumulate_prediction(predict, X, out, lock): """ This is a utility function for joblib's Parallel. It can't go locally in ForestClassifier or ForestRegressor, because joblib complains that it cannot pickle it when placed there. """ prediction = predict(X, check_input=False) with lock:...
This is a utility function for joblib's Parallel. It can't go locally in ForestClassifier or ForestRegressor, because joblib complains that it cannot pickle it when placed there.
_accumulate_prediction
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def _get_oob_predictions(tree, X): """Compute the OOB predictions for an individual tree. Parameters ---------- tree : DecisionTreeClassifier object A single decision tree classifier. X : ndarray of shape (n_samples, n_features) The OOB samples. ...
Compute the OOB predictions for an individual tree. Parameters ---------- tree : DecisionTreeClassifier object A single decision tree classifier. X : ndarray of shape (n_samples, n_features) The OOB samples. Returns ------- y_pred : ndarr...
_get_oob_predictions
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def _set_oob_score_and_attributes(self, X, y, scoring_function=None): """Compute and set the OOB score and attributes. Parameters ---------- X : array-like of shape (n_samples, n_features) The data matrix. y : ndarray of shape (n_samples, n_outputs) The t...
Compute and set the OOB score and attributes. Parameters ---------- X : array-like of shape (n_samples, n_features) The data matrix. y : ndarray of shape (n_samples, n_outputs) The target matrix. scoring_function : callable, default=None Scori...
_set_oob_score_and_attributes
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def predict(self, X): """ Predict class for X. The predicted class of an input sample is a vote by the trees in the forest, weighted by their probability estimates. That is, the predicted class is the one with highest mean probability estimate across the trees. ...
Predict class for X. The predicted class of an input sample is a vote by the trees in the forest, weighted by their probability estimates. That is, the predicted class is the one with highest mean probability estimate across the trees. Parameters ---------- ...
predict
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def predict_proba(self, X): """ Predict class probabilities for X. The predicted class probabilities of an input sample are computed as the mean predicted class probabilities of the trees in the forest. The class probability of a single tree is the fraction of samples of ...
Predict class probabilities for X. The predicted class probabilities of an input sample are computed as the mean predicted class probabilities of the trees in the forest. The class probability of a single tree is the fraction of samples of the same class in a leaf. Par...
predict_proba
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def predict_log_proba(self, X): """ Predict class log-probabilities for X. The predicted class log-probabilities of an input sample is computed as the log of the mean predicted class probabilities of the trees in the forest. Parameters ---------- X : {ar...
Predict class log-probabilities for X. The predicted class log-probabilities of an input sample is computed as the log of the mean predicted class probabilities of the trees in the forest. Parameters ---------- X : {array-like, sparse matrix} of shape (n_sample...
predict_log_proba
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def predict(self, X): """ Predict regression target for X. The predicted regression target of an input sample is computed as the mean predicted regression targets of the trees in the forest. Parameters ---------- X : {array-like, sparse matrix} of shape (n_sampl...
Predict regression target for X. The predicted regression target of an input sample is computed as the mean predicted regression targets of the trees in the forest. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The i...
predict
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def _get_oob_predictions(tree, X): """Compute the OOB predictions for an individual tree. Parameters ---------- tree : DecisionTreeRegressor object A single decision tree regressor. X : ndarray of shape (n_samples, n_features) The OOB samples. Re...
Compute the OOB predictions for an individual tree. Parameters ---------- tree : DecisionTreeRegressor object A single decision tree regressor. X : ndarray of shape (n_samples, n_features) The OOB samples. Returns ------- y_pred : ndarray...
_get_oob_predictions
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def _set_oob_score_and_attributes(self, X, y, scoring_function=None): """Compute and set the OOB score and attributes. Parameters ---------- X : array-like of shape (n_samples, n_features) The data matrix. y : ndarray of shape (n_samples, n_outputs) The t...
Compute and set the OOB score and attributes. Parameters ---------- X : array-like of shape (n_samples, n_features) The data matrix. y : ndarray of shape (n_samples, n_outputs) The target matrix. scoring_function : callable, default=None Scori...
_set_oob_score_and_attributes
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def _compute_partial_dependence_recursion(self, grid, target_features): """Fast partial dependence computation. Parameters ---------- grid : ndarray of shape (n_samples, n_target_features), dtype=DTYPE The grid points on which the partial dependence should be eva...
Fast partial dependence computation. Parameters ---------- grid : ndarray of shape (n_samples, n_target_features), dtype=DTYPE The grid points on which the partial dependence should be evaluated. target_features : ndarray of shape (n_target_features), dtype=np.in...
_compute_partial_dependence_recursion
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def fit(self, X, y=None, sample_weight=None): """ Fit estimator. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Use ``dtype=np.float32`` for maximum efficiency. Sparse matrices are also supported,...
Fit estimator. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Use ``dtype=np.float32`` for maximum efficiency. Sparse matrices are also supported, use sparse ``csc_matrix`` for maximum effici...
fit
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def fit_transform(self, X, y=None, sample_weight=None): """ Fit estimator and transform dataset. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Input data used to build forests. Use ``dtype=np.float32`` for maximum ...
Fit estimator and transform dataset. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Input data used to build forests. Use ``dtype=np.float32`` for maximum efficiency. y : Ignored Not used, present for ...
fit_transform
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def get_feature_names_out(self, input_features=None): """Get output feature names for transformation. Parameters ---------- input_features : array-like of str or None, default=None Only used to validate feature names with the names seen in :meth:`fit`. Returns ...
Get output feature names for transformation. Parameters ---------- input_features : array-like of str or None, default=None Only used to validate feature names with the names seen in :meth:`fit`. Returns ------- feature_names_out : ndarray of str objects ...
get_feature_names_out
python
scikit-learn/scikit-learn
sklearn/ensemble/_forest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_forest.py
BSD-3-Clause
def _safe_divide(numerator, denominator): """Prevents overflow and division by zero.""" # This is used for classifiers where the denominator might become zero exactly. # For instance for log loss, HalfBinomialLoss, if proba=0 or proba=1 exactly, then # denominator = hessian = 0, and we should set the no...
Prevents overflow and division by zero.
_safe_divide
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def _init_raw_predictions(X, estimator, loss, use_predict_proba): """Return the initial raw predictions. Parameters ---------- X : ndarray of shape (n_samples, n_features) The data array. estimator : object The estimator to use to compute the predictions. loss : BaseLoss ...
Return the initial raw predictions. Parameters ---------- X : ndarray of shape (n_samples, n_features) The data array. estimator : object The estimator to use to compute the predictions. loss : BaseLoss An instance of a loss function class. use_predict_proba : bool ...
_init_raw_predictions
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def _update_terminal_regions( loss, tree, X, y, neg_gradient, raw_prediction, sample_weight, sample_mask, learning_rate=0.1, k=0, ): """Update the leaf values to be predicted by the tree and raw_prediction. The current raw predictions of the model (of this stage) are upd...
Update the leaf values to be predicted by the tree and raw_prediction. The current raw predictions of the model (of this stage) are updated. Additionally, the terminal regions (=leaves) of the given tree are updated as well. This corresponds to the line search step in "Greedy Function Approximation" by ...
_update_terminal_regions
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def set_huber_delta(loss, y_true, raw_prediction, sample_weight=None): """Calculate and set self.closs.delta based on self.quantile.""" abserr = np.abs(y_true - raw_prediction.squeeze()) # sample_weight is always a ndarray, never None. delta = _weighted_percentile(abserr, sample_weight, 100 * loss.quant...
Calculate and set self.closs.delta based on self.quantile.
set_huber_delta
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def init(self, est, begin_at_stage=0): """Initialize reporter Parameters ---------- est : Estimator The estimator begin_at_stage : int, default=0 stage at which to begin reporting """ # header fields and line format str header_fie...
Initialize reporter Parameters ---------- est : Estimator The estimator begin_at_stage : int, default=0 stage at which to begin reporting
init
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def update(self, j, est): """Update reporter with new iteration. Parameters ---------- j : int The new iteration. est : Estimator The estimator. """ do_oob = est.subsample < 1 # we need to take into account if we fit additional est...
Update reporter with new iteration. Parameters ---------- j : int The new iteration. est : Estimator The estimator.
update
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def _init_state(self): """Initialize model state and allocate model state data structures.""" self.init_ = self.init if self.init_ is None: if is_classifier(self): self.init_ = DummyClassifier(strategy="prior") elif isinstance(self._loss, (AbsoluteError, ...
Initialize model state and allocate model state data structures.
_init_state
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def _clear_state(self): """Clear the state of the gradient boosting model.""" if hasattr(self, "estimators_"): self.estimators_ = np.empty((0, 0), dtype=object) if hasattr(self, "train_score_"): del self.train_score_ if hasattr(self, "oob_improvement_"): ...
Clear the state of the gradient boosting model.
_clear_state
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def _resize_state(self): """Add additional ``n_estimators`` entries to all attributes.""" # self.n_estimators is the number of additional est to fit total_n_estimators = self.n_estimators if total_n_estimators < self.estimators_.shape[0]: raise ValueError( "re...
Add additional ``n_estimators`` entries to all attributes.
_resize_state
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def fit(self, X, y, sample_weight=None, monitor=None): """Fit the gradient boosting model. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, it will be converted to ``dtype=np.float32`` and if a ...
Fit the gradient boosting model. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, it will be converted to ``dtype=np.float32`` and if a sparse matrix is provided to a sparse ``csr_matrix``. ...
fit
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def _fit_stages( self, X, y, raw_predictions, sample_weight, random_state, X_val, y_val, sample_weight_val, begin_at_stage=0, monitor=None, ): """Iteratively fits the stages. For each stage it computes the progr...
Iteratively fits the stages. For each stage it computes the progress (OOB, train score) and delegates to ``_fit_stage``. Returns the number of stages fit; might differ from ``n_estimators`` due to early stopping.
_fit_stages
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def _raw_predict_init(self, X): """Check input and compute raw predictions of the init estimator.""" self._check_initialized() X = self.estimators_[0, 0]._validate_X_predict(X, check_input=True) if self.init_ == "zero": raw_predictions = np.zeros( shape=(X.sha...
Check input and compute raw predictions of the init estimator.
_raw_predict_init
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def _raw_predict(self, X): """Return the sum of the trees raw predictions (+ init estimator).""" check_is_fitted(self) raw_predictions = self._raw_predict_init(X) predict_stages(self.estimators_, X, self.learning_rate, raw_predictions) return raw_predictions
Return the sum of the trees raw predictions (+ init estimator).
_raw_predict
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def _staged_raw_predict(self, X, check_input=True): """Compute raw predictions of ``X`` for each iteration. This method allows monitoring (i.e. determine error on testing set) after each stage. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n...
Compute raw predictions of ``X`` for each iteration. This method allows monitoring (i.e. determine error on testing set) after each stage. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, it will b...
_staged_raw_predict
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def feature_importances_(self): """The impurity-based feature importances. The higher, the more important the feature. The importance of a feature is computed as the (normalized) total reduction of the criterion brought by that feature. It is also known as the Gini importance. ...
The impurity-based feature importances. The higher, the more important the feature. The importance of a feature is computed as the (normalized) total reduction of the criterion brought by that feature. It is also known as the Gini importance. Warning: impurity-based feature im...
feature_importances_
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def _compute_partial_dependence_recursion(self, grid, target_features): """Fast partial dependence computation. Parameters ---------- grid : ndarray of shape (n_samples, n_target_features), dtype=np.float32 The grid points on which the partial dependence should be ...
Fast partial dependence computation. Parameters ---------- grid : ndarray of shape (n_samples, n_target_features), dtype=np.float32 The grid points on which the partial dependence should be evaluated. target_features : ndarray of shape (n_target_features,), dtype...
_compute_partial_dependence_recursion
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def apply(self, X): """Apply trees in the ensemble to X, return leaf indices. .. versionadded:: 0.17 Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, its dtype will be converted to ``dt...
Apply trees in the ensemble to X, return leaf indices. .. versionadded:: 0.17 Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, its dtype will be converted to ``dtype=np.float32``. If a sparse m...
apply
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def decision_function(self, X): """Compute the decision function of ``X``. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, it will be converted to ``dtype=np.float32`` and if a sparse matrix is...
Compute the decision function of ``X``. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, it will be converted to ``dtype=np.float32`` and if a sparse matrix is provided to a sparse ``csr_mat...
decision_function
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def predict(self, X): """Predict class for X. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, it will be converted to ``dtype=np.float32`` and if a sparse matrix is provided to a sp...
Predict class for X. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, it will be converted to ``dtype=np.float32`` and if a sparse matrix is provided to a sparse ``csr_matrix``. Ret...
predict
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def staged_predict(self, X): """Predict class at each stage for X. This method allows monitoring (i.e. determine error on testing set) after each stage. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples....
Predict class at each stage for X. This method allows monitoring (i.e. determine error on testing set) after each stage. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, it will be converted to ...
staged_predict
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def staged_predict_proba(self, X): """Predict class probabilities at each stage for X. This method allows monitoring (i.e. determine error on testing set) after each stage. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) ...
Predict class probabilities at each stage for X. This method allows monitoring (i.e. determine error on testing set) after each stage. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, it will be co...
staged_predict_proba
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def predict(self, X): """Predict regression target for X. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, it will be converted to ``dtype=np.float32`` and if a sparse matrix is provided ...
Predict regression target for X. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, it will be converted to ``dtype=np.float32`` and if a sparse matrix is provided to a sparse ``csr_matrix``. ...
predict
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def apply(self, X): """Apply trees in the ensemble to X, return leaf indices. .. versionadded:: 0.17 Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, its dtype will be converted to ``dt...
Apply trees in the ensemble to X, return leaf indices. .. versionadded:: 0.17 Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, its dtype will be converted to ``dtype=np.float32``. If a sparse m...
apply
python
scikit-learn/scikit-learn
sklearn/ensemble/_gb.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_gb.py
BSD-3-Clause
def _parallel_compute_tree_depths( tree, X, features, tree_decision_path_lengths, tree_avg_path_lengths, depths, lock, ): """Parallel computation of isolation tree depth.""" if features is None: X_subset = X else: X_subset = X[:, features] leaves_index = tree...
Parallel computation of isolation tree depth.
_parallel_compute_tree_depths
python
scikit-learn/scikit-learn
sklearn/ensemble/_iforest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_iforest.py
BSD-3-Clause
def fit(self, X, y=None, sample_weight=None): """ Fit estimator. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Use ``dtype=np.float32`` for maximum efficiency. Sparse matrices are also supported,...
Fit estimator. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Use ``dtype=np.float32`` for maximum efficiency. Sparse matrices are also supported, use sparse ``csc_matrix`` for maximum effici...
fit
python
scikit-learn/scikit-learn
sklearn/ensemble/_iforest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_iforest.py
BSD-3-Clause
def predict(self, X): """ Predict if a particular sample is an outlier or not. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, it will be converted to ``dtype=np.float32`` and if a spar...
Predict if a particular sample is an outlier or not. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) The input samples. Internally, it will be converted to ``dtype=np.float32`` and if a sparse matrix is provided ...
predict
python
scikit-learn/scikit-learn
sklearn/ensemble/_iforest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_iforest.py
BSD-3-Clause
def decision_function(self, X): """ Average anomaly score of X of the base classifiers. The anomaly score of an input sample is computed as the mean anomaly score of the trees in the forest. The measure of normality of an observation given a tree is the depth of the lea...
Average anomaly score of X of the base classifiers. The anomaly score of an input sample is computed as the mean anomaly score of the trees in the forest. The measure of normality of an observation given a tree is the depth of the leaf containing this observation, which is equ...
decision_function
python
scikit-learn/scikit-learn
sklearn/ensemble/_iforest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_iforest.py
BSD-3-Clause
def score_samples(self, X): """ Opposite of the anomaly score defined in the original paper. The anomaly score of an input sample is computed as the mean anomaly score of the trees in the forest. The measure of normality of an observation given a tree is the depth of th...
Opposite of the anomaly score defined in the original paper. The anomaly score of an input sample is computed as the mean anomaly score of the trees in the forest. The measure of normality of an observation given a tree is the depth of the leaf containing this observation, whi...
score_samples
python
scikit-learn/scikit-learn
sklearn/ensemble/_iforest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_iforest.py
BSD-3-Clause
def _score_samples(self, X): """Private version of score_samples without input validation. Input validation would remove feature names, so we disable it. """ # Code structure from ForestClassifier/predict_proba check_is_fitted(self) # Take the opposite of the scores as...
Private version of score_samples without input validation. Input validation would remove feature names, so we disable it.
_score_samples
python
scikit-learn/scikit-learn
sklearn/ensemble/_iforest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_iforest.py
BSD-3-Clause
def _compute_score_samples(self, X, subsample_features): """ Compute the score of each samples in X going through the extra trees. Parameters ---------- X : array-like or sparse matrix Data matrix. subsample_features : bool Whether features shoul...
Compute the score of each samples in X going through the extra trees. Parameters ---------- X : array-like or sparse matrix Data matrix. subsample_features : bool Whether features should be subsampled. Returns ------- scores : n...
_compute_score_samples
python
scikit-learn/scikit-learn
sklearn/ensemble/_iforest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_iforest.py
BSD-3-Clause
def _average_path_length(n_samples_leaf): """ The average path length in a n_samples iTree, which is equal to the average path length of an unsuccessful BST search since the latter has the same structure as an isolation tree. Parameters ---------- n_samples_leaf : array-like of shape (n_samp...
The average path length in a n_samples iTree, which is equal to the average path length of an unsuccessful BST search since the latter has the same structure as an isolation tree. Parameters ---------- n_samples_leaf : array-like of shape (n_samples,) The number of training samples in e...
_average_path_length
python
scikit-learn/scikit-learn
sklearn/ensemble/_iforest.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_iforest.py
BSD-3-Clause
def _concatenate_predictions(self, X, predictions): """Concatenate the predictions of each first layer learner and possibly the input dataset `X`. If `X` is sparse and `self.passthrough` is False, the output of `transform` will be dense (the predictions). If `X` is sparse and `s...
Concatenate the predictions of each first layer learner and possibly the input dataset `X`. If `X` is sparse and `self.passthrough` is False, the output of `transform` will be dense (the predictions). If `X` is sparse and `self.passthrough` is True, the output of `transform` will ...
_concatenate_predictions
python
scikit-learn/scikit-learn
sklearn/ensemble/_stacking.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_stacking.py
BSD-3-Clause
def fit(self, X, y, **fit_params): """Fit the estimators. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Training vectors, where `n_samples` is the number of samples and `n_features` is the number of features. y : ...
Fit the estimators. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Training vectors, where `n_samples` is the number of samples and `n_features` is the number of features. y : array-like of shape (n_samples,) T...
fit
python
scikit-learn/scikit-learn
sklearn/ensemble/_stacking.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_stacking.py
BSD-3-Clause
def _transform(self, X): """Concatenate and return the predictions of the estimators.""" check_is_fitted(self) predictions = [ getattr(est, meth)(X) for est, meth in zip(self.estimators_, self.stack_method_) if est != "drop" ] return self._conc...
Concatenate and return the predictions of the estimators.
_transform
python
scikit-learn/scikit-learn
sklearn/ensemble/_stacking.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_stacking.py
BSD-3-Clause
def get_feature_names_out(self, input_features=None): """Get output feature names for transformation. Parameters ---------- input_features : array-like of str or None, default=None Input features. The input feature names are only used when `passthrough` is `True`...
Get output feature names for transformation. Parameters ---------- input_features : array-like of str or None, default=None Input features. The input feature names are only used when `passthrough` is `True`. - If `input_features` is `None`, then `feature_nam...
get_feature_names_out
python
scikit-learn/scikit-learn
sklearn/ensemble/_stacking.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_stacking.py
BSD-3-Clause
def predict(self, X, **predict_params): """Predict target for X. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Training vectors, where `n_samples` is the number of samples and `n_features` is the number of features. ...
Predict target for X. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features) Training vectors, where `n_samples` is the number of samples and `n_features` is the number of features. **predict_params : dict of str -> obj ...
predict
python
scikit-learn/scikit-learn
sklearn/ensemble/_stacking.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_stacking.py
BSD-3-Clause
def _validate_estimators(self): """Overload the method of `_BaseHeterogeneousEnsemble` to be more lenient towards the type of `estimators`. Regressors can be accepted for some cases such as ordinal regression. """ if len(self.estimators) == 0: raise ValueError( ...
Overload the method of `_BaseHeterogeneousEnsemble` to be more lenient towards the type of `estimators`. Regressors can be accepted for some cases such as ordinal regression.
_validate_estimators
python
scikit-learn/scikit-learn
sklearn/ensemble/_stacking.py
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/ensemble/_stacking.py
BSD-3-Clause