This documentation is for scikit-learn version 0.11-gitOther versions

Citing

If you use the software, please consider citing scikit-learn.

This page

8. Reference

This is the class and function reference of scikit-learn. Please refer to the full user guide for further details, as the class and function raw specifications may not be enough to give full guidelines on their uses.

List of modules

8.1. sklearn.cluster: Clustering

The sklearn.cluster module gathers popular unsupervised clustering algorithms.

User guide: See the Clustering section for further details.

cluster.AffinityPropagation([damping, ...]) Perform Affinity Propagation Clustering of data
cluster.DBSCAN([eps, min_samples, metric, ...]) Perform DBSCAN clustering from vector array or distance matrix.
cluster.KMeans([k, init, n_init, max_iter, ...]) K-Means clustering
cluster.MiniBatchKMeans([k, init, max_iter, ...]) Mini-Batch K-Means clustering
cluster.MeanShift([bandwidth, seeds, ...]) MeanShift clustering
cluster.SpectralClustering([k, mode, ...]) Apply k-means to a projection to the normalized laplacian
cluster.Ward([n_clusters, memory, ...]) Ward hierarchical clustering: constructs a tree and cuts it.
cluster.estimate_bandwidth(X[, quantile, ...]) Estimate the bandwith to use with MeanShift algorithm

8.2. sklearn.covariance: Covariance Estimators

The sklearn.covariance module includes methods and algorithms to robustly estimate the covariance of features given a set of points. The precision matrix defined as the inverse of the covariance is also estimated. Covariance estimation is closely related to the theory of Gaussian Graphical Models.

User guide: See the Covariance estimation section for further details.

covariance.EmpiricalCovariance([...]) Maximum likelihood covariance estimator
covariance.ShrunkCovariance([...]) Covariance estimator with shrinkage
covariance.LedoitWolf([store_precision, ...]) LedoitWolf Estimator
covariance.OAS([store_precision, ...]) Oracle Approximating Shrinkage Estimator
covariance.GraphLasso([alpha, mode, tol, ...]) Sparse inverse covariance estimation with an l1-penalized estimator.
covariance.GraphLassoCV([alphas, ...]) Sparse inverse covariance w/ cross-validated choice of the l1 penality
covariance.MinCovDet([store_precision, ...]) Minimum Covariance Determinant (MCD): robust estimator of covariance
covariance.empirical_covariance(X[, ...]) Computes the Maximum likelihood covariance estimator
covariance.ledoit_wolf(X[, assume_centered]) Estimates the shrunk Ledoit-Wolf covariance matrix.
covariance.shrunk_covariance(emp_cov[, ...]) Calculates a covariance matrix shrunk on the diagonal
covariance.oas(X[, assume_centered]) Estimate covariance with the Oracle Approximating Shrinkage algorithm.
covariance.graph_lasso(emp_cov, alpha[, ...]) l1-penalized covariance estimator

8.3. sklearn.cross_validation: Cross Validation

The sklearn.cross_validation module includes utilities for cross- validation and performance evaluation.

User guide: See the Cross-Validation section for further details.

cross_validation.Bootstrap(n[, ...]) Random sampling with replacement cross-validation iterator
cross_validation.KFold(n, k[, indices]) K-Folds cross validation iterator
cross_validation.LeaveOneLabelOut(labels[, ...]) Leave-One-Label_Out cross-validation iterator
cross_validation.LeaveOneOut(n[, indices]) Leave-One-Out cross validation iterator.
cross_validation.LeavePLabelOut(labels, p[, ...]) Leave-P-Label_Out cross-validation iterator
cross_validation.LeavePOut(n, p[, indices]) Leave-P-Out cross validation iterator
cross_validation.StratifiedKFold(y, k[, indices]) Stratified K-Folds cross validation iterator
cross_validation.ShuffleSplit(n[, ...]) Random permutation cross-validation iterator.
cross_validation.train_test_split(*arrays, ...) Split arrays or matrices into random train and test subsets
cross_validation.cross_val_score(estimator, X) Evaluate a score by cross-validation
cross_validation.permutation_test_score(...) Evaluate the significance of a cross-validated score with permutations
cross_validation.check_cv(cv[, X, y, classifier]) Input checker utility for building a CV in a user friendly way.

8.4. sklearn.datasets: Datasets

The sklearn.datasets module includes utilities to load datasets, including methods to load and fetch popular reference datasets. It also features some artificial data generators.

User guide: See the Dataset loading utilities section for further details.

8.4.1. Loaders

datasets.load_20newsgroups(*args, **kwargs) DEPRECATED: Use fetch_20newsgroups instead with download_if_missing=False
datasets.fetch_20newsgroups([data_home, ...]) Load the filenames of the 20 newsgroups dataset.
datasets.fetch_20newsgroups_vectorized([...]) Load the 20 newsgroups dataset and transform it into tf-idf vectors.
datasets.load_boston() Load and return the boston house-prices dataset (regression).
datasets.load_diabetes() Load and return the diabetes dataset (regression).
datasets.load_digits([n_class]) Load and return the digits dataset (classification).
datasets.load_files(container_path[, ...]) Load text files with categories as subfolder names.
datasets.load_iris() Load and return the iris dataset (classification).
datasets.load_lfw_pairs([download_if_missing]) Alias for fetch_lfw_pairs(download_if_missing=False)
datasets.fetch_lfw_pairs([subset, ...]) Loader for the Labeled Faces in the Wild (LFW) pairs dataset
datasets.load_lfw_people([download_if_missing]) Alias for fetch_lfw_people(download_if_missing=False)
datasets.fetch_lfw_people([data_home, ...]) Loader for the Labeled Faces in the Wild (LFW) people dataset
datasets.load_linnerud() Load and return the linnerud dataset (multivariate regression).
datasets.fetch_olivetti_faces([data_home, ...]) Loader for the Olivetti faces data-set from AT&T.
datasets.load_sample_image(image_name) Load the numpy array of a single sample image
datasets.load_sample_images() Load sample images for image manipulation.
datasets.load_svmlight_file(f[, n_features, ...]) Load datasets in the svmlight / libsvm format into sparse CSR matrix

8.4.2. Samples generator

datasets.make_blobs([n_samples, n_features, ...]) Generate isotropic Gaussian blobs for clustering.
datasets.make_classification([n_samples, ...]) Generate a random n-class classification problem.
datasets.make_circles([n_samples, shuffle, ...]) Make a large circle containing a smaller circle in 2di
datasets.make_friedman1([n_samples, ...]) Generate the “Friedman #1” regression problem
datasets.make_friedman2([n_samples, noise, ...]) Generate the “Friedman #2” regression problem
datasets.make_friedman3([n_samples, noise, ...]) Generate the “Friedman #3” regression problem
datasets.make_low_rank_matrix([n_samples, ...]) Generate a mostly low rank matrix with bell-shaped singular values
datasets.make_moons([n_samples, shuffle, ...]) Make two interleaving half circles
datasets.make_multilabel_classification([...]) Generate a random multilabel classification problem.
datasets.make_regression([n_samples, ...]) Generate a random regression problem.
datasets.make_s_curve([n_samples, noise, ...]) Generate an S curve dataset.
datasets.make_sparse_coded_signal(n_samples, ...) Generate a signal as a sparse combination of dictionary elements.
datasets.make_sparse_spd_matrix([dim, ...]) Generate a sparse symetric definite positive matrix.
datasets.make_sparse_uncorrelated([...]) Generate a random regression problem with sparse uncorrelated design
datasets.make_spd_matrix(n_dim[, random_state]) Generate a random symmetric, positive-definite matrix.
datasets.make_swiss_roll([n_samples, noise, ...]) Generate a swiss roll dataset.

8.5. sklearn.decomposition: Matrix Decomposition

The sklearn.decomposition module includes matrix decomposition algorithms, including among others PCA, NMF or ICA. Most of the algorithms of this module can be regarded as dimensionality reduction techniques.

User guide: See the Decomposing signals in components (matrix factorization problems) section for further details.

decomposition.PCA([n_components, copy, whiten]) Principal component analysis (PCA)
decomposition.ProbabilisticPCA([...]) Additional layer on top of PCA that adds a probabilistic evaluationPrincipal component analysis (PCA)
decomposition.ProjectedGradientNMF([...]) Non-Negative matrix factorization by Projected Gradient (NMF)
decomposition.RandomizedPCA(n_components[, ...]) Principal component analysis (PCA) using randomized SVD
decomposition.KernelPCA([n_components, ...]) Kernel Principal component analysis (KPCA)
decomposition.FastICA([n_components, ...]) FastICA; a fast algorithm for Independent Component Analysis
decomposition.NMF([n_components, init, ...]) Non-Negative matrix factorization by Projected Gradient (NMF)
decomposition.SparsePCA(n_components[, ...]) Sparse Principal Components Analysis (SparsePCA)
decomposition.MiniBatchSparsePCA(n_components) Mini-batch Sparse Principal Components Analysis
decomposition.SparseCoder(dictionary[, ...]) Sparse coding
decomposition.DictionaryLearning(n_atoms[, ...]) Dictionary learning
decomposition.MiniBatchDictionaryLearning(n_atoms) Mini-batch dictionary learning
decomposition.fastica(X[, n_components, ...]) Perform Fast Independent Component Analysis.
decomposition.dict_learning(X, n_atoms, alpha) Solves a dictionary learning matrix factorization problem.
decomposition.dict_learning_online(X, ...[, ...]) Solves a dictionary learning matrix factorization problem online.
decomposition.sparse_encode(X, dictionary[, ...]) Sparse coding

8.6. sklearn.ensemble: Ensemble Methods

The sklearn.ensemble module includes ensemble-based methods for classification and regression.

User guide: See the Ensemble methods section for further details.

ensemble.RandomForestClassifier([...]) A random forest classifier.
ensemble.RandomForestRegressor([...]) A random forest regressor.
ensemble.ExtraTreesClassifier([...]) An extra-trees classifier.
ensemble.ExtraTreesRegressor([n_estimators, ...]) An extra-trees regressor.

8.7. sklearn.feature_extraction: Feature Extraction

The sklearn.feature_extraction module deals with feature extraction from raw data. It currently includes methods to extract features from text and images.

User guide: See the Feature extraction section for further details.

8.7.1. From images

The sklearn.feature_extraction.image submodule gathers utilities to extract features from images.

feature_extraction.image.img_to_graph(img[, ...]) Graph of the pixel-to-pixel gradient connections
feature_extraction.image.grid_to_graph(n_x, n_y) Graph of the pixel-to-pixel connections
feature_extraction.image.extract_patches_2d(...) Reshape a 2D image into a collection of patches
feature_extraction.image.reconstruct_from_patches_2d(...) Reconstruct the image from all of its patches.
feature_extraction.image.PatchExtractor(...) Extracts patches from a collection of images

8.7.2. From text

The sklearn.feature_extraction.text submodule gathers utilities to build feature vectors from text documents.

feature_extraction.text.CountVectorizer([...]) Convert a collection of raw documents to a matrix of token counts
feature_extraction.text.TfidfTransformer([...]) Transform a count matrix to a normalized tf or tf–idf representation
feature_extraction.text.Vectorizer([input, ...]) Convert a collection of raw documents to a matrix of TF-IDF features.

8.8. sklearn.feature_selection: Feature Selection

The sklearn.feature_selection module implements feature selection algorithms. It currently includes univariate filter selection methods and the recursive feature elimination algorithm.

User guide: See the Feature selection section for further details.

feature_selection.SelectPercentile(score_func) Filter: Select the best percentile of the p_values
feature_selection.SelectKBest(score_func[, k]) Filter: Select the k lowest p-values
feature_selection.SelectFpr(score_func[, alpha]) Filter: Select the pvalues below alpha based on a FPR test.
feature_selection.SelectFdr(score_func[, alpha]) Filter: Select the p-values for an estimated false discovery rate
feature_selection.SelectFwe(score_func[, alpha]) Filter: Select the p-values corresponding to Family-wise error rate
feature_selection.RFE(estimator, ...[, step]) Feature ranking with recursive feature elimination.
feature_selection.RFECV(estimator[, step, ...]) Feature ranking with recursive feature elimination and cross-validated selection of the best number of features.
feature_selection.chi2(X, y) Compute χ² (chi-squared) statistic for each class/feature combination.
feature_selection.f_classif(X, y) Compute the Anova F-value for the provided sample
feature_selection.f_regression(X, y[, center]) Univariate linear regression tests

8.9. sklearn.gaussian_process: Gaussian Processes

The sklearn.gaussian_process module implements scalar Gaussian Process based predictions.

User guide: See the Gaussian Processes section for further details.

gaussian_process.GaussianProcess([regr, ...]) The Gaussian Process model class.
gaussian_process.correlation_models.absolute_exponential(...) Absolute exponential autocorrelation model.
gaussian_process.correlation_models.squared_exponential(...) Squared exponential correlation model (Radial Basis Function).
gaussian_process.correlation_models.generalized_exponential(...) Generalized exponential correlation model.
gaussian_process.correlation_models.pure_nugget(...) Spatial independence correlation model (pure nugget).
gaussian_process.correlation_models.cubic(...) Cubic correlation model:
gaussian_process.correlation_models.linear(...) Linear correlation model:
gaussian_process.regression_models.constant(x) Zero order polynomial (constant, p = 1) regression model.
gaussian_process.regression_models.linear(x) First order polynomial (linear, p = n+1) regression model.
gaussian_process.regression_models.quadratic(x) Second order polynomial (quadratic, p = n*(n-1)/2+n+1) regression model.

8.11. sklearn.hmm: Hidden Markov Models

The sklearn.hmm module implements hidden Markov models.

Warning: sklearn.hmm is orphaned, undocumented and has known numerical stability issues. If nobody volunteers to write documentation and make it more stable, this module will be removed in version 0.11.

User guide: See the Hidden Markov Models section for further details.

hmm.GaussianHMM([n_components, ...]) Hidden Markov Model with Gaussian emissions
hmm.MultinomialHMM([n_components, ...]) Hidden Markov Model with multinomial (discrete) emissions
hmm.GMMHMM([n_components, n_mix, startprob, ...]) Hidden Markov Model with Gaussin mixture emissions

8.12. sklearn.kernel_approximation Kernel Approximation

The sklearn.kernel_approximation module implements several approximate kernel feature maps base on Fourier transforms.

User guide: See the Kernel Approximation section for further details.

kernel_approximation.RBFSampler([gamma, ...]) Approximates feature map of an RBF kernel by Monte Carlo approximation
kernel_approximation.AdditiveChi2Sampler([...]) Approximate feature map for additive chi² kernel.
kernel_approximation.SkewedChi2Sampler([...]) Approximates feature map of the “skewed chi-squared” kernel by Monte

8.13. sklearn.semi_supervised Semi-Supervised Learning

The sklearn.semi_supervised module implements semi-supervised learning algorithms. These algorithms utilized small amounts of labeled data and large amounts of unlabeled data for classification tasks. This module includes Label Propagation.

User guide: See the Semi-Supervised section for further details.

semi_supervised.LabelPropagation([kernel, ...]) Label Propagation classifier
semi_supervised.LabelSpreading([kernel, ...]) LabelSpreading model for semi-supervised learning

8.14. sklearn.lda: Linear Discriminant Analysis

The sklearn.lda module implements Linear Discriminant Analysis (LDA).

User guide: See the Linear and Quadratic Discriminant Analysis section for further details.

lda.LDA([n_components, priors]) Linear Discriminant Analysis (LDA)

8.15. sklearn.linear_model: Generalized Linear Models

The sklearn.linear_model module implements genelarized linear models. It includes Ridge regression, Bayesian Regression, Lasso and Elastic Net estimators computed with Least Angle Regression and coordinate descent. It also implements Stochastic Gradient Descent related algorithms.

User guide: See the Generalized Linear Models section for further details.

8.15.1. For dense data

linear_model.LinearRegression([...]) Ordinary least squares Linear Regression.
linear_model.Ridge([alpha, fit_intercept, ...]) Linear least squares with l2 regularization.
linear_model.RidgeClassifier([alpha, ...]) Classifier using Ridge regression.
linear_model.RidgeCV([alphas, ...]) Ridge regression with built-in cross-validation.
linear_model.Lasso([alpha, fit_intercept, ...]) Linear Model trained with L1 prior as regularizer (aka the Lasso)
linear_model.LassoCV([eps, n_alphas, ...]) Lasso linear model with iterative fitting along a regularization path
linear_model.ElasticNet([alpha, rho, ...]) Linear Model trained with L1 and L2 prior as regularizer
linear_model.ElasticNetCV([rho, eps, ...]) Elastic Net model with iterative fitting along a regularization path
linear_model.Lars([fit_intercept, verbose, ...]) Least Angle Regression model a.k.a. LAR
linear_model.LassoLars([alpha, ...]) Lasso model fit with Least Angle Regression a.k.a. Lars
linear_model.LarsCV([fit_intercept, ...]) Cross-validated Least Angle Regression model
linear_model.LassoLarsCV([fit_intercept, ...]) Cross-validated Lasso, using the LARS algorithm
linear_model.LassoLarsIC([criterion, ...]) Lasso model fit with Lars using BIC or AIC for model selection
linear_model.LogisticRegression([penalty, ...]) Logistic Regression (aka logit, MaxEnt) classifier.
linear_model.OrthogonalMatchingPursuit([...]) Orthogonal Mathching Pursuit model (OMP)
linear_model.Perceptron([penalty, alpha, ...]) Perceptron
linear_model.SGDClassifier([loss, penalty, ...]) Linear model fitted by minimizing a regularized empirical loss with SGD.
linear_model.SGDRegressor([loss, penalty, ...]) Linear model fitted by minimizing a regularized empirical loss with SGD
linear_model.BayesianRidge([n_iter, tol, ...]) Bayesian ridge regression
linear_model.ARDRegression([n_iter, tol, ...]) Bayesian ARD regression.
linear_model.RandomizedLasso([alpha, ...]) Randomized Lasso
linear_model.RandomizedLogisticRegression([...]) Randomized Logistic Regression
linear_model.lasso_path(X, y[, eps, ...]) Compute Lasso path with coordinate descent
linear_model.lars_path(X, y[, Xy, Gram, ...]) Compute Least Angle Regression and Lasso path
linear_model.orthogonal_mp(X, y[, ...]) Orthogonal Matching Pursuit (OMP)
linear_model.orthogonal_mp_gram(Gram, Xy[, ...]) Gram Orthogonal Matching Pursuit (OMP)
linear_model.lasso_stability_path(X, y[, ...]) Stabiliy path based on randomized Lasso estimates

8.15.2. For sparse data

The sklearn.linear_model.sparse submodule is the sparse counterpart of the sklearn.linear_model module.

User guide: See the Generalized Linear Models section for further details.

linear_model.sparse.Lasso([alpha, ...]) Linear Model trained with L1 prior as regularizer
linear_model.sparse.ElasticNet([alpha, rho, ...]) Linear Model trained with L1 and L2 prior as regularizer
linear_model.sparse.SGDClassifier(*args, ...)
linear_model.sparse.SGDRegressor(*args, **kwargs)
linear_model.LogisticRegression([penalty, ...]) Logistic Regression (aka logit, MaxEnt) classifier.

8.16. sklearn.manifold: Manifold Learning

The sklearn.manifold module implements data embedding techniques.

User guide: See the Manifold learning section for further details.

manifold.LocallyLinearEmbedding([...]) Locally Linear Embedding
manifold.Isomap([n_neighbors, out_dim, ...]) Isomap Embedding
manifold.locally_linear_embedding(X, ...[, ...]) Perform a Locally Linear Embedding analysis on the data.

8.17. sklearn.metrics: Metrics

The sklearn.metrics module includes score functions, performance metrics and pairwise metrics and distance computations.

8.17.1. Classification metrics

metrics.confusion_matrix(y_true, y_pred[, ...]) Compute confusion matrix to evaluate the accuracy of a classification
metrics.roc_curve(y_true, y_score) compute Receiver operating characteristic (ROC)
metrics.auc(x, y) Compute Area Under the Curve (AUC) using the trapezoidal rule
metrics.precision_score(y_true, y_pred[, ...]) Compute the precision
metrics.recall_score(y_true, y_pred[, ...]) Compute the recall
metrics.fbeta_score(y_true, y_pred, beta[, ...]) Compute fbeta score
metrics.f1_score(y_true, y_pred[, labels, ...]) Compute f1 score
metrics.precision_recall_fscore_support(...) Compute precisions, recalls, f-measures and support for each class
metrics.classification_report(y_true, y_pred) Build a text report showing the main classification metrics
metrics.precision_recall_curve(y_true, ...) Compute precision-recall pairs for different probability thresholds
metrics.zero_one_score(y_true, y_pred) Zero-One classification score
metrics.zero_one(y_true, y_pred) Zero-One classification loss
metrics.hinge_loss(y_true, pred_decision[, ...]) Cumulated hinge loss (non-regularized).

8.17.2. Regression metrics

metrics.r2_score(y_true, y_pred) R^2 (coefficient of determination) regression score function
metrics.mean_squared_error(y_true, y_pred) Mean squared error regression loss

8.17.3. Clustering metrics

See the Clustering section of the user guide for further details.

The sklearn.metrics.cluster submodule contains evaluation metrics for cluster analysis results. There are two forms of evaluation:

  • supervised, which uses a ground truth class values for each sample.
  • unsupervised, which does not and measures the ‘quality’ of the model itself.
metrics.adjusted_rand_score(labels_true, ...) Rand index adjusted for chance
metrics.adjusted_mutual_info_score(...) Adjusted Mutual Information between two clusterings
metrics.homogeneity_completeness_v_measure(...) Compute the homogeneity and completeness and V-measure scores at once
metrics.homogeneity_score(labels_true, ...) Homogeneity metric of a cluster labeling given a ground truth
metrics.completeness_score(labels_true, ...) Completeness metric of a cluster labeling given a ground truth
metrics.v_measure_score(labels_true, labels_pred) V-Measure cluster labeling given a ground truth
metrics.silhouette_score(X, labels[, ...]) Compute the mean Silhouette Coefficient of all samples.

8.17.4. Pairwise metrics

The sklearn.metrics.pairwise submodule implements utilities to evaluate pairwise distances or affinity of sets of samples.

This module contains both distance metrics and kernels. A brief summary is given on the two here.

Distance metrics are a function d(a, b) such that d(a, b) < d(a, c) if objects a and b are considered “more similar” to objects a and c. Two objects exactly alike would have a distance of zero. One of the most popular examples is Euclidean distance. To be a ‘true’ metric, it must obey the following four conditions:

1. d(a, b) >= 0, for all a and b
2. d(a, b) == 0, if and only if a = b, positive definiteness
3. d(a, b) == d(b, a), symmetry
4. d(a, c) <= d(a, b) + d(b, c), the triangle inequality

Kernels are measures of similarity, i.e. s(a, b) > s(a, c) if objects a and b are considered “more similar” to objects a and c. A kernel must also be positive semi-definite.

There are a number of ways to convert between a distance metric and a similarity measure, such as a kernel. Let D be the distance, and S be the kernel:

1. ``S = np.exp(-D * gamma)``, where one heuristic for choosing
   ``gamma`` is ``1 / num_features``
2. ``S = 1. / (D / np.max(D))``
metrics.pairwise.euclidean_distances(X[, Y, ...]) Considering the rows of X (and Y=X) as vectors, compute the
metrics.pairwise.manhattan_distances(X[, Y, ...]) Compute the L1 distances between the vectors in X and Y.
metrics.pairwise.linear_kernel(X[, Y]) Compute the linear kernel between X and Y.
metrics.pairwise.polynomial_kernel(X[, Y, ...]) Compute the polynomial kernel between X and Y:
metrics.pairwise.rbf_kernel(X[, Y, gamma]) Compute the rbf (gaussian) kernel between X and Y:
metrics.pairwise.distance_metrics() Valid metrics for pairwise_distances
metrics.pairwise.pairwise_distances(X[, Y, ...]) Compute the distance matrix from a vector array X and optional Y.
metrics.pairwise.kernel_metrics() Valid metrics for pairwise_kernels
metrics.pairwise.pairwise_kernels(X[, Y, ...]) Compute the kernel between arrays X and optional array Y.

8.18. sklearn.mixture: Gaussian Mixture Models

The sklearn.mixture module implements mixture modeling algorithms.

User guide: See the Gaussian mixture models section for further details.

mixture.GMM([n_components, covariance_type, ...]) Gaussian Mixture Model
mixture.DPGMM([n_components, ...]) Variational Inference for the Infinite Gaussian Mixture Model.
mixture.VBGMM([n_components, ...]) Variational Inference for the Gaussian Mixture Model

8.19. sklearn.multiclass: Multiclass and multilabel classification

8.19.1. Multiclass and multilabel classification strategies

This module implements multiclass learning algorithms:
  • one-vs-the-rest / one-vs-all
  • one-vs-one
  • error correcting output codes

The estimators provided in this module are meta-estimators: they require a base estimator to be provided in their constructor. For example, it is possible to use these estimators to turn a binary classifier or a regressor into a multiclass classifier. It is also possible to use these estimators with multiclass estimators in the hope that their accuracy or runtime performance improves.

User guide: See the Multiclass and multilabel algorithms section for further details.

multiclass.OneVsRestClassifier(estimator) One-vs-the-rest (OvR) multiclass/multilabel strategy
multiclass.OneVsOneClassifier(estimator) One-vs-one multiclass strategy
multiclass.OutputCodeClassifier(estimator[, ...]) (Error-Correcting) Output-Code multiclass strategy
multiclass.fit_ovr(estimator, X, y) Fit a one-vs-the-rest strategy.
multiclass.predict_ovr(estimators, ...) Make predictions using the one-vs-the-rest strategy.
multiclass.fit_ovo(estimator, X, y) Fit a one-vs-one strategy.
multiclass.predict_ovo(estimators, classes, X) Make predictions using the one-vs-one strategy.
multiclass.fit_ecoc(estimator, X, y[, ...]) Fit an error-correcting output-code strategy.
multiclass.predict_ecoc(estimators, classes, ...) Make predictions using the error-correcting output-code strategy.

8.20. sklearn.naive_bayes: Naive Bayes

The sklearn.naive_bayes module implements Naive Bayes algorithms. These are supervised learning methods based on applying Bayes’ theorem with strong (naive) feature independence assumptions.

User guide: See the Naive Bayes section for further details.

naive_bayes.GaussianNB Gaussian Naive Bayes (GaussianNB)
naive_bayes.MultinomialNB([alpha, fit_prior]) Naive Bayes classifier for multinomial models
naive_bayes.BernoulliNB([alpha, binarize, ...]) Naive Bayes classifier for multivariate Bernoulli models.

8.21. sklearn.neighbors: Nearest Neighbors

The sklearn.neighbors module implements the k-nearest neighbors algorithm.

User guide: See the Nearest Neighbors section for further details.

neighbors.NearestNeighbors([n_neighbors, ...]) Unsupervised learner for implementing neighbor searches.
neighbors.KNeighborsClassifier([...]) Classifier implementing the k-nearest neighbors vote.
neighbors.RadiusNeighborsClassifier([...]) Classifier implementing a vote among neighbors within a given radius
neighbors.KNeighborsRegressor([n_neighbors, ...]) Regression based on k-nearest neighbors.
neighbors.RadiusNeighborsRegressor([radius, ...]) Regression based on neighbors within a fixed radius.
neighbors.BallTree Ball Tree for fast nearest-neighbor searches :
neighbors.kneighbors_graph(X, n_neighbors[, ...]) Computes the (weighted) graph of k-Neighbors for points in X
neighbors.radius_neighbors_graph(X, radius) Computes the (weighted) graph of Neighbors for points in X

8.22. sklearn.pls: Partial Least Squares

The sklearn.pls module implements Partial Least Squares (PLS).

User guide: See the Partial Least Squares section for further details.

pls.PLSRegression([n_components, scale, ...]) PLS regression
pls.PLSCanonical([n_components, scale, ...]) PLS canonical. PLSCanonical inherits from PLS with mode=”A” and
pls.CCA([n_components, scale, algorithm, ...]) CCA Canonical Correlation Analysis. CCA inherits from PLS with
pls.PLSSVD([n_components, scale, copy]) Partial Least Square SVD

8.23. sklearn.pipeline: Pipeline

The sklearn.pipeline module implements utilites to build a composite estimator, as a chain of transforms and estimators.

pipeline.Pipeline(steps) Pipeline of transforms with a final estimator

8.24. sklearn.preprocessing: Preprocessing and Normalization

User guide: See the Preprocessing data section for further details.

preprocessing.Scaler([copy, with_mean, with_std]) Standardize features by removing the mean and scaling to unit variance
preprocessing.Normalizer([norm, copy]) Normalize samples individually to unit norm
preprocessing.Binarizer([threshold, copy]) Binarize data (set feature values to 0 or 1) according to a threshold
preprocessing.LabelBinarizer([neg_label, ...]) Binarize labels in a one-vs-all fashion
preprocessing.KernelCenterer Center a kernel matrix
preprocessing.scale(X[, axis, with_mean, ...]) Standardize a dataset along any axis
preprocessing.normalize(X[, norm, axis, copy]) Normalize a dataset along any axis
preprocessing.binarize(X[, threshold, copy]) Boolean thresholding of array-like or scipy.sparse matrix

8.25. sklearn.qda: Quadratic Discriminant Analysis

Quadratic Discriminant Analysis

User guide: See the Linear and Quadratic Discriminant Analysis section for further details.

qda.QDA([priors]) Quadratic Discriminant Analysis (QDA)

8.26. sklearn.svm: Support Vector Machines

The sklearn.svm module includes Support Vector Machine algorithms.

User guide: See the Support Vector Machines section for further details.

8.26.1. Estimators

svm.SVC([C, kernel, degree, gamma, coef0, ...]) C-Support Vector Classification.
svm.LinearSVC([penalty, loss, dual, tol, C, ...]) Linear Support Vector Classification.
svm.NuSVC([nu, kernel, degree, gamma, ...]) Nu-Support Vector Classification.
svm.SVR([kernel, degree, gamma, coef0, tol, ...]) epsilon-Support Vector Regression.
svm.NuSVR([nu, C, kernel, degree, gamma, ...]) Nu Support Vector Regression.
svm.OneClassSVM([kernel, degree, gamma, ...]) Unsupervised Outliers Detection.
svm.l1_min_c(X, y[, loss, fit_intercept, ...]) Return the maximum value for C that yields a model with coefficients

8.26.2. Low-level methods

svm.libsvm.fit Train the model using libsvm (low-level method)
svm.libsvm.decision_function Predict margin (libsvm name for this is predict_values)
svm.libsvm.predict Predict target values of X given a model (low-level method)
svm.libsvm.predict_proba Predict probabilities svm_model stores all parameters needed to predict a given value.
svm.libsvm.cross_validation Binding of the cross-validation routine (low-level routine)

8.27. sklearn.tree: Decision Trees

The sklearn.tree module includes decision tree-based models for classification and regression.

User guide: See the Decision Trees section for further details.

tree.DecisionTreeClassifier([criterion, ...]) A decision tree classifier.
tree.DecisionTreeRegressor([criterion, ...]) A tree regressor.
tree.ExtraTreeClassifier([criterion, ...]) An extremely randomized tree classifier.
tree.ExtraTreeRegressor([criterion, ...]) An extremely randomized tree regressor.
tree.export_graphviz(decision_tree[, ...]) Export a decision tree in DOT format.

8.28. sklearn.utils: Utilities

The sklearn.utils module includes various utilites.

Developer guide: See the Utilities for Developers page for further details.

utils.check_random_state(seed) Turn seed into a np.random.RandomState instance
utils.resample(*arrays, **options) Resample arrays or sparse matrices in a consistent way
utils.shuffle(*arrays, **options) Shuffle arrays or sparse matrices in a consistent way