Python基础学习-Day32
面对一个全新的官方库,是否可以借助官方文档的写法了解其如何使用。
我们以pdpbox这个机器学习解释性库来介绍如何使用官方文档。
大多数 Python 库都会有官方文档,里面包含了函数的详细说明、用法示例以及版本兼容性信息。
通常查询方式包含以下2种:
- GitHub 仓库:https://github.com/SauceCat/PDPbox
- PyPI 页面:https://pypi.org/project/PDPbox/
- 官方文档:https://pdpbox.readthedocs.io/en/latest/
一般通过github仓库都可以找到对应的官方文档那个。
在官方文档中搜索函数名,然后查看函数的详细说明和用法示例。
iris = load_iris()
df = pd.DataFrame(iris.data, columns=iris.feature_names)
df['target'] = iris.target
features = iris.feature_names
target = 'target'X_train, X_test, y_train, y_test = train_test_split(df[features], df[target], test_size=0.2, random_state=42
)model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)import pdpbox
print(pdpbox.__version__)from pdpbox.info_plots import TargetPlotfeature = 'petal length (cm)'
feature_name = feature feature = 'petal length (cm)'
feature_name = feature
)
target_plot = TargetPlot(df=df, feature=feature, feature_name=feature_name, # target='target',target='target', grid_type='percentile', num_grid_points=10 target_plot.plot()
type(target_plot.plot())
len(target_plot.plot())
target_plot.plot()[0]
target_plot.plot()[2]fig, axes, summary_df = target_plot.plot(which_classes=None, show_percentile=True, engine='plotly',template='plotly_white'
)
)
fig.update_layout(width=800, height=500, title=dict(text=f'Target Plot: {feature_name}', x=0.5) fig.show()
@浙大疏锦行