In [ ]:


In [2]:
import numpy as np
import scipy as sp
import pandas as pd
import statsmodels.api as sm
import statsmodels.formula.api as smf
import sklearn as sk
import matplotlib as mpl
import matplotlib.pylab as plt
from mpl_toolkits.mplot3d import Axes3D
import seaborn as sns
sns.set()
sns.set_color_codes()

%matplotlib inline
%config InlineBackend.figure_format='png'

In [3]:
from sklearn.metrics import confusion_matrix

In [5]:
y_true =    [2, 0, 2, 2, 0, 1]
y_predict = [2, 1, 2, 2, 2, 2]
confusion_matrix(y_true, y_predict)


Out[5]:
array([[0, 1, 1],
       [0, 0, 1],
       [0, 0, 3]])

In [6]:
y_true = ["cat", "ant", "cat", "cat", "ant", "bird"]
y_pred = ["ant", "ant", "cat", "cat", "ant", "cat"]
confusion_matrix(y_true, y_pred, labels=["ant", "bird", "cat"])


Out[6]:
array([[2, 0, 0],
       [0, 0, 1],
       [1, 0, 2]])

In [8]:
from sklearn.metrics import classification_report

In [11]:
y_true = [0, 1, 2, 2, 2]
y_pred = [0, 0, 2, 2, 1]
target_name = ["class 0", "class 1", "class 2"]
print(confusion_matrix(y_true, y_pred))
print(classification_report(y_true, y_pred, target_names = target_name))


[[1 0 0]
 [1 0 0]
 [0 1 2]]
             precision    recall  f1-score   support

    class 0       0.50      1.00      0.67         1
    class 1       0.00      0.00      0.00         1
    class 2       1.00      0.67      0.80         3

avg / total       0.70      0.60      0.61         5


In [34]:
from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
X, y = make_classification(n_features=1, n_redundant=0, n_informative = 1, n_clusters_per_class = 1, random_state=4)
model = LogisticRegression().fit(X,y)

In [37]:
print(confusion_matrix(y,model.predict(X)))


[[47  2]
 [ 3 48]]

In [38]:
print(classification_report(y,model.predict(X)))


             precision    recall  f1-score   support

          0       0.94      0.96      0.95        49
          1       0.96      0.94      0.95        51

avg / total       0.95      0.95      0.95       100


In [41]:
from sklearn.metrics import roc_curve
fpr, tpr, thresholds = roc_curve(y, model.decision_function(X))

In [42]:
plt.plot(fpr, tpr)


Out[42]:
[<matplotlib.lines.Line2D at 0x7f41c2e24eb8>]

In [43]:
model.decision_function?

In [ ]: