API reference
Scikit-Learn API reference
scikit-learn machine learning
- Identifiers
- 134
- With full guides
- 130
- Types
- 3
Topics covered
- Estimator API
- Train/test split
- Preprocessing
- Pipelines
- Classification
- Regression
- Clustering
- Model selection
Class
| Name | What it does |
|---|---|
LinearRegression | LinearRegression fits an ordinary least-squares model by minimizing residual squared error. Use it to predict continuous targets from one or more features, with optional intercept fitting and non-negative coefficient constraints. |
LogisticRegression | LogisticRegression is a regularized classifier for binary and multiclass problems. It supports dense or sparse features and several solvers with different penalty and multiclass capabilities. |
RandomForestClassifier | A classifier that combines many decision trees trained on dataset subsamples. Averaging their outputs improves predictive accuracy and helps control overfitting. |
KMeans | KMeans partitions data into a chosen number of clusters by iteratively assigning samples to centroids and updating those centroids. It supports k-means++ or custom initialization and Lloyd or Elkan optimization. |
StandardScaler | StandardScaler removes each feature's training mean and scales by its training standard deviation. It is useful for putting numeric features on comparable scales before modeling. |
Pipeline | Pipeline chains transformers in order and optionally finishes with a predictor. It lets the complete sequence be fitted, cross-validated, and parameter-tuned as one estimator. |
GridSearchCV | GridSearchCV exhaustively evaluates estimator hyperparameter combinations from a parameter grid using cross-validation. After fitting, it retains the best configuration and can delegate supported estimator methods. |
DecisionTreeClassifier | A supervised decision-tree classifier that learns feature-based rules for binary or multiclass prediction. Its split criterion, growth limits, weighting, randomness, and pruning behavior are configurable. |
SVC | SVC is a libsvm-based C-support vector classifier for binary and multiclass problems. It supports several kernels, with RBF as the default, and handles multiclass classification through one-vs-one models. |
PCA | PCA performs linear dimensionality reduction by centering data and using singular value decomposition to project it into a lower-dimensional space. It supports exact, randomized, covariance-based, and truncated SVD strategies. |
Ridge | Ridge is a linear regression estimator that minimizes squared error with an L2 penalty on coefficients. Its alpha parameter controls regularization strength, and it supports single- and multi-target regression. |
Lasso | Lasso is a linear regression estimator with an L1 penalty. It encourages sparse coefficients by allowing some feature weights to become exactly zero. |
ElasticNet | ElasticNet is linear regression with combined L1 and L2 regularization. Use alpha to control overall penalty strength and l1_ratio to control the L1/L2 balance. |
SGDClassifier | SGDClassifier trains regularized linear classifiers with stochastic gradient descent. It supports configurable losses, sparse or dense floating-point features, and incremental learning through partial_fit. |
SGDRegressor | SGDRegressor fits a regularized linear regression model using stochastic gradient descent. It supports several loss functions and L1, L2, or elastic-net penalties. |
Perceptron | Perceptron is a linear classifier backed by SGDClassifier. It uses perceptron loss with a constant learning rate and supports optional regularization, early stopping, and incremental fitting. |
DecisionTreeRegressor | DecisionTreeRegressor predicts continuous targets by recursively partitioning feature space with decision rules. Its criterion, split strategy, depth, leaf-size, and pruning parameters control how the tree is built and how complex it becomes. |
RandomForestRegressor | RandomForestRegressor is an ensemble of decision-tree regressors that averages predictions from trees trained on dataset subsamples. It improves predictive accuracy and helps control over-fitting. |
GradientBoostingClassifier | GradientBoostingClassifier builds a classification model by adding regression trees stage by stage to optimize a differentiable loss. It supports binary and multiclass classification, with log loss as the default objective. |
GradientBoostingRegressor | GradientBoostingRegressor fits an additive regression model by sequentially training trees against the negative gradient of a chosen loss. Tune learning_rate and n_estimators together to balance each tree’s contribution against the number of stages. |
HistGradientBoostingClassifier | Histogram-based gradient boosting classifier for fast tree ensembles on large datasets. It natively handles NaNs and offers controls for regularization, early stopping, categorical features, and constraints. |
AdaBoostClassifier | AdaBoostClassifier is a classification meta-estimator that sequentially fits classifiers while emphasizing difficult training examples. It combines the fitted classifiers, with n_estimators and learning_rate controlling the ensemble. |
ExtraTreesClassifier | ExtraTreesClassifier is an ensemble classifier that fits randomized decision trees on dataset sub-samples and averages them. It supports classification with randomized splits and can natively handle missing values for random splits. |
BaggingClassifier | An ensemble classifier that trains base classifiers on randomized subsets of samples and features, then aggregates their predictions. It is commonly used to reduce variance in high-variance estimators. |
VotingClassifier | VotingClassifier combines named classifiers by majority labels or aggregated probabilities. It supports hard and soft voting, optional classifier weights, and parallel fitting. |
StackingClassifier | StackingClassifier combines predictions from named base classifiers with a final classifier. It trains the final classifier on cross-validated base predictions to improve generalization. |
SVR | SVR is scikit-learn’s epsilon-support vector regression estimator. It supports linear and nonlinear kernels, with C controlling regularization and epsilon defining the no-penalty prediction tube. |
LinearSVC | LinearSVC is a linear support-vector classifier implemented with liblinear. It supports dense and sparse inputs, flexible penalties and losses, and one-vs-the-rest multiclass classification. |
KNeighborsClassifier | KNeighborsClassifier implements supervised classification by voting among a sample’s nearest neighbors. It supports uniform or distance-based voting and configurable neighbor-search algorithms and distance metrics. |
KNeighborsRegressor | KNeighborsRegressor predicts continuous targets from the nearest training samples. It supports uniform, inverse-distance, or callable weighting and configurable neighbor-search algorithms and distance metrics. |
GaussianNB | GaussianNB is a Gaussian Naive Bayes classifier that models each feature with a class-specific normal distribution. It supports both batch training with fit and incremental learning with partial_fit. |
MultinomialNB | MultinomialNB is a Naive Bayes classifier for multinomial data, particularly discrete features such as word counts. It can also work with fractional values such as tf-idf and uses additive smoothing by default. |
BernoulliNB | BernoulliNB is a Naive Bayes classifier for multivariate Bernoulli data. It is designed for binary or Boolean features and can optionally binarize numeric inputs. |
NearestNeighbors | NearestNeighbors is an unsupervised estimator for finding nearby samples in a fitted dataset. It supports fixed-count and radius-based queries with configurable search algorithms and distance metrics. |
MiniBatchKMeans | MiniBatchKMeans performs K-Means clustering with randomly sampled mini-batches instead of repeatedly processing the full dataset. It usually reduces computation time while accepting a possible decrease in clustering quality. |
DBSCAN | DBSCAN is a density-based clustering estimator that expands clusters from dense core samples, supports arbitrary-shaped groups, and marks low-density samples as noise. It does not require the number of clusters to be specified in advance. |
AgglomerativeClustering | AgglomerativeClustering hierarchically groups samples by repeatedly merging clusters. Choose either a target cluster count or a distance threshold, with linkage and optional connectivity controlling the merges. |
SpectralClustering | Clusters samples by embedding an affinity matrix through the normalized Laplacian and then labeling points in the embedded space. It is particularly useful for small, non-convex clusters where center-and-spread descriptions are inadequate. |
MeanShift | MeanShift performs unsupervised clustering with a flat kernel, automatically discovering cluster centers from sample density. It updates candidate centroids toward local means and removes near-duplicate candidates. |
Birch | Birch is a memory-efficient, online clustering estimator that incrementally builds a Clustering Feature Tree. It can produce final clusters or compress data into subclusters for a later clustering algorithm. |
GaussianMixture | |
TruncatedSVD | TruncatedSVD reduces feature matrices to a chosen number of dimensions using truncated singular value decomposition without centering the data. It efficiently supports sparse count and TF-IDF matrices, where the transformation is commonly called latent semantic analysis (LSA). |
NMF | NMF factorizes a non-negative matrix X into non-negative matrices W and H whose product approximates X. It is useful for additive representations such as dimensionality reduction, source separation, and topic extraction. |
FastICA | FastICA is a transformer for estimating independent sources from mixed observations. It supports configurable component count, whitening, nonlinear contrast functions, iterative convergence, and initialization. |
KernelPCA | KernelPCA performs nonlinear dimensionality reduction using kernels. It can also learn an approximate inverse mapping back to the original feature space. |
LatentDirichletAllocation | LatentDirichletAllocation is a topic-model estimator that learns latent topics from a document-term matrix using variational Bayes. It supports batch and online training and can transform documents into topic distributions. |
MinMaxScaler | MinMaxScaler linearly maps each feature independently into a chosen interval, defaulting to [0, 1]. It learns feature extrema during fitting and reuses them for later transformations. |
RobustScaler | RobustScaler centers features by their median and scales them using a configurable quantile range. Its default interquartile-range statistics are less affected by outliers than mean-and-variance scaling. |
MaxAbsScaler | MaxAbsScaler scales each feature by its largest absolute training value. It preserves zero-centered structure and sparsity because it does not subtract feature means. |
Normalizer | Normalizer rescales each nonzero sample independently to unit l1, l2, or max norm. It supports dense and sparse data and is stateless, so it does not need fitting. |
OneHotEncoder | OneHotEncoder converts categorical features into binary one-hot columns. It learns or accepts category vocabularies and can control output sparsity, unknown values, dropped categories, and infrequent-category grouping. |
OrdinalEncoder | |
LabelEncoder | LabelEncoder converts target labels into integer codes from 0 to n_classes - 1 and can convert those codes back. It is for y, not input features X. |
PolynomialFeatures | PolynomialFeatures expands input columns into polynomial and interaction terms up to a chosen degree. It supports bounded degree ranges, interaction-only expansion, optional bias, and dense-output memory order. |
KBinsDiscretizer | KBinsDiscretizer converts continuous features into intervals using uniform, quantile, or one-dimensional k-means boundaries. It can emit sparse one-hot, dense one-hot, or ordinal integer representations. |
FunctionTransformer | FunctionTransformer turns an arbitrary callable into a scikit-learn transformer. It is designed for stateless operations such as logarithmic feature transforms or custom scaling. |
PowerTransformer | PowerTransformer applies a feature-wise Box-Cox or Yeo-Johnson transformation to make data more Gaussian-like. It estimates each feature's power parameter by maximum likelihood and standardizes the result by default. |
QuantileTransformer | QuantileTransformer maps each feature independently through an estimated quantile function to produce uniform or normal marginal distributions. It is a robust nonlinear preprocessing method that reduces the influence of marginal outliers. |
RandomizedSearchCV | RandomizedSearchCV samples a fixed number of hyperparameter settings and evaluates them with cross-validation. It is useful when exhaustive grid search is too costly. |
KFold | KFold creates k train/validation splits by holding out each fold once and training on the remaining folds. It can optionally shuffle fold assignment and make that ordering reproducible. |
StratifiedKFold | StratifiedKFold generates classification cross-validation folds that preserve class proportions. It returns train/test indices and can optionally shuffle class samples reproducibly. |
TimeSeriesSplit | TimeSeriesSplit is a cross-validator for time-ordered data. It builds progressively later test folds while training on earlier observations, with optional limits on training size, test size, and a gap. |
ColumnTransformer | ColumnTransformer applies different transformers to selected columns of an array or pandas DataFrame and concatenates their outputs into one feature space. It is useful for heterogeneous data requiring separate preprocessing paths. |
FeatureUnion | FeatureUnion runs multiple named transformers in parallel and concatenates their outputs into one feature space. It is useful for combining different feature-extraction approaches in a single estimator. |
SelectKBest | SelectKBest ranks features using a univariate scoring function and keeps the k highest-scoring ones. It is useful for reducing feature dimensionality before fitting an estimator. |
RFE | RFE selects features by repeatedly fitting an importance-producing estimator and removing the least important features. It returns rankings and a Boolean mask for the retained subset. |
SelectFromModel | SelectFromModel is a meta-transformer that keeps features whose model-derived importance meets a threshold. It can fit the wrapped estimator itself or consume a prefit estimator. |
TfidfVectorizer | TfidfVectorizer converts raw documents into a sparse matrix of TF-IDF features. It combines CountVectorizer and TfidfTransformer functionality in one estimator. |
CountVectorizer | CountVectorizer converts text documents into a sparse matrix of token-occurrence features. It learns a vocabulary unless one is supplied and supports configurable preprocessing, tokenization, stop-word filtering, and n-grams. |
RidgeCV | RidgeCV fits ridge regression while selecting the best regularization strength by cross-validation. It defaults to efficient leave-one-out cross-validation and supports custom scoring and validation strategies. |
LassoCV | LassoCV fits Lasso models over a regularization path and selects the penalty alpha by cross-validation. It uses coordinate descent and exposes the selected model and validation results. |
ElasticNetCV | ElasticNetCV fits Elastic Net models along a regularization path and uses cross-validation to select regularization settings. It then refits the chosen model on the full training set. |
BayesianRidge | BayesianRidge is a probabilistic linear regression estimator with Bayesian regularization. It learns noise and weight precisions from the data while fitting the model. |
HuberRegressor | HuberRegressor is an L2-regularized linear regression model that reduces the influence of outliers. It switches from squared to absolute loss when scaled residuals exceed epsilon. |
PassiveAggressiveClassifier | PassiveAggressiveClassifier is a linear online classifier using passive-aggressive updates. It supports hinge loss for PA-I and squared hinge loss for PA-II, but the class is deprecated in scikit-learn 1.8 and planned for removal in 1.10. |
NuSVC | NuSVC is a support-vector classifier whose nu parameter controls the allowed fraction of margin errors and the minimum fraction of support vectors. It supports multiple kernel types, including the default RBF kernel. |
ComplementNB | ComplementNB is a Complement Naive Bayes classifier designed for imbalanced datasets. It uses complement-class statistics and is especially useful for text classification with nonnegative features. |
CategoricalNB | CategoricalNB is a Naive Bayes classifier for categorically distributed features. Encode each feature’s categories as contiguous integers starting at zero before fitting. |
OPTICS | OPTICS estimates clustering structure while preserving density information over a range of neighborhood radii. It extracts clusters with either the Xi method or a DBSCAN-like method. |
AffinityPropagation | AffinityPropagation clusters data by exchanging messages to identify representative samples, or exemplars. It supports Euclidean similarities or a precomputed affinity matrix, with preferences influencing the number of clusters. |
IncrementalPCA | IncrementalPCA performs PCA-style SVD-based dimensionality reduction while processing data in batches. It is designed for large or sparse inputs when ordinary batch PCA would use too much memory. |
Isomap | Isomap is a nonlinear dimensionality-reduction estimator that embeds data while preserving geodesic distances. It constructs shortest-path distances on a neighborhood graph and converts them into lower-dimensional coordinates. |
LocallyLinearEmbedding | LocallyLinearEmbedding learns a low-dimensional representation by preserving local neighborhood relationships. Its method parameter supports standard, Hessian, modified, and local tangent-space alignment variants. |
TSNE | TSNE is a nonlinear method for embedding high-dimensional samples into a lower-dimensional space for visualization. It models pairwise similarities as probabilities and optimizes their low-dimensional representation. |
MDS | MDS embeds pairwise dissimilarities in a lower-dimensional space using SMACOF. It supports metric and nonmetric variants and can use Euclidean or precomputed dissimilarities. |
IsolationForest | IsolationForest detects outliers by randomly partitioning feature space into trees. Observations isolated with shorter average paths are treated as more anomalous. |
OneClassSVM | OneClassSVM is an unsupervised estimator for detecting outliers by estimating the support of a distribution. It uses kernel methods and labels samples as inliers or outliers. |
LocalOutlierFactor | LocalOutlierFactor is an unsupervised estimator for detecting observations whose local density is substantially lower than that of their nearest neighbors. It uses k-nearest-neighbor distances to compute local outlier scores. |
CalibratedClassifierCV | CalibratedClassifierCV calibrates a classifier’s probability estimates with cross-validation. It supports sigmoid, isotonic, and temperature scaling, and can average predictions from calibrated fold-specific models. |
MultiOutputClassifier | MultiOutputClassifier extends a single-output classifier to multi-target classification by fitting one classifier per target. It can parallelize target-wise fit, prediction, and supported partial fitting. |
OneVsRestClassifier | OneVsRestClassifier wraps a binary classifier to solve multiclass problems by fitting one model per class against all other classes. It also supports multilabel classification through independent binary models for each label. |
Function
| Name | What it does |
|---|---|
train_test_split | Splits aligned arrays or matrices into random training and test subsets. It supports proportional or absolute subset sizes, reproducible shuffling, and optional stratification by class labels. |
cross_val_score | Evaluate an estimator by cross-validation and return one score for each split. The function can use a named metric, a custom scorer, or the estimator's default scorer. |
accuracy_score | Computes classification accuracy by comparing predicted labels with true labels. It returns a fraction by default or a correct-sample count when normalize=False. |
confusion_matrix | Compute a classification confusion matrix from true and predicted labels. The result counts or normalizes observations by true and predicted class. |
fit | fit trains a scikit-learn estimator from feature data and, for supervised learning, targets. It stores learned state and returns the fitted estimator. |
predict | predict applies a fitted scikit-learn estimator to input samples and returns predictions. Classification produces class labels; regression produces numeric values. |
cross_validate | Evaluate one or more metrics across cross-validation folds while recording fit and score times. Optional outputs include training scores, fitted estimators, and the indices used for each split. |
cross_val_predict | Generate one out-of-fold estimate for every input sample by fitting separate estimators on cross-validation training folds. Use it to obtain predictions for visualization or downstream analysis, not as a substitute for per-fold generalization metrics. |
learning_curve | Computes cross-validated training and test scores for multiple training-set sizes. It helps assess how estimator performance changes as more training data is provided. |
validation_curve | Evaluate an estimator across values of one parameter and collect cross-validation training and test scores. The result helps reveal how that parameter affects model performance. |
precision_score | Compute classification precision: the ratio of true positives to all predicted positives. It supports binary, multiclass, and multilabel targets through configurable label selection and averaging. |
recall_score | Computes recall, the proportion of actual positive cases identified by the predictions. It supports binary, multiclass, and multilabel targets through configurable label selection and averaging. |
f1_score | Compute the F1 score, the harmonic mean of precision and recall. It ranges from 0 to 1 and supports binary, multiclass, and multilabel classification through averaging options. |
roc_auc_score | Computes the area under the receiver operating characteristic curve from prediction scores. It supports binary, multiclass, and multilabel classification, with restrictions determined by the input type and options. |
classification_report | Builds a per-class classification-metrics report from true and predicted labels. It returns formatted text by default or structured data when output_dict=True. |
mean_squared_error | Computes mean squared error, a regression loss that summarizes squared differences between true and predicted targets. It returns one aggregate value by default or per-output values when requested. |
mean_absolute_error | Computes mean absolute error, a non-negative regression loss based on absolute differences between true and predicted targets. It can weight samples and either preserve or aggregate errors across multiple outputs. |
r2_score | Computes the coefficient of determination for regression predictions. A score of 1.0 is best; scores can be negative, and multi-output results can be aggregated or returned separately. |
roc_curve | Computes the receiver operating characteristic for binary classification by evaluating scores at decision thresholds. Returns false-positive rates, true-positive rates, and the thresholds that produce them. |
precision_recall_curve | Computes precision-recall pairs over score thresholds for binary classification. It accepts positive-class probabilities or classifier decision scores and returns precision, recall, and thresholds. |
log_loss | Computes classification log loss, also called logistic or cross-entropy loss, from true labels and predicted probabilities. It evaluates the negative log-likelihood of the true labels and returns the mean by default. |
silhouette_score | Computes the mean Silhouette Coefficient for a clustering assignment. Scores near 1 indicate well-separated clusters, near 0 indicate overlap, and negative values often indicate unsuitable assignments. |
make_pipeline | Constructs a scikit-learn Pipeline from estimators supplied in order. It automatically generates lowercase step names from estimator types. |
make_column_transformer | Creates a ColumnTransformer from transformer-and-column pairs without requiring explicit transformer names. Names are generated automatically from transformer types. |
make_classification | Generates a synthetic n-class classification problem with controllable class structure, feature categories, and noise. It returns feature data and integer labels by default. |
make_regression | Generates synthetic regression data from a random linear model. It supports configurable feature structure, informative features, target count, Gaussian noise, shuffling, and optional recovery of the true coefficients. |
make_blobs | Generates synthetic multiclass data as isotropic Gaussian clusters. It returns feature samples and integer cluster labels, with optional generated center coordinates. |
load_iris | Loads scikit-learn’s built-in Iris dataset for multi-class classification. It returns a metadata-rich Bunch by default, or data and targets directly with configurable pandas output. |
load_digits | Loads scikit-learn’s built-in handwritten-digits classification dataset. It can return a metadata-rich Bunch or a features-and-target tuple, with optional class restriction and pandas output. |
fetch_openml | Downloads a dataset from OpenML by name or numeric ID. It can cache the download and return either a dataset container or separate features and target. |
permutation_importance | Computes feature importance for a fitted estimator by repeatedly shuffling each feature and measuring the resulting score change. It returns per-feature averages, variability, and raw scores across permutations. |
balanced_accuracy_score | Computes balanced accuracy for binary or multiclass classification by averaging recall across classes. It is designed to provide a more informative score than ordinary accuracy on imbalanced datasets. |
cohen_kappa_score | Computes Cohen’s kappa, a chance-adjusted measure of agreement between two classification labelings. It supports optional ordinal disagreement weights, sample weights, explicit labels, and an undefined-result replacement value. |
matthews_corrcoef | Computes the Matthews correlation coefficient (MCC) for binary or multiclass classification. The score ranges from -1 for inverse prediction to +1 for perfect prediction, with 0 representing average random prediction. |
adjusted_rand_score | Computes the Rand similarity between two clusterings and corrects it for chance. It is symmetric, returns 1.0 for identical partitions up to label permutation, and is near 0.0 for random labelings. |
GroupKFold | GroupKFold performs K-fold cross-validation while keeping each group wholly within one fold. Every group is used as test data exactly once, preventing the same group from appearing in both training and test data. |
LeaveOneOut | LeaveOneOut is a cross-validator that holds out one sample at a time while using all remaining samples for training. It creates as many splits as there are samples. |
RepeatedKFold | RepeatedKFold repeats K-fold cross-validation several times, randomizing the fold assignments for each repetition. Use random_state when reproducible splits are needed. |
Module
| Name | What it does |
|---|---|
transform | |
fit_transform | fit_transform fits a transformer on data and then transforms that data in one call. It accepts optional targets and fit parameters, returning the transformed feature array. |
predict_proba | |
score | accuracy_score evaluates classification predictions by comparing true and predicted labels. It returns either the fraction of correct samples or their count, with optional sample weighting. |
fit_predict | fit_predict fits an estimator and returns predictions for the same training data in one call. It is especially useful for unsupervised, transductive estimators and clustering workflows. |
Search across every package and filter by type in your dashboard.
Start learning