One-vs-the-rest (OvR) multiclass strategy.
Also known as one-vs-all, this strategy consists in fitting one classifier per class. For each classifier, the class is fitted against all the other classes. In addition to its computational efficiency (only n_classes classifiers are needed), one advantage of this approach is its interpretability. Since each class is represented by one and one classifier only, it is possible to gain knowledge about the class by inspecting its corresponding classifier. This is the most commonly used strategy for multiclass classification and is a fair default choice.
OneVsRestClassifier can also be used for multilabel classification. To use this feature, provide an indicator matrix for the target y when calling .fit. In other words, the target labels should be formatted as a 2D binary (0/1) matrix, where [i, j] == 1 indicates the presence of label j in sample i. This estimator uses the binary relevance method to perform multilabel classification, which involves training one binary classifier independently for each label.
Read more in the User Guide.
An estimator object implementing fit and one of decision_function or predict_proba.
The number of jobs to use for the computation: the n_classes one-vs-rest problems are computed in parallel.
None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Changed in version v0.20: n_jobs default changed from 1 to None
Estimators used for predictions.
Coefficient of the features in the decision function. This attribute exists only if the estimators_ defines coef_.
Deprecated since version 0.24: This attribute is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). If you use this attribute in RFE or SelectFromModel, you may pass a callable to the importance_getter parameter that extracts feature the importances from estimators_.
If y is binary, the shape is (1, 1) else (n_classes, 1) This attribute exists only if the estimators_ defines intercept_.
Deprecated since version 0.24: This attribute is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). If you use this attribute in RFE or SelectFromModel, you may pass a callable to the importance_getter parameter that extracts feature the importances from estimators_.
Class labels.
Number of classes.
Object used to transform multiclass labels to binary labels and vice-versa.
Whether this is a multilabel classifier
See also
Alternate way of extending an estimator for multilabel classification.
Transform iterable of iterables to binary indicator matrix.
decision_function(X)
Returns the distance of each sample from the decision boundary for each class.
fit(X, y)
Fit underlying estimators.
get_params([deep])
Get parameters for this estimator.
partial_fit(X, y[, classes])
Partially fit underlying estimators
predict(X)
Predict multi-class targets using underlying estimators.
predict_proba(X)
Probability estimates.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Returns the distance of each sample from the decision boundary for each class. This can only be used with estimators which implement the decision_function method.
Changed in version 0.19: output shape changed to (n_samples,) to conform to scikit-learn conventions for binary classification.
Fit underlying estimators.
Data.
Multi-class targets. An indicator matrix turns on multilabel classification.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Whether this is a multilabel classifier
Partially fit underlying estimators
Should be used when memory is inefficient to train all data. Chunks of data can be passed in several iteration.
Data.
Multi-class targets. An indicator matrix turns on multilabel classification.
Classes across all calls to partial_fit. Can be obtained via np.unique(y_all), where y_all is the target vector of the entire dataset. This argument is only required in the first call of partial_fit and can be omitted in the subsequent calls.
Predict multi-class targets using underlying estimators.
Data.
Predicted multi-class targets.
Probability estimates.
The returned estimates for all classes are ordered by label of classes.
Note that in the multilabel case, each sample can have any number of labels. This returns the marginal probability that the given sample has the label in question. For example, it is entirely consistent that two labels both have a 90% probability of applying to a given sample.
In the single label multiclass case, the rows of the returned matrix sum to 1.
Returns the probability of the sample for each class in the model, where classes are ordered as they are in self.classes_.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


One-vs-the-rest (OvR) multiclass strategy.
Also known as one-vs-all, this strategy consists in fitting one classifier per class. For each classifier, the class is fitted against all the other classes. In addition to its computational efficiency (only n_classes classifiers are needed), one advantage of this approach is its interpretability. Since each class is represented by one and one classifier only, it is possible to gain knowledge about the class by inspecting its corresponding classifier. This is the most commonly used strategy for multiclass classification and is a fair default choice.
OneVsRestClassifier can also be used for multilabel classification. To use this feature, provide an indicator matrix for the target y when calling .fit. In other words, the target labels should be formatted as a 2D binary (0/1) matrix, where [i, j] == 1 indicates the presence of label j in sample i. This estimator uses the binary relevance method to perform multilabel classification, which involves training one binary classifier independently for each label.
Read more in the User Guide.
An estimator object implementing fit and one of decision_function or predict_proba.
The number of jobs to use for the computation: the n_classes one-vs-rest problems are computed in parallel.
None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Changed in version v0.20: n_jobs default changed from 1 to None
Estimators used for predictions.
Coefficient of the features in the decision function. This attribute exists only if the estimators_ defines coef_.
Deprecated since version 0.24: This attribute is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). If you use this attribute in RFE or SelectFromModel, you may pass a callable to the importance_getter parameter that extracts feature the importances from estimators_.
If y is binary, the shape is (1, 1) else (n_classes, 1) This attribute exists only if the estimators_ defines intercept_.
Deprecated since version 0.24: This attribute is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). If you use this attribute in RFE or SelectFromModel, you may pass a callable to the importance_getter parameter that extracts feature the importances from estimators_.
Class labels.
Number of classes.
Object used to transform multiclass labels to binary labels and vice-versa.
Whether this is a multilabel classifier
See also
Alternate way of extending an estimator for multilabel classification.
Transform iterable of iterables to binary indicator matrix.
decision_function(X)
Returns the distance of each sample from the decision boundary for each class.
fit(X, y)
Fit underlying estimators.
get_params([deep])
Get parameters for this estimator.
partial_fit(X, y[, classes])
Partially fit underlying estimators
predict(X)
Predict multi-class targets using underlying estimators.
predict_proba(X)
Probability estimates.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Returns the distance of each sample from the decision boundary for each class. This can only be used with estimators which implement the decision_function method.
Changed in version 0.19: output shape changed to (n_samples,) to conform to scikit-learn conventions for binary classification.
Fit underlying estimators.
Data.
Multi-class targets. An indicator matrix turns on multilabel classification.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Whether this is a multilabel classifier
Partially fit underlying estimators
Should be used when memory is inefficient to train all data. Chunks of data can be passed in several iteration.
Data.
Multi-class targets. An indicator matrix turns on multilabel classification.
Classes across all calls to partial_fit. Can be obtained via np.unique(y_all), where y_all is the target vector of the entire dataset. This argument is only required in the first call of partial_fit and can be omitted in the subsequent calls.
Predict multi-class targets using underlying estimators.
Data.
Predicted multi-class targets.
Probability estimates.
The returned estimates for all classes are ordered by label of classes.
Note that in the multilabel case, each sample can have any number of labels. This returns the marginal probability that the given sample has the label in question. For example, it is entirely consistent that two labels both have a 90% probability of applying to a given sample.
In the single label multiclass case, the rows of the returned matrix sum to 1.
Returns the probability of the sample for each class in the model, where classes are ordered as they are in self.classes_.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Multilabel classification
Receiver Operating Characteristic (ROC)
Precision-Recall
Classifier Chain


Returns the distance of each sample from the decision boundary for each class. This can only be used with estimators which implement the decision_function method.
Changed in version 0.19: output shape changed to (n_samples,) to conform to scikit-learn conventions for binary classification.


Fit underlying estimators.
Data.
Multi-class targets. An indicator matrix turns on multilabel classification.


Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.


Partially fit underlying estimators
Should be used when memory is inefficient to train all data. Chunks of data can be passed in several iteration.
Data.
Multi-class targets. An indicator matrix turns on multilabel classification.
Classes across all calls to partial_fit. Can be obtained via np.unique(y_all), where y_all is the target vector of the entire dataset. This argument is only required in the first call of partial_fit and can be omitted in the subsequent calls.


Predict multi-class targets using underlying estimators.
Data.
Predicted multi-class targets.


Probability estimates.
The returned estimates for all classes are ordered by label of classes.
Note that in the multilabel case, each sample can have any number of labels. This returns the marginal probability that the given sample has the label in question. For example, it is entirely consistent that two labels both have a 90% probability of applying to a given sample.
In the single label multiclass case, the rows of the returned matrix sum to 1.
Returns the probability of the sample for each class in the model, where classes are ordered as they are in self.classes_.


Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.


Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


(Error-Correcting) Output-Code multiclass strategy
Output-code based strategies consist in representing each class with a binary code (an array of 0s and 1s). At fitting time, one binary classifier per bit in the code book is fitted. At prediction time, the classifiers are used to project new points in the class space and the class closest to the points is chosen. The main advantage of these strategies is that the number of classifiers used can be controlled by the user, either for compressing the model (0 < code_size < 1) or for making the model more robust to errors (code_size > 1). See the documentation for more details.
Read more in the User Guide.
An estimator object implementing fit and one of decision_function or predict_proba.
Percentage of the number of classes to be used to create the code book. A number between 0 and 1 will require fewer classifiers than one-vs-the-rest. A number greater than 1 will require more classifiers than one-vs-the-rest.
The generator used to initialize the codebook. Pass an int for reproducible output across multiple function calls. See Glossary.
The number of jobs to use for the computation: the multiclass problems are computed in parallel.
None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Estimators used for predictions.
Array containing labels.
Binary array containing the code of each class.
“Solving multiclass learning problems via error-correcting output codes”, Dietterich T., Bakiri G., Journal of Artificial Intelligence Research 2, 1995.
“The error coding method and PICTs”, James G., Hastie T., Journal of Computational and Graphical statistics 7, 1998.
“The Elements of Statistical Learning”, Hastie T., Tibshirani R., Friedman J., page 606 (second-edition) 2008.
fit(X, y)
Fit underlying estimators.
get_params([deep])
Get parameters for this estimator.
predict(X)
Predict multi-class targets using underlying estimators.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Fit underlying estimators.
Data.
Multi-class targets.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Predict multi-class targets using underlying estimators.
Data.
Predicted multi-class targets.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Fit underlying estimators.
Data.
Multi-class targets.


A multi-label model that arranges binary classifiers into a chain.
Each model makes a prediction in the order specified by the chain using all of the available features provided to the model plus the predictions of models that are earlier in the chain.
Read more in the User Guide.
New in version 0.19.
The base estimator from which the classifier chain is built.
If None, the order will be determined by the order of columns in the label matrix Y.:
The order of the chain can be explicitly set by providing a list of integers. For example, for a chain of length 5.:
means that the first model in the chain will make predictions for column 1 in the Y matrix, the second model will make predictions for column 3, etc.
If order is ‘random’ a random ordering will be used.
Determines whether to use cross validated predictions or true labels for the results of previous estimators in the chain. Possible inputs for cv are:
If order='random', determines random number generation for the chain order. In addition, it controls the random seed given at each base_estimator at each chaining iteration. Thus, it is only used when base_estimator exposes a random_state. Pass an int for reproducible output across multiple function calls. See Glossary.
A list of arrays of length len(estimators_) containing the class labels for each estimator in the chain.
A list of clones of base_estimator.
The order of labels in the classifier chain.
See also
Equivalent for regression.
Classifies each output independently rather than chaining.
Jesse Read, Bernhard Pfahringer, Geoff Holmes, Eibe Frank, “Classifier Chains for Multi-label Classification”, 2009.
decision_function(X)
Evaluate the decision_function of the models in the chain.
fit(X, Y)
Fit the model to data matrix X and targets Y.
get_params([deep])
Get parameters for this estimator.
predict(X)
Predict on the data matrix X using the ClassifierChain model.
predict_proba(X)
Predict probability estimates.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Evaluate the decision_function of the models in the chain.
Returns the decision function of the sample for each model in the chain.
Fit the model to data matrix X and targets Y.
The input data.
The target values.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Predict on the data matrix X using the ClassifierChain model.
The input data.
The predicted values.
Predict probability estimates.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


A multi-label model that arranges binary classifiers into a chain.
Each model makes a prediction in the order specified by the chain using all of the available features provided to the model plus the predictions of models that are earlier in the chain.
Read more in the User Guide.
New in version 0.19.
The base estimator from which the classifier chain is built.
If None, the order will be determined by the order of columns in the label matrix Y.:
The order of the chain can be explicitly set by providing a list of integers. For example, for a chain of length 5.:
means that the first model in the chain will make predictions for column 1 in the Y matrix, the second model will make predictions for column 3, etc.
If order is ‘random’ a random ordering will be used.
Determines whether to use cross validated predictions or true labels for the results of previous estimators in the chain. Possible inputs for cv are:
If order='random', determines random number generation for the chain order. In addition, it controls the random seed given at each base_estimator at each chaining iteration. Thus, it is only used when base_estimator exposes a random_state. Pass an int for reproducible output across multiple function calls. See Glossary.
A list of arrays of length len(estimators_) containing the class labels for each estimator in the chain.
A list of clones of base_estimator.
The order of labels in the classifier chain.
See also
Equivalent for regression.
Classifies each output independently rather than chaining.
Jesse Read, Bernhard Pfahringer, Geoff Holmes, Eibe Frank, “Classifier Chains for Multi-label Classification”, 2009.
decision_function(X)
Evaluate the decision_function of the models in the chain.
fit(X, Y)
Fit the model to data matrix X and targets Y.
get_params([deep])
Get parameters for this estimator.
predict(X)
Predict on the data matrix X using the ClassifierChain model.
predict_proba(X)
Predict probability estimates.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Evaluate the decision_function of the models in the chain.
Returns the decision function of the sample for each model in the chain.
Fit the model to data matrix X and targets Y.
The input data.
The target values.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Predict on the data matrix X using the ClassifierChain model.
The input data.
The predicted values.
Predict probability estimates.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Classifier Chain


Evaluate the decision_function of the models in the chain.
Returns the decision function of the sample for each model in the chain.


Fit the model to data matrix X and targets Y.
The input data.
The target values.


Predict on the data matrix X using the ClassifierChain model.
The input data.
The predicted values.


Multi target classification
This strategy consists of fitting one classifier per target. This is a simple strategy for extending classifiers that do not natively support multi-target classification
An estimator object implementing fit, score and predict_proba.
The number of jobs to run in parallel. fit, predict and partial_fit (if supported by the passed estimator) will be parallelized for each target.
When individual estimators are fast to train or predict, using n_jobs > 1 can result in slower performance due to the parallelism overhead.
None means 1 unless in a joblib.parallel_backend context. -1 means using all available processes / threads. See Glossary for more details.
Changed in version 0.20: n_jobs default changed from 1 to None
Class labels.
Estimators used for predictions.
fit(X, Y[, sample_weight])
Fit the model to data matrix X and targets Y.
get_params([deep])
Get parameters for this estimator.
partial_fit(X, y[, classes, sample_weight])
Incrementally fit the model to data.
predict(X)
Predict multi-output variable using a model
score(X, y)
Returns the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Fit the model to data matrix X and targets Y.
The input data.
The target values.
Sample weights. If None, then samples are equally weighted. Only supported if the underlying classifier supports sample weights.
Parameters passed to the estimator.fit method of each step.
New in version 0.23.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Incrementally fit the model to data. Fit a separate model for each output variable.
Data.
Multi-output targets.
Each array is unique classes for one output in str/int Can be obtained by via [np.unique(y[:, i]) for i in range(y.shape[1])], where y is the target matrix of the entire dataset. This argument is required for the first call to partial_fit and can be omitted in the subsequent calls. Note that y doesn’t need to contain all labels in classes.
Sample weights. If None, then samples are equally weighted. Only supported if the underlying regressor supports sample weights.
trained for each target variable.
Data.
Multi-output targets predicted across multiple predictors. Note: Separate models are generated for each predictor.
Probability estimates. Returns prediction probabilities for each class of each output.
This method will raise a ValueError if any of the estimators do not have predict_proba.
Data
The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.
Changed in version 0.19: This function now returns a list of arrays where the length of the list is n_outputs, and each array is (n_samples, n_classes) for that particular output.
Returns the mean accuracy on the given test data and labels.
Test samples
True values for X
accuracy_score of self.predict(X) versus y
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Fit the model to data matrix X and targets Y.
The input data.
The target values.
Sample weights. If None, then samples are equally weighted. Only supported if the underlying classifier supports sample weights.
Parameters passed to the estimator.fit method of each step.
New in version 0.23.


Incrementally fit the model to data. Fit a separate model for each output variable.
Data.
Multi-output targets.
Each array is unique classes for one output in str/int Can be obtained by via [np.unique(y[:, i]) for i in range(y.shape[1])], where y is the target matrix of the entire dataset. This argument is required for the first call to partial_fit and can be omitted in the subsequent calls. Note that y doesn’t need to contain all labels in classes.
Sample weights. If None, then samples are equally weighted. Only supported if the underlying regressor supports sample weights.


trained for each target variable.
Data.
Multi-output targets predicted across multiple predictors. Note: Separate models are generated for each predictor.


Probability estimates. Returns prediction probabilities for each class of each output.
This method will raise a ValueError if any of the estimators do not have predict_proba.
Data
The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.
Changed in version 0.19: This function now returns a list of arrays where the length of the list is n_outputs, and each array is (n_samples, n_classes) for that particular output.


Returns the mean accuracy on the given test data and labels.
Test samples
True values for X
accuracy_score of self.predict(X) versus y


Multi target regression
This strategy consists of fitting one regressor per target. This is a simple strategy for extending regressors that do not natively support multi-target regression.
New in version 0.18.
An estimator object implementing fit and predict.
The number of jobs to run in parallel. fit, predict and partial_fit (if supported by the passed estimator) will be parallelized for each target.
When individual estimators are fast to train or predict, using n_jobs > 1 can result in slower performance due to the parallelism overhead.
None means 1 unless in a joblib.parallel_backend context. -1 means using all available processes / threads. See Glossary for more details.
Changed in version 0.20: n_jobs default changed from 1 to None
Estimators used for predictions.
fit(X, y[, sample_weight])
Fit the model to data.
get_params([deep])
Get parameters for this estimator.
partial_fit(X, y[, sample_weight])
Incrementally fit the model to data.
predict(X)
Predict multi-output variable using a model
score(X, y[, sample_weight])
Return the coefficient of determination \(R^2\) of the prediction.
set_params(**params)
Set the parameters of this estimator.
Fit the model to data. Fit a separate model for each output variable.
Data.
Multi-output targets. An indicator matrix turns on multilabel estimation.
Sample weights. If None, then samples are equally weighted. Only supported if the underlying regressor supports sample weights.
Parameters passed to the estimator.fit method of each step.
New in version 0.23.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Incrementally fit the model to data. Fit a separate model for each output variable.
Data.
Multi-output targets.
Sample weights. If None, then samples are equally weighted. Only supported if the underlying regressor supports sample weights.
trained for each target variable.
Data.
Multi-output targets predicted across multiple predictors. Note: Separate models are generated for each predictor.
Return the coefficient of determination \(R^2\) of the prediction.
The coefficient \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)
** 2).sum() and \(v\) is the total sum of squares ((y_true -
y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.
Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.
True values for X.
Sample weights.
\(R^2\) of self.predict(X) wrt. y.
The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score. This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Multi target regression
This strategy consists of fitting one regressor per target. This is a simple strategy for extending regressors that do not natively support multi-target regression.
New in version 0.18.
An estimator object implementing fit and predict.
The number of jobs to run in parallel. fit, predict and partial_fit (if supported by the passed estimator) will be parallelized for each target.
When individual estimators are fast to train or predict, using n_jobs > 1 can result in slower performance due to the parallelism overhead.
None means 1 unless in a joblib.parallel_backend context. -1 means using all available processes / threads. See Glossary for more details.
Changed in version 0.20: n_jobs default changed from 1 to None
Estimators used for predictions.
fit(X, y[, sample_weight])
Fit the model to data.
get_params([deep])
Get parameters for this estimator.
partial_fit(X, y[, sample_weight])
Incrementally fit the model to data.
predict(X)
Predict multi-output variable using a model
score(X, y[, sample_weight])
Return the coefficient of determination \(R^2\) of the prediction.
set_params(**params)
Set the parameters of this estimator.
Fit the model to data. Fit a separate model for each output variable.
Data.
Multi-output targets. An indicator matrix turns on multilabel estimation.
Sample weights. If None, then samples are equally weighted. Only supported if the underlying regressor supports sample weights.
Parameters passed to the estimator.fit method of each step.
New in version 0.23.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Incrementally fit the model to data. Fit a separate model for each output variable.
Data.
Multi-output targets.
Sample weights. If None, then samples are equally weighted. Only supported if the underlying regressor supports sample weights.
trained for each target variable.
Data.
Multi-output targets predicted across multiple predictors. Note: Separate models are generated for each predictor.
Return the coefficient of determination \(R^2\) of the prediction.
The coefficient \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)
** 2).sum() and \(v\) is the total sum of squares ((y_true -
y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.
Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.
True values for X.
Sample weights.
\(R^2\) of self.predict(X) wrt. y.
The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score. This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Comparing random forests and the multi-output meta estimator


Fit the model to data. Fit a separate model for each output variable.
Data.
Multi-output targets. An indicator matrix turns on multilabel estimation.
Sample weights. If None, then samples are equally weighted. Only supported if the underlying regressor supports sample weights.
Parameters passed to the estimator.fit method of each step.
New in version 0.23.


Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.


Incrementally fit the model to data. Fit a separate model for each output variable.
Data.
Multi-output targets.
Sample weights. If None, then samples are equally weighted. Only supported if the underlying regressor supports sample weights.


Return the coefficient of determination \(R^2\) of the prediction.
The coefficient \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)
** 2).sum() and \(v\) is the total sum of squares ((y_true -
y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.
Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.
True values for X.
Sample weights.
\(R^2\) of self.predict(X) wrt. y.
The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score. This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).


Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


A multi-label model that arranges regressions into a chain.
Each model makes a prediction in the order specified by the chain using all of the available features provided to the model plus the predictions of models that are earlier in the chain.
Read more in the User Guide.
New in version 0.20.
The base estimator from which the classifier chain is built.
If None, the order will be determined by the order of columns in the label matrix Y.:
The order of the chain can be explicitly set by providing a list of integers. For example, for a chain of length 5.:
means that the first model in the chain will make predictions for column 1 in the Y matrix, the second model will make predictions for column 3, etc.
If order is ‘random’ a random ordering will be used.
Determines whether to use cross validated predictions or true labels for the results of previous estimators in the chain. Possible inputs for cv are:
If order='random', determines random number generation for the chain order. In addition, it controls the random seed given at each base_estimator at each chaining iteration. Thus, it is only used when base_estimator exposes a random_state. Pass an int for reproducible output across multiple function calls. See Glossary.
A list of clones of base_estimator.
The order of labels in the classifier chain.
See also
Equivalent for classification.
Learns each output independently rather than chaining.
fit(X, Y, **fit_params)
Fit the model to data matrix X and targets Y.
get_params([deep])
Get parameters for this estimator.
predict(X)
Predict on the data matrix X using the ClassifierChain model.
score(X, y[, sample_weight])
Return the coefficient of determination \(R^2\) of the prediction.
set_params(**params)
Set the parameters of this estimator.
Fit the model to data matrix X and targets Y.
The input data.
The target values.
Parameters passed to the fit method at each step of the regressor chain.
New in version 0.23.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Predict on the data matrix X using the ClassifierChain model.
The input data.
The predicted values.
Return the coefficient of determination \(R^2\) of the prediction.
The coefficient \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)
** 2).sum() and \(v\) is the total sum of squares ((y_true -
y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.
Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.
True values for X.
Sample weights.
\(R^2\) of self.predict(X) wrt. y.
The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score. This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Fit the model to data matrix X and targets Y.
The input data.
The target values.
Parameters passed to the fit method at each step of the regressor chain.
New in version 0.23.


Naive Bayes classifier for multivariate Bernoulli models.
Like MultinomialNB, this classifier is suitable for discrete data. The difference is that while MultinomialNB works with occurrence counts, BernoulliNB is designed for binary/boolean features.
Read more in the User Guide.
Additive (Laplace/Lidstone) smoothing parameter (0 for no smoothing).
Threshold for binarizing (mapping to booleans) of sample features. If None, input is presumed to already consist of binary vectors.
Whether to learn class prior probabilities or not. If false, a uniform prior will be used.
Prior probabilities of the classes. If specified the priors are not adjusted according to the data.
Number of samples encountered for each class during fitting. This value is weighted by the sample weight when provided.
Log probability of each class (smoothed).
Class labels known to the classifier
Mirrors feature_log_prob_ for interpreting BernoulliNB as a linear model.
Number of samples encountered for each (class, feature) during fitting. This value is weighted by the sample weight when provided.
Empirical log probability of features given a class, P(x_i|y).
Mirrors class_log_prior_ for interpreting BernoulliNB as a linear model.
Number of features of each sample.
C.D. Manning, P. Raghavan and H. Schuetze (2008). Introduction to Information Retrieval. Cambridge University Press, pp. 234-265. https://nlp.stanford.edu/IR-book/html/htmledition/the-bernoulli-model-1.html
A. McCallum and K. Nigam (1998). A comparison of event models for naive Bayes text classification. Proc. AAAI/ICML-98 Workshop on Learning for Text Categorization, pp. 41-48.
V. Metsis, I. Androutsopoulos and G. Paliouras (2006). Spam filtering with naive Bayes – Which naive Bayes? 3rd Conf. on Email and Anti-Spam (CEAS).
fit(X, y[, sample_weight])
Fit Naive Bayes classifier according to X, y
get_params([deep])
Get parameters for this estimator.
partial_fit(X, y[, classes, sample_weight])
Incremental fit on a batch of samples.
predict(X)
Perform classification on an array of test vectors X.
predict_log_proba(X)
Return log-probability estimates for the test vector X.
predict_proba(X)
Return probability estimates for the test vector X.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Fit Naive Bayes classifier according to X, y
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
Weights applied to individual samples (1. for unweighted).
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Incremental fit on a batch of samples.
This method is expected to be called several times consecutively on different chunks of a dataset so as to implement out-of-core or online learning.
This is especially useful when the whole dataset is too big to fit in memory at once.
This method has some performance overhead hence it is better to call partial_fit on chunks of data that are as large as possible (as long as fitting in the memory budget) to hide the overhead.
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
List of all the classes that can possibly appear in the y vector.
Must be provided at the first call to partial_fit, can be omitted in subsequent calls.
Weights applied to individual samples (1. for unweighted).
Perform classification on an array of test vectors X.
Predicted target values for X
Return log-probability estimates for the test vector X.
Returns the log-probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return probability estimates for the test vector X.
Returns the probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Naive Bayes classifier for multivariate Bernoulli models.
Like MultinomialNB, this classifier is suitable for discrete data. The difference is that while MultinomialNB works with occurrence counts, BernoulliNB is designed for binary/boolean features.
Read more in the User Guide.
Additive (Laplace/Lidstone) smoothing parameter (0 for no smoothing).
Threshold for binarizing (mapping to booleans) of sample features. If None, input is presumed to already consist of binary vectors.
Whether to learn class prior probabilities or not. If false, a uniform prior will be used.
Prior probabilities of the classes. If specified the priors are not adjusted according to the data.
Number of samples encountered for each class during fitting. This value is weighted by the sample weight when provided.
Log probability of each class (smoothed).
Class labels known to the classifier
Mirrors feature_log_prob_ for interpreting BernoulliNB as a linear model.
Number of samples encountered for each (class, feature) during fitting. This value is weighted by the sample weight when provided.
Empirical log probability of features given a class, P(x_i|y).
Mirrors class_log_prior_ for interpreting BernoulliNB as a linear model.
Number of features of each sample.
C.D. Manning, P. Raghavan and H. Schuetze (2008). Introduction to Information Retrieval. Cambridge University Press, pp. 234-265. https://nlp.stanford.edu/IR-book/html/htmledition/the-bernoulli-model-1.html
A. McCallum and K. Nigam (1998). A comparison of event models for naive Bayes text classification. Proc. AAAI/ICML-98 Workshop on Learning for Text Categorization, pp. 41-48.
V. Metsis, I. Androutsopoulos and G. Paliouras (2006). Spam filtering with naive Bayes – Which naive Bayes? 3rd Conf. on Email and Anti-Spam (CEAS).
fit(X, y[, sample_weight])
Fit Naive Bayes classifier according to X, y
get_params([deep])
Get parameters for this estimator.
partial_fit(X, y[, classes, sample_weight])
Incremental fit on a batch of samples.
predict(X)
Perform classification on an array of test vectors X.
predict_log_proba(X)
Return log-probability estimates for the test vector X.
predict_proba(X)
Return probability estimates for the test vector X.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Fit Naive Bayes classifier according to X, y
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
Weights applied to individual samples (1. for unweighted).
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Incremental fit on a batch of samples.
This method is expected to be called several times consecutively on different chunks of a dataset so as to implement out-of-core or online learning.
This is especially useful when the whole dataset is too big to fit in memory at once.
This method has some performance overhead hence it is better to call partial_fit on chunks of data that are as large as possible (as long as fitting in the memory budget) to hide the overhead.
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
List of all the classes that can possibly appear in the y vector.
Must be provided at the first call to partial_fit, can be omitted in subsequent calls.
Weights applied to individual samples (1. for unweighted).
Perform classification on an array of test vectors X.
Predicted target values for X
Return log-probability estimates for the test vector X.
Returns the log-probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return probability estimates for the test vector X.
Returns the probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Hashing feature transformation using Totally Random Trees
Classification of text documents using sparse features


Fit Naive Bayes classifier according to X, y
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
Weights applied to individual samples (1. for unweighted).


Incremental fit on a batch of samples.
This method is expected to be called several times consecutively on different chunks of a dataset so as to implement out-of-core or online learning.
This is especially useful when the whole dataset is too big to fit in memory at once.
This method has some performance overhead hence it is better to call partial_fit on chunks of data that are as large as possible (as long as fitting in the memory budget) to hide the overhead.
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
List of all the classes that can possibly appear in the y vector.
Must be provided at the first call to partial_fit, can be omitted in subsequent calls.
Weights applied to individual samples (1. for unweighted).


Perform classification on an array of test vectors X.
Predicted target values for X


Return log-probability estimates for the test vector X.
Returns the log-probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.


Return probability estimates for the test vector X.
Returns the probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.


Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.


Naive Bayes classifier for categorical features
The categorical Naive Bayes classifier is suitable for classification with discrete features that are categorically distributed. The categories of each feature are drawn from a categorical distribution.
Read more in the User Guide.
Additive (Laplace/Lidstone) smoothing parameter (0 for no smoothing).
Whether to learn class prior probabilities or not. If false, a uniform prior will be used.
Prior probabilities of the classes. If specified the priors are not adjusted according to the data.
Minimum number of categories per feature.
New in version 0.24.
Holds arrays of shape (n_classes, n_categories of respective feature) for each feature. Each array provides the number of samples encountered for each class and category of the specific feature.
Number of samples encountered for each class during fitting. This value is weighted by the sample weight when provided.
Smoothed empirical log probability for each class.
Class labels known to the classifier
Holds arrays of shape (n_classes, n_categories of respective feature) for each feature. Each array provides the empirical log probability of categories given the respective feature and class, P(x_i|y).
Number of features of each sample.
Number of categories for each feature. This value is inferred from the data or set by the minimum number of categories.
New in version 0.24.
fit(X, y[, sample_weight])
Fit Naive Bayes classifier according to X, y
get_params([deep])
Get parameters for this estimator.
partial_fit(X, y[, classes, sample_weight])
Incremental fit on a batch of samples.
predict(X)
Perform classification on an array of test vectors X.
predict_log_proba(X)
Return log-probability estimates for the test vector X.
predict_proba(X)
Return probability estimates for the test vector X.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Fit Naive Bayes classifier according to X, y
Training vectors, where n_samples is the number of samples and n_features is the number of features. Here, each feature of X is assumed to be from a different categorical distribution. It is further assumed that all categories of each feature are represented by the numbers 0, …, n - 1, where n refers to the total number of categories for the given feature. This can, for instance, be achieved with the help of OrdinalEncoder.
Target values.
Weights applied to individual samples (1. for unweighted).
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Incremental fit on a batch of samples.
This method is expected to be called several times consecutively on different chunks of a dataset so as to implement out-of-core or online learning.
This is especially useful when the whole dataset is too big to fit in memory at once.
This method has some performance overhead hence it is better to call partial_fit on chunks of data that are as large as possible (as long as fitting in the memory budget) to hide the overhead.
Training vectors, where n_samples is the number of samples and n_features is the number of features. Here, each feature of X is assumed to be from a different categorical distribution. It is further assumed that all categories of each feature are represented by the numbers 0, …, n - 1, where n refers to the total number of categories for the given feature. This can, for instance, be achieved with the help of OrdinalEncoder.
Target values.
List of all the classes that can possibly appear in the y vector.
Must be provided at the first call to partial_fit, can be omitted in subsequent calls.
Weights applied to individual samples (1. for unweighted).
Perform classification on an array of test vectors X.
Predicted target values for X
Return log-probability estimates for the test vector X.
Returns the log-probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return probability estimates for the test vector X.
Returns the probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Fit Naive Bayes classifier according to X, y
Training vectors, where n_samples is the number of samples and n_features is the number of features. Here, each feature of X is assumed to be from a different categorical distribution. It is further assumed that all categories of each feature are represented by the numbers 0, …, n - 1, where n refers to the total number of categories for the given feature. This can, for instance, be achieved with the help of OrdinalEncoder.
Target values.
Weights applied to individual samples (1. for unweighted).


Incremental fit on a batch of samples.
This method is expected to be called several times consecutively on different chunks of a dataset so as to implement out-of-core or online learning.
This is especially useful when the whole dataset is too big to fit in memory at once.
This method has some performance overhead hence it is better to call partial_fit on chunks of data that are as large as possible (as long as fitting in the memory budget) to hide the overhead.
Training vectors, where n_samples is the number of samples and n_features is the number of features. Here, each feature of X is assumed to be from a different categorical distribution. It is further assumed that all categories of each feature are represented by the numbers 0, …, n - 1, where n refers to the total number of categories for the given feature. This can, for instance, be achieved with the help of OrdinalEncoder.
Target values.
List of all the classes that can possibly appear in the y vector.
Must be provided at the first call to partial_fit, can be omitted in subsequent calls.
Weights applied to individual samples (1. for unweighted).


The Complement Naive Bayes classifier described in Rennie et al. (2003).
The Complement Naive Bayes classifier was designed to correct the “severe assumptions” made by the standard Multinomial Naive Bayes classifier. It is particularly suited for imbalanced data sets.
Read more in the User Guide.
New in version 0.20.
Additive (Laplace/Lidstone) smoothing parameter (0 for no smoothing).
Only used in edge case with a single class in the training set.
Prior probabilities of the classes. Not used.
Whether or not a second normalization of the weights is performed. The default behavior mirrors the implementations found in Mahout and Weka, which do not follow the full algorithm described in Table 9 of the paper.
Number of samples encountered for each class during fitting. This value is weighted by the sample weight when provided.
Smoothed empirical log probability for each class. Only used in edge case with a single class in the training set.
Class labels known to the classifier
Mirrors feature_log_prob_ for interpreting ComplementNB as a linear model.
Deprecated since version 0.24: coef_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26).
Number of samples encountered for each feature during fitting. This value is weighted by the sample weight when provided.
Number of samples encountered for each (class, feature) during fitting. This value is weighted by the sample weight when provided.
Empirical weights for class complements.
Mirrors class_log_prior_ for interpreting ComplementNB as a linear model.
Deprecated since version 0.24: coef_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26).
Number of features of each sample.
Rennie, J. D., Shih, L., Teevan, J., & Karger, D. R. (2003). Tackling the poor assumptions of naive bayes text classifiers. In ICML (Vol. 3, pp. 616-623). https://people.csail.mit.edu/jrennie/papers/icml03-nb.pdf
fit(X, y[, sample_weight])
Fit Naive Bayes classifier according to X, y
get_params([deep])
Get parameters for this estimator.
partial_fit(X, y[, classes, sample_weight])
Incremental fit on a batch of samples.
predict(X)
Perform classification on an array of test vectors X.
predict_log_proba(X)
Return log-probability estimates for the test vector X.
predict_proba(X)
Return probability estimates for the test vector X.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Fit Naive Bayes classifier according to X, y
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
Weights applied to individual samples (1. for unweighted).
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Incremental fit on a batch of samples.
This method is expected to be called several times consecutively on different chunks of a dataset so as to implement out-of-core or online learning.
This is especially useful when the whole dataset is too big to fit in memory at once.
This method has some performance overhead hence it is better to call partial_fit on chunks of data that are as large as possible (as long as fitting in the memory budget) to hide the overhead.
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
List of all the classes that can possibly appear in the y vector.
Must be provided at the first call to partial_fit, can be omitted in subsequent calls.
Weights applied to individual samples (1. for unweighted).
Perform classification on an array of test vectors X.
Predicted target values for X
Return log-probability estimates for the test vector X.
Returns the log-probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return probability estimates for the test vector X.
Returns the probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


The Complement Naive Bayes classifier described in Rennie et al. (2003).
The Complement Naive Bayes classifier was designed to correct the “severe assumptions” made by the standard Multinomial Naive Bayes classifier. It is particularly suited for imbalanced data sets.
Read more in the User Guide.
New in version 0.20.
Additive (Laplace/Lidstone) smoothing parameter (0 for no smoothing).
Only used in edge case with a single class in the training set.
Prior probabilities of the classes. Not used.
Whether or not a second normalization of the weights is performed. The default behavior mirrors the implementations found in Mahout and Weka, which do not follow the full algorithm described in Table 9 of the paper.
Number of samples encountered for each class during fitting. This value is weighted by the sample weight when provided.
Smoothed empirical log probability for each class. Only used in edge case with a single class in the training set.
Class labels known to the classifier
Mirrors feature_log_prob_ for interpreting ComplementNB as a linear model.
Deprecated since version 0.24: coef_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26).
Number of samples encountered for each feature during fitting. This value is weighted by the sample weight when provided.
Number of samples encountered for each (class, feature) during fitting. This value is weighted by the sample weight when provided.
Empirical weights for class complements.
Mirrors class_log_prior_ for interpreting ComplementNB as a linear model.
Deprecated since version 0.24: coef_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26).
Number of features of each sample.
Rennie, J. D., Shih, L., Teevan, J., & Karger, D. R. (2003). Tackling the poor assumptions of naive bayes text classifiers. In ICML (Vol. 3, pp. 616-623). https://people.csail.mit.edu/jrennie/papers/icml03-nb.pdf
fit(X, y[, sample_weight])
Fit Naive Bayes classifier according to X, y
get_params([deep])
Get parameters for this estimator.
partial_fit(X, y[, classes, sample_weight])
Incremental fit on a batch of samples.
predict(X)
Perform classification on an array of test vectors X.
predict_log_proba(X)
Return log-probability estimates for the test vector X.
predict_proba(X)
Return probability estimates for the test vector X.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Fit Naive Bayes classifier according to X, y
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
Weights applied to individual samples (1. for unweighted).
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Incremental fit on a batch of samples.
This method is expected to be called several times consecutively on different chunks of a dataset so as to implement out-of-core or online learning.
This is especially useful when the whole dataset is too big to fit in memory at once.
This method has some performance overhead hence it is better to call partial_fit on chunks of data that are as large as possible (as long as fitting in the memory budget) to hide the overhead.
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
List of all the classes that can possibly appear in the y vector.
Must be provided at the first call to partial_fit, can be omitted in subsequent calls.
Weights applied to individual samples (1. for unweighted).
Perform classification on an array of test vectors X.
Predicted target values for X
Return log-probability estimates for the test vector X.
Returns the log-probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return probability estimates for the test vector X.
Returns the probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Classification of text documents using sparse features


Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.


Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Gaussian Naive Bayes (GaussianNB)
Can perform online updates to model parameters via partial_fit. For details on algorithm used to update feature means and variance online, see Stanford CS tech report STAN-CS-79-773 by Chan, Golub, and LeVeque:
http://i.stanford.edu/pub/cstr/reports/cs/tr/79/773/CS-TR-79-773.pdf
Read more in the User Guide.
Prior probabilities of the classes. If specified the priors are not adjusted according to the data.
Portion of the largest variance of all features that is added to variances for calculation stability.
New in version 0.20.
number of training samples observed in each class.
probability of each class.
class labels known to the classifier
absolute additive value to variances
variance of each feature per class
mean of each feature per class
fit(X, y[, sample_weight])
Fit Gaussian Naive Bayes according to X, y
get_params([deep])
Get parameters for this estimator.
partial_fit(X, y[, classes, sample_weight])
Incremental fit on a batch of samples.
predict(X)
Perform classification on an array of test vectors X.
predict_log_proba(X)
Return log-probability estimates for the test vector X.
predict_proba(X)
Return probability estimates for the test vector X.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Fit Gaussian Naive Bayes according to X, y
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
Weights applied to individual samples (1. for unweighted).
New in version 0.17: Gaussian Naive Bayes supports fitting with sample_weight.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Incremental fit on a batch of samples.
This method is expected to be called several times consecutively on different chunks of a dataset so as to implement out-of-core or online learning.
This is especially useful when the whole dataset is too big to fit in memory at once.
This method has some performance and numerical stability overhead, hence it is better to call partial_fit on chunks of data that are as large as possible (as long as fitting in the memory budget) to hide the overhead.
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
List of all the classes that can possibly appear in the y vector.
Must be provided at the first call to partial_fit, can be omitted in subsequent calls.
Weights applied to individual samples (1. for unweighted).
New in version 0.17.
Perform classification on an array of test vectors X.
Predicted target values for X
Return log-probability estimates for the test vector X.
Returns the log-probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return probability estimates for the test vector X.
Returns the probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Gaussian Naive Bayes (GaussianNB)
Can perform online updates to model parameters via partial_fit. For details on algorithm used to update feature means and variance online, see Stanford CS tech report STAN-CS-79-773 by Chan, Golub, and LeVeque:
http://i.stanford.edu/pub/cstr/reports/cs/tr/79/773/CS-TR-79-773.pdf
Read more in the User Guide.
Prior probabilities of the classes. If specified the priors are not adjusted according to the data.
Portion of the largest variance of all features that is added to variances for calculation stability.
New in version 0.20.
number of training samples observed in each class.
probability of each class.
class labels known to the classifier
absolute additive value to variances
variance of each feature per class
mean of each feature per class
fit(X, y[, sample_weight])
Fit Gaussian Naive Bayes according to X, y
get_params([deep])
Get parameters for this estimator.
partial_fit(X, y[, classes, sample_weight])
Incremental fit on a batch of samples.
predict(X)
Perform classification on an array of test vectors X.
predict_log_proba(X)
Return log-probability estimates for the test vector X.
predict_proba(X)
Return probability estimates for the test vector X.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Fit Gaussian Naive Bayes according to X, y
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
Weights applied to individual samples (1. for unweighted).
New in version 0.17: Gaussian Naive Bayes supports fitting with sample_weight.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Incremental fit on a batch of samples.
This method is expected to be called several times consecutively on different chunks of a dataset so as to implement out-of-core or online learning.
This is especially useful when the whole dataset is too big to fit in memory at once.
This method has some performance and numerical stability overhead, hence it is better to call partial_fit on chunks of data that are as large as possible (as long as fitting in the memory budget) to hide the overhead.
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
List of all the classes that can possibly appear in the y vector.
Must be provided at the first call to partial_fit, can be omitted in subsequent calls.
Weights applied to individual samples (1. for unweighted).
New in version 0.17.
Perform classification on an array of test vectors X.
Predicted target values for X
Return log-probability estimates for the test vector X.
Returns the log-probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return probability estimates for the test vector X.
Returns the probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Comparison of Calibration of Classifiers
Probability Calibration curves
Probability calibration of classifiers
Classifier comparison
Plot class probabilities calculated by the VotingClassifier
Plotting Learning Curves
Importance of Feature Scaling


Fit Gaussian Naive Bayes according to X, y
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
Weights applied to individual samples (1. for unweighted).
New in version 0.17: Gaussian Naive Bayes supports fitting with sample_weight.


Incremental fit on a batch of samples.
This method is expected to be called several times consecutively on different chunks of a dataset so as to implement out-of-core or online learning.
This is especially useful when the whole dataset is too big to fit in memory at once.
This method has some performance and numerical stability overhead, hence it is better to call partial_fit on chunks of data that are as large as possible (as long as fitting in the memory budget) to hide the overhead.
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
List of all the classes that can possibly appear in the y vector.
Must be provided at the first call to partial_fit, can be omitted in subsequent calls.
Weights applied to individual samples (1. for unweighted).
New in version 0.17.


Naive Bayes classifier for multinomial models
The multinomial Naive Bayes classifier is suitable for classification with discrete features (e.g., word counts for text classification). The multinomial distribution normally requires integer feature counts. However, in practice, fractional counts such as tf-idf may also work.
Read more in the User Guide.
Additive (Laplace/Lidstone) smoothing parameter (0 for no smoothing).
Whether to learn class prior probabilities or not. If false, a uniform prior will be used.
Prior probabilities of the classes. If specified the priors are not adjusted according to the data.
Number of samples encountered for each class during fitting. This value is weighted by the sample weight when provided.
Smoothed empirical log probability for each class.
Class labels known to the classifier
Mirrors feature_log_prob_ for interpreting MultinomialNB as a linear model.
Deprecated since version 0.24: coef_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26).
Number of samples encountered for each (class, feature) during fitting. This value is weighted by the sample weight when provided.
Empirical log probability of features given a class, P(x_i|y).
Mirrors class_log_prior_ for interpreting MultinomialNB as a linear model.
Deprecated since version 0.24: intercept_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26).
Number of features of each sample.
For the rationale behind the names coef_ and intercept_, i.e. naive Bayes as a linear classifier, see J. Rennie et al. (2003), Tackling the poor assumptions of naive Bayes text classifiers, ICML.
C.D. Manning, P. Raghavan and H. Schuetze (2008). Introduction to Information Retrieval. Cambridge University Press, pp. 234-265. https://nlp.stanford.edu/IR-book/html/htmledition/naive-bayes-text-classification-1.html
fit(X, y[, sample_weight])
Fit Naive Bayes classifier according to X, y
get_params([deep])
Get parameters for this estimator.
partial_fit(X, y[, classes, sample_weight])
Incremental fit on a batch of samples.
predict(X)
Perform classification on an array of test vectors X.
predict_log_proba(X)
Return log-probability estimates for the test vector X.
predict_proba(X)
Return probability estimates for the test vector X.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Fit Naive Bayes classifier according to X, y
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
Weights applied to individual samples (1. for unweighted).
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Incremental fit on a batch of samples.
This method is expected to be called several times consecutively on different chunks of a dataset so as to implement out-of-core or online learning.
This is especially useful when the whole dataset is too big to fit in memory at once.
This method has some performance overhead hence it is better to call partial_fit on chunks of data that are as large as possible (as long as fitting in the memory budget) to hide the overhead.
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
List of all the classes that can possibly appear in the y vector.
Must be provided at the first call to partial_fit, can be omitted in subsequent calls.
Weights applied to individual samples (1. for unweighted).
Perform classification on an array of test vectors X.
Predicted target values for X
Return log-probability estimates for the test vector X.
Returns the log-probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return probability estimates for the test vector X.
Returns the probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Naive Bayes classifier for multinomial models
The multinomial Naive Bayes classifier is suitable for classification with discrete features (e.g., word counts for text classification). The multinomial distribution normally requires integer feature counts. However, in practice, fractional counts such as tf-idf may also work.
Read more in the User Guide.
Additive (Laplace/Lidstone) smoothing parameter (0 for no smoothing).
Whether to learn class prior probabilities or not. If false, a uniform prior will be used.
Prior probabilities of the classes. If specified the priors are not adjusted according to the data.
Number of samples encountered for each class during fitting. This value is weighted by the sample weight when provided.
Smoothed empirical log probability for each class.
Class labels known to the classifier
Mirrors feature_log_prob_ for interpreting MultinomialNB as a linear model.
Deprecated since version 0.24: coef_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26).
Number of samples encountered for each (class, feature) during fitting. This value is weighted by the sample weight when provided.
Empirical log probability of features given a class, P(x_i|y).
Mirrors class_log_prior_ for interpreting MultinomialNB as a linear model.
Deprecated since version 0.24: intercept_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26).
Number of features of each sample.
For the rationale behind the names coef_ and intercept_, i.e. naive Bayes as a linear classifier, see J. Rennie et al. (2003), Tackling the poor assumptions of naive Bayes text classifiers, ICML.
C.D. Manning, P. Raghavan and H. Schuetze (2008). Introduction to Information Retrieval. Cambridge University Press, pp. 234-265. https://nlp.stanford.edu/IR-book/html/htmledition/naive-bayes-text-classification-1.html
fit(X, y[, sample_weight])
Fit Naive Bayes classifier according to X, y
get_params([deep])
Get parameters for this estimator.
partial_fit(X, y[, classes, sample_weight])
Incremental fit on a batch of samples.
predict(X)
Perform classification on an array of test vectors X.
predict_log_proba(X)
Return log-probability estimates for the test vector X.
predict_proba(X)
Return probability estimates for the test vector X.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Fit Naive Bayes classifier according to X, y
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
Weights applied to individual samples (1. for unweighted).
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Incremental fit on a batch of samples.
This method is expected to be called several times consecutively on different chunks of a dataset so as to implement out-of-core or online learning.
This is especially useful when the whole dataset is too big to fit in memory at once.
This method has some performance overhead hence it is better to call partial_fit on chunks of data that are as large as possible (as long as fitting in the memory budget) to hide the overhead.
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
List of all the classes that can possibly appear in the y vector.
Must be provided at the first call to partial_fit, can be omitted in subsequent calls.
Weights applied to individual samples (1. for unweighted).
Perform classification on an array of test vectors X.
Predicted target values for X
Return log-probability estimates for the test vector X.
Returns the log-probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return probability estimates for the test vector X.
Returns the probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Out-of-core classification of text documents
Classification of text documents using sparse features


Fit Naive Bayes classifier according to X, y
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
Weights applied to individual samples (1. for unweighted).


Incremental fit on a batch of samples.
This method is expected to be called several times consecutively on different chunks of a dataset so as to implement out-of-core or online learning.
This is especially useful when the whole dataset is too big to fit in memory at once.
This method has some performance overhead hence it is better to call partial_fit on chunks of data that are as large as possible (as long as fitting in the memory budget) to hide the overhead.
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values.
List of all the classes that can possibly appear in the y vector.
Must be provided at the first call to partial_fit, can be omitted in subsequent calls.
Weights applied to individual samples (1. for unweighted).


Perform classification on an array of test vectors X.
Predicted target values for X


Return log-probability estimates for the test vector X.
Returns the log-probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.


Return probability estimates for the test vector X.
Returns the probability of the samples for each class in the model. The columns correspond to the classes in sorted order, as they appear in the attribute classes_.


Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.


BallTree for fast generalized N-point problems
Read more in the User Guide.
n_samples is the number of points in the data set, and n_features is the dimension of the parameter space. Note: if X is a C-contiguous array of doubles then data will not be copied. Otherwise, an internal copy will be made.
Number of points at which to switch to brute-force. Changing leaf_size will not affect the results of a query, but can significantly impact the speed of a query and the memory required to store the constructed tree. The amount of memory needed to store the tree scales as approximately n_samples / leaf_size. For a specified leaf_size, a leaf node is guaranteed to satisfy leaf_size <= n_points <= 2 * leaf_size, except in the case that n_samples < leaf_size.
the distance metric to use for the tree. Default=’minkowski’ with p=2 (that is, a euclidean metric). See the documentation of the DistanceMetric class for a list of available metrics. ball_tree.valid_metrics gives a list of the metrics which are valid for BallTree.
The training data
Query for k-nearest neighbors
Pickle and Unpickle a tree. Note that the state of the tree is saved in the pickle operation: the tree needs not be rebuilt upon unpickling.
Query for neighbors within a given radius
Compute a gaussian kernel density estimate:
Compute a two-point auto-correlation function
get_arrays(self)
Get data and node arrays.
get_n_calls(self)
Get number of calls.
get_tree_stats(self)
Get tree status.
kernel_density(self, X, h[, kernel, atol, …])
Compute the kernel density estimate at points X with the given kernel, using the distance metric specified at tree creation.
query(X[, k, return_distance, dualtree, …])
query the tree for the k nearest neighbors
query_radius(X, r[, return_distance, …])
query the tree for neighbors within a radius r
reset_n_calls(self)
Reset number of calls to 0.
two_point_correlation(X, r[, dualtree])
Compute the two-point correlation function
Get data and node arrays.
Arrays for storing tree data, index, node data and node bounds.
Get number of calls.
number of distance computation calls
Get tree status.
(number of trims, number of leaves, number of splits)
Compute the kernel density estimate at points X with the given kernel, using the distance metric specified at tree creation.
An array of points to query. Last dimension should match dimension of training data.
the bandwidth of the kernel
specify the kernel to use. Options are - ‘gaussian’ - ‘tophat’ - ‘epanechnikov’ - ‘exponential’ - ‘linear’ - ‘cosine’ Default is kernel = ‘gaussian’
Specify the desired relative and absolute tolerance of the result. If the true result is K_true, then the returned result K_ret satisfies abs(K_true - K_ret) < atol + rtol * K_ret The default is zero (i.e. machine precision) for both.
If True, use a breadth-first search. If False (default) use a depth-first search. Breadth-first is generally faster for compact kernels and/or high tolerances.
Return the logarithm of the result. This can be more accurate than returning the result itself for narrow kernels.
The array of (log)-density evaluations
query the tree for the k nearest neighbors
An array of points to query
The number of nearest neighbors to return
if True, return a tuple (d, i) of distances and indices if False, return array i
if True, use the dual tree formalism for the query: a tree is built for the query points, and the pair of trees is used to efficiently search this space. This can lead to better performance as the number of points grows large.
if True, then query the nodes in a breadth-first manner. Otherwise, query the nodes in a depth-first manner.
if True, then distances and indices of each point are sorted on return, so that the first column contains the closest points. Otherwise, neighbors are returned in an arbitrary order.
Each entry gives the list of distances to the neighbors of the corresponding point.
Each entry gives the list of indices of neighbors of the corresponding point.
query the tree for neighbors within a radius r
An array of points to query
r can be a single value, or an array of values of shape x.shape[:-1] if different radii are desired for each point.
if True, return distances to neighbors of each point if False, return only neighbors Note that unlike the query() method, setting return_distance=True here adds to the computation time. Not all distances need to be calculated explicitly for return_distance=False. Results are not sorted by default: see sort_results keyword.
if True, return only the count of points within distance r if False, return the indices of all points within distance r If return_distance==True, setting count_only=True will result in an error.
if True, the distances and indices will be sorted before being returned. If False, the results will not be sorted. If return_distance == False, setting sort_results = True will result in an error.
Each entry gives the number of neighbors within a distance r of the corresponding point.
Each element is a numpy integer array listing the indices of neighbors of the corresponding point. Note that unlike the results of a k-neighbors query, the returned neighbors are not sorted by distance by default.
Each element is a numpy double array listing the distances corresponding to indices in i.
Reset number of calls to 0.
Compute the two-point correlation function
An array of points to query. Last dimension should match dimension of training data.
A one-dimensional array of distances
If True, use a dualtree algorithm. Otherwise, use a single-tree algorithm. Dual tree algorithms can have better scaling for large N.
counts[i] contains the number of pairs of points with distance less than or equal to r[i]


Get data and node arrays.
Arrays for storing tree data, index, node data and node bounds.


Get number of calls.
number of distance computation calls


Get tree status.
(number of trims, number of leaves, number of splits)


Compute the kernel density estimate at points X with the given kernel, using the distance metric specified at tree creation.
An array of points to query. Last dimension should match dimension of training data.
the bandwidth of the kernel
specify the kernel to use. Options are - ‘gaussian’ - ‘tophat’ - ‘epanechnikov’ - ‘exponential’ - ‘linear’ - ‘cosine’ Default is kernel = ‘gaussian’
Specify the desired relative and absolute tolerance of the result. If the true result is K_true, then the returned result K_ret satisfies abs(K_true - K_ret) < atol + rtol * K_ret The default is zero (i.e. machine precision) for both.
If True, use a breadth-first search. If False (default) use a depth-first search. Breadth-first is generally faster for compact kernels and/or high tolerances.
Return the logarithm of the result. This can be more accurate than returning the result itself for narrow kernels.
The array of (log)-density evaluations


query the tree for the k nearest neighbors
An array of points to query
The number of nearest neighbors to return
if True, return a tuple (d, i) of distances and indices if False, return array i
if True, use the dual tree formalism for the query: a tree is built for the query points, and the pair of trees is used to efficiently search this space. This can lead to better performance as the number of points grows large.
if True, then query the nodes in a breadth-first manner. Otherwise, query the nodes in a depth-first manner.
if True, then distances and indices of each point are sorted on return, so that the first column contains the closest points. Otherwise, neighbors are returned in an arbitrary order.
Each entry gives the list of distances to the neighbors of the corresponding point.
Each entry gives the list of indices of neighbors of the corresponding point.


query the tree for neighbors within a radius r
An array of points to query
r can be a single value, or an array of values of shape x.shape[:-1] if different radii are desired for each point.
if True, return distances to neighbors of each point if False, return only neighbors Note that unlike the query() method, setting return_distance=True here adds to the computation time. Not all distances need to be calculated explicitly for return_distance=False. Results are not sorted by default: see sort_results keyword.
if True, return only the count of points within distance r if False, return the indices of all points within distance r If return_distance==True, setting count_only=True will result in an error.
if True, the distances and indices will be sorted before being returned. If False, the results will not be sorted. If return_distance == False, setting sort_results = True will result in an error.
Each entry gives the number of neighbors within a distance r of the corresponding point.
Each element is a numpy integer array listing the indices of neighbors of the corresponding point. Note that unlike the results of a k-neighbors query, the returned neighbors are not sorted by distance by default.
Each element is a numpy double array listing the distances corresponding to indices in i.


Compute the two-point correlation function
An array of points to query. Last dimension should match dimension of training data.
A one-dimensional array of distances
If True, use a dualtree algorithm. Otherwise, use a single-tree algorithm. Dual tree algorithms can have better scaling for large N.
counts[i] contains the number of pairs of points with distance less than or equal to r[i]