%load_ext autoreload
%autoreload 2
%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = [14, 9]
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import load_iris
data = load_iris()
X, y = data.data, data.target
names = data.feature_names
est = LogisticRegression(solver='lbfgs', multi_class='auto')
est.fit(X, y)
from sklearn.ensemble import RandomForestClassifier
dtree = RandomForestClassifier(n_estimators=100)
dtree.fit(X, y)
from sklearn_plot_api import plot_partial_dependence
features = [0, 1, 2, 3]
viz = plot_partial_dependence(est, X, features, feature_names=[names[i] for i in features])
from sklearn_plot_api import plot_partial_dependence
features = [0, 1, 2, 3]
viz = plot_partial_dependence(dtree, X, features, feature_names=[names[i] for i in features])
viz.artists_['sepal width (cm)'].set_color('green')
viz.figure_
viz.axes_['petal length (cm)'].set_ylabel('Parital dependence')
viz.figure_
from sklearn_plot_api import plot_partial_dependence
fig, (ax1, ax2) = plt.subplots(1, 2)
features = [0, 1, 2, 3]
viz1 = plot_partial_dependence(est, X, features, feature_names=[names[i] for i in features], ax=ax1)
viz2 = plot_partial_dependence(dtree, X, features, feature_names=[names[i] for i in features], ax=ax2)