示例#

这是展示如何使用scikit-learn的示例库。一些示例演示了 API 一般来说,有些以教程形式演示特定的应用程序。另请查看我们的 user guide 了解更详细的插图。

发布亮点#

这些示例说明了scikit-learn版本的主要功能。

scikit-learn 1.6的发布亮点

Release Highlights for scikit-learn 1.6

scikit-learn 1.5的发布亮点

Release Highlights for scikit-learn 1.5

scikit-learn 1.4的发布亮点

Release Highlights for scikit-learn 1.4

scikit-learn 1.3的发布亮点

Release Highlights for scikit-learn 1.3

scikit-learn 1.1的发布亮点

Release Highlights for scikit-learn 1.1

scikit-learn 1.0的发布亮点

Release Highlights for scikit-learn 1.0

scikit-learn 0.24发布亮点

Release Highlights for scikit-learn 0.24

scikit-learn 0.23的发布亮点

Release Highlights for scikit-learn 0.23

双聚类#

有关双集群技术的示例。

光谱双集群算法的演示

A demo of the Spectral Biclustering algorithm

光谱协同聚集算法的演示

A demo of the Spectral Co-Clustering algorithm

使用谱协同集群算法对文档进行二集群

Biclustering documents with the Spectral Co-clustering algorithm

校准#

示例说明分类器预测概率的校准。

分类器校准的比较

Comparison of Calibration of Classifiers

概率校准曲线

Probability Calibration curves

分类器的概率校准

Probability calibration of classifiers

分类#

有关分类算法的一般示例。

分类器比较

Classifier comparison

具有协方差椭圆体的线性和二次鉴别分析

Linear and Quadratic Discriminant Analysis with covariance ellipsoid

用于分类的正态、Ledoit-Wolf和OAS线性鉴别分析

Normal, Ledoit-Wolf and OAS Linear Discriminant Analysis for classification

识别手写数字

Recognizing hand-written digits

聚类#

有关的例子 sklearn.cluster module.

手写数字数据上的K-Means集群演示

A demo of K-Means clustering on the handwritten digits data

硬币图像上的结构化Ward分层集群演示

A demo of structured Ward hierarchical clustering on an image of coins

均值漂移集群算法的演示

A demo of the mean-shift clustering algorithm

集群绩效评估中的机会调整

Adjustment for chance in clustering performance evaluation

有结构和不有结构的集聚

Agglomerative clustering with and without structure

具有不同指标的聚集性集群

Agglomerative clustering with different metrics

K-Means++初始化的示例

An example of K-Means++ initialization

二分K均值和常规K均值性能比较

Bisecting K-Means and Regular K-Means Performance Comparison

比较BIRCH和MiniBatchKMeans

Compare BIRCH and MiniBatchKMeans

在玩具数据集上比较不同的聚类算法

Comparing different clustering algorithms on toy datasets

在玩具数据集上比较不同的分层链接方法

Comparing different hierarchical linkage methods on toy datasets

K-Means和MiniBatchKMeans集群算法的比较

Comparison of the K-Means and MiniBatchKMeans clustering algorithms

DBSCAN集群算法演示

Demo of DBSCAN clustering algorithm

HDSCAN集群算法演示

Demo of HDBSCAN clustering algorithm

OPTICS分簇算法演示

Demo of OPTICS clustering algorithm

亲和力传播分簇算法演示

Demo of affinity propagation clustering algorithm

k均值假设的证明

Demonstration of k-means assumptions

k均值初始化影响的实证评估

Empirical evaluation of the impact of k-means initialization

特征聚集

Feature agglomeration

特征聚集与单变量选择

Feature agglomeration vs. univariate selection

分层集群:结构化与非结构化病房

Hierarchical clustering: structured vs unstructured ward

归纳集群

Inductive Clustering

在线学习面部部分词典

Online learning of a dictionary of parts of faces

图分层聚集树图

Plot Hierarchical Clustering Dendrogram

按地区划分希腊硬币的图片

Segmenting the picture of greek coins in regions

在KMeans聚类中使用轮廓分析选择聚类数

Selecting the number of clusters with silhouette analysis on KMeans clustering

用于图像分割的光谱集群

Spectral clustering for image segmentation

2D数字嵌入上的各种聚集性聚集

Various Agglomerative Clustering on a 2D embedding of digits

载体量化示例

Vector Quantization Example

协方差估计#

有关的例子 sklearn.covariance module.

Ledoit-Wolf与OAS估计

Ledoit-Wolf vs OAS estimation

稳健协方差估计和Mahalanobis距离相关性

Robust covariance estimation and Mahalanobis distances relevance

稳健与经验协方差估计

Robust vs Empirical covariance estimate

收缩协方差估计:LedoitWolf vs OAS和最大似然

Shrinkage covariance estimation: LedoitWolf vs OAS and max-likelihood

稀疏逆协方差估计

Sparse inverse covariance estimation

交叉分解#

有关的例子 sklearn.cross_decomposition module.

比较交叉分解方法

Compare cross decomposition methods

主成分回归与偏最小平方回归

Principal Component Regression vs Partial Least Squares Regression

数据集示例#

有关的例子 sklearn.datasets module.

绘制随机生成的多标签数据集

Plot randomly generated multilabel dataset

决策树#

有关的例子 sklearn.tree module.

决策树回归

Decision Tree Regression

绘制在虹膜数据集上训练的决策树的决策面

Plot the decision surface of decision trees trained on the iris dataset

具有成本复杂性修剪的后修剪决策树

Post pruning decision trees with cost complexity pruning

了解决策树结构

Understanding the decision tree structure

分解#

有关的例子 sklearn.decomposition module.

使用FastICA的盲源分离

Blind source separation using FastICA

Iris数据集LDA和PCA 2D投影的比较

Comparison of LDA and PCA 2D projection of Iris dataset

Faces数据集分解

Faces dataset decompositions

因子分析(旋转)以可视化模式

Factor Analysis (with rotation) to visualize patterns

2D点云上的FastICA

FastICA on 2D point clouds

使用字典学习的图像去噪

Image denoising using dictionary learning

增量PCA

Incremental PCA

核PCA

Kernel PCA

使用概率PCA和因子分析(FA)进行模型选择

Model selection with Probabilistic PCA and Factor Analysis (FA)

Iris数据集的主成分分析(PCA)

Principal Component Analysis (PCA) on Iris Dataset

使用预先计算的字典进行稀疏编码

Sparse coding with a precomputed dictionary

开发估算器#

有关自定义估算器开发的示例。

__sklearn_is_fitted__ 作为开发人员API

__sklearn_is_fitted__ as Developer API

集成方法#

有关的例子 sklearn.ensemble module.

梯度提升中的分类特征支持

Categorical Feature Support in Gradient Boosting

使用堆叠组合预测因子

Combine predictors using stacking

比较随机森林和柱状图梯度增强模型

Comparing Random Forests and Histogram Gradient Boosting models

比较随机森林和多输出Meta估计量

Comparing random forests and the multi-output meta estimator

使用AdaBoost进行决策树回归

Decision Tree Regression with AdaBoost

Gradient Boosting中的提前停止

Early stopping in Gradient Boosting

树木森林的重要性

Feature importances with a forest of trees

使用树木集合的特征转换

Feature transformations with ensembles of trees

梯度增强树的梯度中的功能

Features in Histogram Gradient Boosting Trees

梯度提升袋外估计

Gradient Boosting Out-of-Bag estimates

梯度增强回归

Gradient Boosting regression

梯度提升正规化

Gradient Boosting regularization

使用完全随机树哈希特征转换

Hashing feature transformation using Totally Random Trees

隔离森林示例

IsolationForest example

单调约束

Monotonic Constraints

多类AdaBoosted决策树

Multi-class AdaBoosted Decision Trees

随机森林的OOB错误

OOB Errors for Random Forests

绘制个人和投票回归预测图

Plot individual and voting regression predictions

在虹膜数据集中绘制树木集合的决策面

Plot the decision surfaces of ensembles of trees on the iris dataset

梯度Boosting回归的预测区间

Prediction Intervals for Gradient Boosting Regression

单一估计量与装袋:偏差方差分解

Single estimator versus bagging: bias-variance decomposition

两级AdaBoost

Two-class AdaBoost

可视化VotingClassifier的概率预测

Visualizing the probabilistic predictions of a VotingClassifier

基于现实世界数据集的示例#

应用于具有一些中等大小数据集或交互式用户界面的现实世界问题。

压缩感知:使用L1先验进行断层扫描重建(Lasso)

Compressive sensing: tomography reconstruction with L1 prior (Lasso)

使用特征脸和SVM的人脸识别示例

Faces recognition example using eigenfaces and SVMs

基于核主成分分析的图像去噪

Image denoising using kernel PCA

时间序列预测的滞后特征

Lagged features for time series forecasting

模型复杂性影响

Model Complexity Influence

真实数据集上的离群值检测

Outlier detection on a real data set

预测延迟

Prediction Latency

物种分布建模

Species distribution modeling

与时间相关的特征工程

Time-related feature engineering

非负矩阵分解和潜在Dirichlet分配的主题提取

Topic extraction with Non-negative Matrix Factorization and Latent Dirichlet Allocation

股票市场结构可视化

Visualizing the stock market structure

维基百科主特征量

Wikipedia principal eigenvector

特征选择#

有关的例子 sklearn.feature_selection module.

F检验与互信息的比较

Comparison of F-test and mutual information

基于模型的顺序特征选择

Model-based and sequential feature selection

流水线ANOVA SVM

Pipeline ANOVA SVM

递归特征消除

Recursive feature elimination

单变量特征选择

Univariate Feature Selection

冻结的估计者#

有关的例子 sklearn.frozen module.

例子利用 FrozenEstimator

Examples of Using FrozenEstimator

高斯混合模型#

有关的例子 sklearn.mixture module.

变异Bayesian高斯混合物的浓度先验型分析

Concentration Prior Type Analysis of Variation Bayesian Gaussian Mixture

高斯混合物的密度估计

Density Estimation for a Gaussian mixture

GMM检查方法

GMM Initialization Methods

GMM协方差

GMM covariances

高斯混合模型椭圆体

Gaussian Mixture Model Ellipsoids

高斯混合模型选择

Gaussian Mixture Model Selection

高斯混合模型顺曲线

Gaussian Mixture Model Sine Curve

机器学习的高斯过程#

有关的例子 sklearn.gaussian_process module.

高斯过程回归(GPT)估计数据噪音水平的能力

Ability of Gaussian process regression (GPR) to estimate data noise-level

核岭回归与高斯过程回归的比较

Comparison of kernel ridge and Gaussian process regression

使用高斯过程回归(GPT)预测Mona Loa数据集的二氧化碳水平

Forecasting of CO2 level on Mona Loa dataset using Gaussian process regression (GPR)

高斯过程回归:基本入门示例

Gaussian Processes regression: basic introductory example

虹膜数据集上的高斯过程分类(GSK)

Gaussian process classification (GPC) on iris dataset

离散数据结构上的高斯过程

Gaussian processes on discrete data structures

异或数据集上的高斯过程分类(GSK)插图

Illustration of Gaussian process classification (GPC) on the XOR dataset

不同核的先验和后验高斯过程的说明

Illustration of prior and posterior Gaussian process for different kernels

高斯过程分类(GSK)的等概率线

Iso-probability lines for Gaussian Processes classification (GPC)

利用高斯过程分类(GSK)进行概率预测

Probabilistic predictions with Gaussian process classification (GPC)

广义线性模型#

有关的例子 sklearn.linear_model module.

比较线性Bayesian回归量

Comparing Linear Bayesian Regressors

利用Bayesian Ridge回归进行曲线匹配

Curve Fitting with Bayesian Ridge Regression

多项和一对二回归的决策边界

Decision Boundaries of Multinomial and One-vs-Rest Logistic Regression

随机梯度下降的早停止

Early stopping of Stochastic Gradient Descent

使用预先计算的格拉姆矩阵和加权样本来匹配弹性网络

Fitting an Elastic Net with a precomputed Gram Matrix and Weighted Samples

HuberRegressor与Ridge在具有强异常值的数据集上

HuberRegressor vs Ridge on dataset with strong outliers

使用多任务Lasso进行联合特征选择

Joint feature selection with multi-task Lasso

逻辑回归中的L1罚分和稀疏性

L1 Penalty and Sparsity in Logistic Regression

基于L1的稀疏信号模型

L1-based models for Sparse Signals

通过信息标准选择Lasso模型

Lasso model selection via information criteria

Lasso型号选择:AIC-BIC /交叉验证

Lasso model selection: AIC-BIC / cross-validation

密集和稀疏数据上的套索

Lasso on dense and sparse data

Lasso、Lasso-LARS和Elastic Net路径

Lasso, Lasso-LARS, and Elastic Net paths

逻辑函数

Logistic function

使用多项逻辑+ L1的MNIST分类

MNIST classification using multinomial logistic + L1

20个新群体的多类稀疏逻辑回归

Multiclass sparse logistic regression on 20newgroups

非负最小平方

Non-negative least squares

使用随机梯度下降的一类支持者与一类支持者

One-Class SVM versus One-Class SVM using Stochastic Gradient Descent

普通最小二乘和岭回归

Ordinary Least Squares and Ridge Regression

正交匹配追踪

Orthogonal Matching Pursuit

绘制岭系数作为正规化的函数

Plot Ridge coefficients as a function of the regularization

在iris数据集上绘制多类新元

Plot multi-class SGD on the iris dataset

多项和样条插值

Polynomial and Spline interpolation

分位数回归

Quantile regression

L1-逻辑回归的正规化路径

Regularization path of L1- Logistic Regression

作为L2正则化函数的脊系数

Ridge coefficients as a function of the L2 Regularization

鲁棒线性估计量匹配

Robust linear estimator fitting

使用RASAC的鲁棒线性模型估计

Robust linear model estimation using RANSAC

新元:分离超平面的最大裕度

SGD: Maximum margin separating hyperplane

新元:处罚

SGD: Penalties

新元:加权样本

SGD: Weighted samples

新元:凸损失函数

SGD: convex loss functions

Theil-Sen回归

Theil-Sen Regression

检查#

sklearn.inspection module.

线性模型系数解释中的常见陷阱

Common pitfalls in the interpretation of coefficients of linear models

机器学习无法推断因果效应

Failure of Machine Learning to infer causal effects

排列重要性与随机森林特征重要性(Millennium)

Permutation Importance vs Random Forest Feature Importance (MDI)

具有多重共线或相关特征的排列重要性

Permutation Importance with Multicollinear or Correlated Features

核近似#

有关的例子 sklearn.kernel_approximation module.

具有多项核逼近的可扩展学习

Scalable learning with polynomial kernel approximation

流形学习#

有关的例子 sklearn.manifold module.

多种学习方法的比较

Comparison of Manifold Learning methods

分割球面上的流形学习方法

Manifold Learning methods on a severed sphere

手写数字的流形学习:局部线性嵌入,Isomap...

Manifold learning on handwritten digits: Locally Linear Embedding, Isomap...

多维标度

Multi-dimensional scaling

瑞士滚动和瑞士洞减少

Swiss Roll And Swiss-Hole Reduction

t-SNE:各种困惑度值对形状的影响

t-SNE: The effect of various perplexity values on the shape

杂项#

scikit-learn的其他和介绍性示例。

部分相关的高级绘图

Advanced Plotting With Partial Dependence

比较玩具数据集异常值检测的异常检测算法

Comparing anomaly detection algorithms for outlier detection on toy datasets

核岭回归与SVR的比较

Comparison of kernel ridge regression and SVR

管道

Displaying Pipelines

NPS估计器和复杂管道

Displaying estimators and complex pipelines

基于RBS核的显式特征图逼近

Explicit feature map approximation for RBF kernels

使用多输出估计器完成面

Face completion with a multi-output estimators

介绍 set_output API

Introducing the set_output API

保序回归

Isotonic Regression

元数据路由

Metadata Routing

多标签分类

Multilabel classification

随机投影嵌入的Johnson-Lindenstrauss界

The Johnson-Lindenstrauss bound for embedding with random projections

具有显示对象的可视化

Visualizations with Display Objects

缺失值插补#

有关的例子 sklearn.impute module.

在构建估计器之前输入缺失值

Imputing missing values before building an estimator

使用IterativeImputer的变体输入缺失值

Imputing missing values with variants of IterativeImputer

模型选择#

sklearn.model_selection module.

平衡模型复杂性和交叉验证分数

Balance model complexity and cross-validated score

比较随机搜索和网格搜索用于超参数估计

Comparing randomized search and grid search for hyperparameter estimation

网格搜索和连续减半的比较

Comparison between grid search and successive halving

混淆矩阵

Confusion matrix

具有交叉验证的网格搜索自定义改装策略

Custom refit strategy of a grid search with cross-validation

基于cross_val_score和GridSearchCV的多度量评估演示

Demonstration of multi-metric evaluation on cross_val_score and GridSearchCV

模型正规化对训练和测试误差的影响

Effect of model regularization on training and test error

嵌套与非嵌套交叉验证

Nested versus non-nested cross-validation

绘制交叉验证预测

Plotting Cross-Validated Predictions

绘制学习曲线并检查模型的可扩展性

Plotting Learning Curves and Checking Models' Scalability

事后调整决策函数的截止点

Post-hoc tuning the cut-off point of decision function

pr曲线

Precision-Recall

具有交叉验证的接收器工作特性(ROC)

Receiver Operating Characteristic (ROC) with cross validation

用于文本特征提取和评估的样本管道

Sample pipeline for text feature extraction and evaluation

使用网格搜索进行模型统计比较

Statistical comparison of models using grid search

连续减半迭代

Successive Halving Iterations

用排列测试分类分数的重要性

Test with permutations the significance of a classification score

不足与过度贴合

Underfitting vs. Overfitting

在scikit-learn中可视化交叉验证行为

Visualizing cross-validation behavior in scikit-learn

多类方法#

有关的例子 sklearn.multiclass module.

多类训练元估计器概述

Overview of multiclass training meta-estimators

多输出方法#

有关的例子 sklearn.multioutput module.

使用分类器链的多标签分类

Multilabel classification using a classifier chain

最近邻居#

有关的例子 sklearn.neighbors module.

TSNE的大约最近邻居

Approximate nearest neighbors in TSNE

缓存最近的邻居

Caching nearest neighbors

比较使用和不使用邻居成分分析的最近邻居

Comparing Nearest Neighbors with and without Neighborhood Components Analysis

利用邻居成分分析降低维度

Dimensionality Reduction with Neighborhood Components Analysis

物种分布的核密度估计

Kernel Density Estimate of Species Distributions

核密度估计

Kernel Density Estimation

最近的重心分类

Nearest Centroid Classification

最近邻分类

Nearest Neighbors Classification

最近邻回归

Nearest Neighbors regression

邻里要素分析插图

Neighborhood Components Analysis Illustration

利用本地异常值因子(LOF)进行新颖性检测

Novelty detection with Local Outlier Factor (LOF)

使用局部离群因子(LOF)进行离群点检测

Outlier detection with Local Outlier Factor (LOF)

简单的1D核密度估计

Simple 1D Kernel Density Estimation

神经网络#

有关的例子 sklearn.neural_network module.

比较MLP分类器的随机学习策略

Compare Stochastic learning strategies for MLPClassifier

数字分类的受限制Boltzmann Machine功能

Restricted Boltzmann Machine features for digit classification

多层感知器中的变化规则化

Varying regularization in Multi-layer Perceptron

MNIST上MLP权重的可视化

Visualization of MLP weights on MNIST

管道和复合估计量#

如何从其他估计器组成变压器和管道的示例。看到 User Guide .

具有异类数据源的列Transformer

Column Transformer with Heterogeneous Data Sources

混合类型的列Transformer

Column Transformer with Mixed Types

级联多种特征提取方法

Concatenating multiple feature extraction methods

回归模型中目标转换的效果

Effect of transforming the targets in regression model

流水线:链接PCA和逻辑回归

Pipelining: chaining a PCA and a logistic regression

使用Pipeline和GridSearchCV选择降维

Selecting dimensionality reduction with Pipeline and GridSearchCV

预处理#

有关的例子 sklearn.preprocessing module.

比较不同缩放器对数据的影响与离群值

Compare the effect of different scalers on data with outliers

比较目标编码器与其他编码器

Comparing Target Encoder with Other Encoders

特征缩放的重要性

Importance of Feature Scaling

将数据映射到正态分布

Map data to a normal distribution

目标编码器的内部交叉拟合

Target Encoder's Internal Cross fitting

半监督分类#

有关的例子 sklearn.semi_supervised module.

Iris数据集上半监督分类器与支持机的决策边界

Decision boundary of semi-supervised classifiers versus SVM on the Iris dataset

不同阈值对自我训练的影响

Effect of varying threshold for self-training

标签传播圈:学习复杂结构

Label Propagation circles: Learning a complex structure

标签传播数字:主动学习

Label Propagation digits: Active learning

标签传播数字:展示性能

Label Propagation digits: Demonstrating performance

文本数据集的半监督分类

Semi-supervised Classification on a Text Dataset

支持向量机#

有关的例子 sklearn.svm module.

带非线性核(RBS)的一类支持者

One-class SVM with non-linear kernel (RBF)

具有不同支持机核的地块分类边界

Plot classification boundaries with different SVM Kernels

在虹膜数据集中绘制不同的支持者分类器

Plot different SVM classifiers in the iris dataset

在LinearSRC中绘制支持载体

Plot the support vectors in LinearSVC

RBF SVM参数

RBF SVM parameters

支持机边缘示例

SVM Margins Example

SV打破平局示例

SVM Tie Breaking Example

具有自定义内核的支持者

SVM with custom kernel

SVM-Anova:具有单变量特征选择的支持者

SVM-Anova: SVM with univariate feature selection

SV:最大裕度分离超平面

SVM: Maximum margin separating hyperplane

支持者:分离不平衡类别的超平面

SVM: Separating hyperplane for unbalanced classes

支持者:加权样本

SVM: Weighted samples

缩放SVCs的正规化参数

Scaling the regularization parameter for SVCs

使用线性和非线性核的支持量回归(SVR)

Support Vector Regression (SVR) using linear and non-linear kernels

使用文本文档#

有关的例子 sklearn.feature_extraction.text module.

使用稀疏特征对文本文档进行分类

Classification of text documents using sparse features

基于k-means的文本聚类

Clustering text documents using k-means

收件箱Hasher和DictVectorizer比较

FeatureHasher and DictVectorizer Comparison

Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io> _