调整部分依赖图的大小 - 看起来太小了

Din*_*esh 4 python matplotlib scikit-learn

我通过 Scikit learn 的库创建了部分依赖图。但是,由于我可以完全阅读所有图,因此我在将图调整得更大方面面临挑战。有没有一种方法可以改变绘图视图和大小?

代码:

from sklearn.ensemble.partial_dependence import partial_dependence, plot_partial_dependence
import pandas as pd
from pandas import read_csv, DataFrame
from sklearn.ensemble import GradientBoostingRegressor
import numpy as np

my_model = GradientBoostingRegressor()
my_model.fit(X, y)

my_plots = plot_partial_dependence(my_model,       
                        features=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22],
                        X=X,        
                        feature_names=['core_self_evaluations', '1b_score', 'investigate','respect_for_people','social','mastery_orientation','realistic','conventional','astronaut_score','innovation','agreeableness','gradeClass_second_lower','AC_TeamPlayer','enterprising','AC_Problemsolving','AC_StartsConversation','verbal','leadership_score','Race_chinese','performance_orientation','self_monitoring','UniLoc_overseas','attention_to_detail'], # labels on graphs
                        grid_resolution=5) 
Run Code Online (Sandbox Code Playgroud)

创建的情节:

在此处输入图片说明

Din*_*esh 5

我已经用下面的代码解决了尺寸问题:

import matplotlib.pyplot as plt
fig, ax = plot_partial_dependence(my_model,       
                        features=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22],
                        X=X,        
                        feature_names=['core_self_evaluations', '1b_score', 'investigate','respect_for_people','social','mastery_orientation','realistic','conventional','astronaut_score','innovation','agreeableness','gradeClass_second_lower','AC_TeamPlayer','enterprising','AC_Problemsolving','AC_StartsConversation','verbal','leadership_score','Race_chinese','performance_orientation','self_monitoring','UniLoc_overseas','attention_to_detail'], # labels on graphs
                        grid_resolution=5) 
fig.set_figwidth(8)
fig.set_figheight(15)
fig.tight_layout()
Run Code Online (Sandbox Code Playgroud)

这提供了具有可自定义高度和宽度的非常好的布局。要查看的提示是该方法的返回值(即“fig”和“ax”)。使用这两个返回值,可以使用额外的选项,例如独立设置宽度和高度。


Bri*_*ien 5

ax参数是 v 0.22 中的新参数。

这是当前的方式:

fig, ax = plt.subplots(figsize=(14, 14))
plot_partial_dependence(est, X, ax=ax)
Run Code Online (Sandbox Code Playgroud)

更新了当前 API 的示例。