+ 1
Data Science - Binary Disorder Confusion matrix of binary classification. For binary classifications, a confusion matrix is a
I didnt get i have tried it like this y_true = [int(x) for x in input().split()] y_pred = [int(x) for x in input().split()] from sklearn.metrics import confusion_matrix from numpy as np y_pred = np.array(y_pred).reshape(-1 , 1) print(confusion_matrix(y_true, y_pred))
6 Answers
+ 14
y_true = [int(x) for x in input().split()]
y_pred = [int(x) for x in input().split()]
import numpy as np
y_true = np.array(y_true)
y_pred= np.array(y_pred)
tp=sum(y_true & y_pred)
fp=sum(~y_true & y_pred)
fn=sum(y_true & ~y_pred)
tn=len(y_true)-tp-fp-fn
print(np.array([[tp,fp],[fn,tn]],dtype='f'))
+ 8
import numpy as np
from sklearn.metrics import confusion_matrix
y_true = [int(x) for x in input().split()]
y_pred = [int(x) for x in input().split()]
# numpy array
y_true = np.array(y_true)
y_pred = np.array(y_pred)
confusion = confusion_matrix(y_pred, y_true, labels=[1, 0])
print(np.array(confusion, dtype="f"))
+ 3
import numpy as np
from sklearn.metrics import confusion_matrix
y_true = [int(x) for x in input().split()]
y_pred = [int(x) for x in input().split()]
X = []
TL = float(0)
TR = float(0)
BL = float(0)
BR = float(0)
for x, y in zip(y_true, y_pred):
if x == 1:
if y == 1:
TL += 1
else:
BL += 1
elif x == 0:
if y == 1:
TR += 1
else:
BR += 1
X.append(TL)
X.append(TR)
X.append(BL)
X.append(BR)
Y = np.array(X)
Y = Y.reshape(2, 2)
print(Y)
I've tried this. And it works for all the cases..
0
import numpy as np
from sklearn.metrics import confusion_matrix
y_true = [int(x) for x in input().split()]
y_pred = [int(x) for x in input().split()]
X = []
TL = float(0)
TR = float(0)
BL = float(0)
BR = float(0)
for x, y in zip(y_true, y_pred):
if x == 1:
if y == 1:
TL += 1
else:
BL += 1
elif x == 0:
if y == 1:
TR += 1
else:
BR += 1
X.append(TL)
X.append(TR)
X.append(BL)
X.append(BR)
Y = np.array(X)
Y = Y.reshape(2, 2)
print(Y)
0
TEWODROS WUBETE DESTA what is purpose of confusion_matrix here?
0
import numpy as np
y_true = [int(x) for x in input().split()]
y_pred = [int(x) for x in input().split()]
conf = list(zip(y_true, y_pred))
def confTuple(tupl, tr,pr):
res = len([t[0] for t in tupl if t[0] == tr and t[1]==pr])
return res
tp = confTuple(conf, 1,1)
fp = confTuple(conf, 0,1)
fn = confTuple(conf, 1,0)
tn = confTuple(conf, 0,0)
print(np.array([[tp,fp],[fn, tn]])/1)