#!/usr/bin/env python # coding: utf-8 # In[1]: get_ipython().run_line_magic('load_ext', 'autoreload') get_ipython().run_line_magic('autoreload', '2') get_ipython().run_line_magic('matplotlib', 'inline') import numpy as np import pandas as pd import matplotlib.pyplot as plt # In[2]: plt.rcParams['figure.figsize'] = [14, 9] # In[20]: from sklearn.linear_model import LogisticRegression from sklearn.datasets import load_iris # In[24]: data = load_iris() X, y = data.data, data.target names = data.feature_names est = LogisticRegression(solver='lbfgs', multi_class='auto') est.fit(X, y) # In[30]: from sklearn.ensemble import RandomForestClassifier # In[33]: dtree = RandomForestClassifier(n_estimators=100) dtree.fit(X, y) # # First Plot # In[34]: 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]) # In[35]: 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]) # ## Adjust color of sepal width # In[37]: viz.artists_['sepal width (cm)'].set_color('green') viz.figure_ # ## Add y label to petal length # In[38]: viz.axes_['petal length (cm)'].set_ylabel('Parital dependence') viz.figure_ # ## Passing bounds through axes # In[41]: 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)