I am new to modeling, and I am practicing building a logistic regression model. I would like to create a confusion matrix, but my code doesn't seem to work.
Here is the code for the model (which works):
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
#train, test = train_test_split(hp[age], test_size=0.3)
#from sklearn import preprocessing
X = hp['age'].values.reshape((32561,1))
#X = hp[['age','hours-per-week']].values
y = hp['evalinvest'].values
LogReg = LogisticRegression()
LogReg.fit(X,y)
print(LogReg.score(X,y))
0.916710174749
Here is where I am having diffculty:
# Confusion Matrix
import numpy as np
from sklearn.metrics import *
CM = confusion_matrix(X,y)
print ("\n\nConfusion matrix:\n", CM)
It runs and outputs results, but I don't feel like it is correct.
Confusion matrix:
[[ 0 0 0 ..., 0 0 0]
[ 0 0 0 ..., 0 0 0]
[385 10 0 ..., 0 0 0]
...,
[ 1 0 0 ..., 0 0 0]
[ 3 0 0 ..., 0 0 0]
[ 33 10 0 ..., 0 0 0]]
Then, when I run the following code, it doesn't work:
tn, fp, fn, tp = CM.ravel()
print ("\nTP, TN, FP, FN:", tp, ",", tn, ",", fp, ",", fn)
error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-68-dca3ebbdc69a> in <module>()
----> 1 tn, fp, fn, tp = CM.ravel()
2 print ("\nTP, TN, FP, FN:", tp, ",", tn, ",", fp, ",", fn)
ValueError: too many values to unpack (expected 4)