kaggle教程--7--Partial Dependence Plots


Partial Dependence Plots:部分依賴圖

 

模型訓練后(fit),才可以創建部分依賴圖(PDP)

部分依賴圖,反映出了某一列特征,對目標列(target)的影響

 

例子:

from sklearn.ensemble.partial_dependence import partial_dependence, plot_partial_dependence

# get_some_data is defined in hidden cell above.
X, y = get_some_data()
# scikit-learn originally implemented partial dependence plots only for Gradient Boosting models
# this was due to an implementation detail, and a future release will support all model types.
my_model = GradientBoostingRegressor()
# fit the model as usual
my_model.fit(X, y)
# Here we make the plot
my_plots = plot_partial_dependence(my_model,
features=[0,1,2], # column numbers of plots we want to show
X=X, # raw predictors data.
feature_names=['Distance', 'Landsize', 'BuildingArea'], # labels on graphs
grid_resolution=10) # number of values to plot on x axis 代表橫坐標上點的數量,越大表示圖上的點越多,默認為100

部分依賴圖(PDP)使用提示:

一次最多顯示2-3個變量,太多了看不清

grid_resolution參數不要太大,否則圖形的鋸齒狀明顯,可以像例子一樣設置為10

還有一個方法叫partial_dependence,這個可以返回構成PDP的原始數據,可以用Seaborn等圖形包畫出更好看的圖


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM