Scikit-Plot Repo

Examples from this link

pip install scikit-plot


In [1]:
%pylab inline
pylab.rcParams['figure.figsize'] = (14, 14)


Populating the interactive namespace from numpy and matplotlib

In [2]:
from sklearn.datasets import load_digits as load_data
from sklearn.naive_bayes import GaussianNB

In [3]:
# This is all that's needed for scikit-plot
import matplotlib.pyplot as plt
from scikitplot import classifier_factory

In [4]:
# Load data
X, y = load_data(return_X_y=True)

In [5]:
# Regular instance using GaussianNB class
nb = GaussianNB()

In [6]:
# Modification of instance of Scikit-Learn
classifier_factory(nb)


Out[6]:
GaussianNB(priors=None)

In [7]:
# An object of Scikit-Learn using the modified version that can use a method plot_roc_curve
nb.plot_roc_curve(X, y, random_state=1)


Out[7]:
<matplotlib.axes._subplots.AxesSubplot at 0x107a53110>

In [8]:
# Display plot
plt.show()

In [ ]:


In [9]:
from sklearn.ensemble import RandomForestClassifier

In [10]:
random_forest_clf = RandomForestClassifier(n_estimators=5, max_depth=5, random_state=1)

In [11]:
from scikitplot import classifier_factory

In [12]:
classifier_factory(random_forest_clf)


Out[12]:
RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
            max_depth=5, max_features='auto', max_leaf_nodes=None,
            min_impurity_split=1e-07, min_samples_leaf=1,
            min_samples_split=2, min_weight_fraction_leaf=0.0,
            n_estimators=5, n_jobs=1, oob_score=False, random_state=1,
            verbose=0, warm_start=False)

In [13]:
random_forest_clf.plot_confusion_matrix(X, y, normalize=True)


Out[13]:
<matplotlib.axes._subplots.AxesSubplot at 0x108798e90>

In [14]:
plt.show()

In [ ]:


In [15]:
from scikitplot import plotters as skplt

In [16]:
rf = RandomForestClassifier()

In [17]:
rf = rf.fit(X, y)

In [18]:
preds = rf.predict(X)

In [19]:
skplt.plot_confusion_matrix(y_true=y, y_pred=preds)
plt.show()



In [ ]:


In [ ]:


In [20]:
from __future__ import absolute_import
import matplotlib.pyplot as plt
from scikitplot import clustering_factory
from sklearn.cluster import KMeans
from sklearn.datasets import load_iris as load_data

In [21]:
X, y = load_data(return_X_y=True)

In [22]:
kmeans = clustering_factory(KMeans(random_state=1))

In [23]:
kmeans.plot_elbow_curve(X, cluster_ranges=range(1, 11))
plt.show()



In [ ]:


In [ ]:


In [24]:
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_iris as load_data
import matplotlib.pyplot as plt
from scikitplot import classifier_factory

In [25]:
X, y = load_data(return_X_y=True)

In [26]:
rf = classifier_factory(RandomForestClassifier(random_state=1))

In [27]:
rf.fit(X, y)


Out[27]:
RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
            max_depth=None, max_features='auto', max_leaf_nodes=None,
            min_impurity_split=1e-07, min_samples_leaf=1,
            min_samples_split=2, min_weight_fraction_leaf=0.0,
            n_estimators=10, n_jobs=1, oob_score=False, random_state=1,
            verbose=0, warm_start=False)

In [28]:
rf.plot_feature_importances(feature_names=['petal length', 'petal width',
                                           'sepal length', 'sepal width'])
plt.show()



In [ ]:


In [ ]:


In [29]:
from __future__ import absolute_import
import matplotlib.pyplot as plt
from scikitplot import classifier_factory
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import load_breast_cancer as load_data

In [30]:
X, y = load_data(return_X_y=True)

In [31]:
lr = classifier_factory(LogisticRegression())

In [32]:
lr.plot_ks_statistic(X, y, random_state=1)
plt.show()



In [ ]:


In [33]:
from scikitplot import plotters as skplt

In [34]:
lr = LogisticRegression()

In [35]:
lr = lr.fit(X, y)

In [36]:
probas = lr.predict_proba(X)

In [37]:
skplt.plot_ks_statistic(y_true=y, y_probas=probas)
plt.show()



In [ ]:


In [ ]:


In [38]:
from __future__ import absolute_import
import matplotlib.pyplot as plt
from scikitplot import classifier_factory
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_breast_cancer as load_data

In [39]:
X, y = load_data(return_X_y=True)

In [40]:
rf = classifier_factory(RandomForestClassifier())

In [41]:
rf.plot_learning_curve(X, y)
plt.show()



In [ ]:


In [42]:
from scikitplot import plotters as skplt

In [43]:
rf = RandomForestClassifier()

In [44]:
skplt.plot_learning_curve(rf, X, y)
plt.show()



In [ ]:


In [ ]:


In [45]:
from sklearn.decomposition import PCA
from sklearn.datasets import load_digits as load_data
import scikitplot.plotters as skplt
import matplotlib.pyplot as plt

In [46]:
X, y = load_data(return_X_y=True)

In [47]:
pca = PCA(random_state=1)

In [48]:
pca.fit(X)


Out[48]:
PCA(copy=True, iterated_power='auto', n_components=None, random_state=1,
  svd_solver='auto', tol=0.0, whiten=False)

In [49]:
skplt.plot_pca_2d_projection(pca, X, y)
plt.show()



In [ ]:


In [ ]:


In [50]:
from sklearn.decomposition import PCA
from sklearn.datasets import load_digits as load_data
import scikitplot.plotters as skplt
import matplotlib.pyplot as plt

In [51]:
X, y = load_data(return_X_y=True)

In [52]:
pca = PCA(random_state=1)

In [53]:
pca.fit(X)


Out[53]:
PCA(copy=True, iterated_power='auto', n_components=None, random_state=1,
  svd_solver='auto', tol=0.0, whiten=False)

In [54]:
skplt.plot_pca_component_variance(pca)
plt.show()



In [ ]:


In [ ]:


In [55]:
from __future__ import absolute_import
import matplotlib.pyplot as plt
from scikitplot import classifier_factory
from sklearn.naive_bayes import GaussianNB
from sklearn.datasets import load_digits as load_data

In [56]:
X, y = load_data(return_X_y=True)

In [57]:
nb = classifier_factory(GaussianNB())

In [58]:
nb.plot_precision_recall_curve(X, y, random_state=1)
plt.show()



In [ ]:


In [ ]:


In [59]:
from __future__ import absolute_import
import matplotlib.pyplot as plt
from scikitplot import classifier_factory
from sklearn.naive_bayes import GaussianNB
from sklearn.datasets import load_digits as load_data

In [60]:
X, y = load_data(return_X_y=True)

In [61]:
nb = classifier_factory(GaussianNB())

In [62]:
nb.plot_roc_curve(X, y, random_state=1)
plt.show()



In [ ]:


In [63]:
from scikitplot import plotters as skplt

In [64]:
nb = GaussianNB()

In [65]:
nb = nb.fit(X, y)

In [66]:
probas = nb.predict_proba(X)

In [67]:
skplt.plot_roc_curve(y_true=y, y_probas=probas)
plt.show()



In [ ]:


In [ ]:


In [ ]:


In [68]:
from __future__ import absolute_import
import matplotlib.pyplot as plt
from scikitplot import clustering_factory
from sklearn.cluster import KMeans
from sklearn.datasets import load_iris as load_data

In [69]:
X, y = load_data(return_X_y=True)

In [70]:
kmeans = clustering_factory(KMeans(n_clusters=4, random_state=1))

In [71]:
kmeans.plot_silhouette(X)
plt.show()



In [ ]:


In [ ]: