日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【机器学习】机器学习可视化利器--Yellowbrick

發布時間:2025/3/12 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【机器学习】机器学习可视化利器--Yellowbrick 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • 本文分享機器學習工具Scikit-Learn強力擴展yellowbrick

  • 通過幾行代碼可視化特征值、模型、模型評估等,幫助更便捷的的選擇機器學習模型和調參,依賴Matplotlib和Scikit-Learn。

本文目錄


yellowbrick安裝

#?清華源加速安裝 pip?install?yellowbrick?-i?https://pypi.tuna.tsinghua.edu.cn/simple

yellowbrick核心“武器”?-?Visualizers

Visualizers可以理解為一個scikit-learn的估計器(estimator)對象,但是附加了可視化的屬性,使用過程與使用scikit-learn模型類似:

  • 導入特定的visualizers;

  • 實例化visualizers;

  • 擬合visualizers;

  • 可視化展示。


yellowbrick實例快速上手

  • 展示ROC曲線,評估不同模型效果

import?matplotlib.pyplot?as?pltplt.figure(dpi=120) from?sklearn.linear_model?import?RidgeClassifier from?sklearn.model_selection?import?train_test_split from?sklearn.preprocessing?import?OrdinalEncoder,?LabelEncoderfrom?yellowbrick.classifier?import?ROCAUC from?yellowbrick.datasets?import?load_game#?導入數據 X,?y?=?load_game()#?數據轉換 X?=?OrdinalEncoder().fit_transform(X) y?=?LabelEncoder().fit_transform(y)#?構建測試集和訓練集 X_train,?X_test,?y_train,?y_test?=?train_test_split(X,?y,?random_state=42)#?實例化分類模型和visualizer model?=?RidgeClassifier() visualizer?=?ROCAUC(model,?classes=["win",?"loss",?"draw"])visualizer.fit(X_train,?y_train)??#?擬合visualizer visualizer.score(X_test,?y_test)??#?評價模型在訓練集上效果 visualizer.show()
  • 特征工程中,展示PCA降維效果

import?matplotlib.pyplot?as?pltplt.figure(dpi=120) from?yellowbrick.features?import?PCAX,?y?=?load_credit() classes?=?['account?in?default',?'current?with?bills']visualizer?=?PCA(scale=True,?projection=3,?classes=classes) visualizer.fit_transform(X,?y) visualizer.show()
  • 回歸模型中,展示預測值和真實值之間的殘差,Q-Q plot評估模型效果。

from?sklearn.linear_model?import?Ridge from?sklearn.model_selection?import?train_test_splitfrom?yellowbrick.datasets?import?load_concrete from?yellowbrick.regressor?import?ResidualsPlot#?導入數據 X,?y?=?load_concrete()#?構建訓練集、測試集 X_train,?X_test,?y_train,?y_test?=?train_test_split(X,?y,?test_size=0.2,?random_state=42)#?實例化模型和visualizer model?=?Ridge() visualizer?=?ResidualsPlot(model,?hist=False,?qqplot=True) visualizer.fit(X_train,?y_train) visualizer.score(X_test,?y_test) visualizer.show()Residuals Plot on the Concrete dataset with a Q-Q plot
  • 展示Lasso回歸模型效果

import?matplotlib.pyplot?as?pltplt.figure(dpi=120) from?sklearn.linear_model?import?Lasso from?yellowbrick.datasets?import?load_bikeshare from?yellowbrick.regressor?import?prediction_errorX,?y?=?load_bikeshare() visualizer?=?prediction_error(Lasso(),?X,?y)#一行代碼即可展示,方不方便

更多實例見下一節~~


yellowbrick常用的Visualizers

特征展示(Feature Visualization)

  • Rank Features: pairwise ranking of features to detect relationships

  • Parallel Coordinates: horizontal visualization of instances

  • Radial Visualization: separation of instances around a circular plot

  • PCA Projection: projection of instances based on principal components

  • Manifold Visualization: high dimensional visualization with manifold learning

  • Joint Plots: direct data visualization with feature selection

分類模型展示(Classification Visualization)

  • Class Prediction Error: shows error and support in classification

  • Classification Report: visual representation of precision, recall, and F1

  • ROC/AUC Curves: receiver operator characteristics and area under the curve

  • Precision-Recall Curves: precision vs recall for different probability thresholds

  • Confusion Matrices: visual description of class decision making

  • Discrimination Threshold: find a threshold that best separates binary classes

回歸模型展示(Regression Visualization)

  • Prediction Error Plot: find model breakdowns along the domain of the target

  • Residuals Plot: show the difference in residuals of training and test data

  • Alpha Selection: show how the choice of alpha influences regularization

  • Cook’s Distance: show the influence of instances on linear regression

聚類模型展示(Clustering Visualization)

  • K-Elbow Plot: select k using the elbow method and various metrics

  • Silhouette Plot: select k by visualizing silhouette coefficient values

  • Intercluster Distance Maps: show relative distance and size/importance of clusters

模型選擇(Model Selection Visualization)

  • Validation Curve: tune a model with respect to a single hyperparameter

  • Learning Curve: show if a model might benefit from more data or less complexity

  • Feature Importances: rank features by importance or linear coefficients for a specific model

  • Recursive Feature Elimination: find the best subset of features based on importance

目標展示(Target Visualization)

  • Balanced Binning Reference: generate a histogram with vertical lines showing the recommended value point to bin the data into evenly distributed bins

  • Class Balance: see how the distribution of classes affects the model

  • Feature Correlation: display the correlation between features and dependent variables

文本展示(Text Visualization)

  • Term Frequency: visualize the frequency distribution of terms in the corpus

  • t-SNE Corpus Visualization: use stochastic neighbor embedding to project documents

  • Dispersion Plot: visualize how key terms are dispersed throughout a corpus

  • UMAP Corpus Visualization: plot similar documents closer together to discover clusters

  • PosTag Visualization: plot the counts of different parts-of-speech throughout a tagged corpus


yellowbrick圖形個性化設置

https://www.scikit-yb.org/en/latest/index.html


-END-

👇點擊👇

Python可視化

Python入門及提高

統計學入門及提高

R可視化

關注「pythonic生物人」

加微信群:掃碼備注學習

日拱一卒無有盡,功不唐捐終入海!「??動手點個在看,下期見~」

總結

以上是生活随笔為你收集整理的【机器学习】机器学习可视化利器--Yellowbrick的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。