I need help creating a confusion matrix from my model. Ive seen multiple sources use yhat or y_prediction, I thought weight was that. But nothing i do is working and Ive tried several things. My model doesnt use scikit-learn but im open to using it for the confusion matirx.
x_train, x_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 55)
x_train
x_train = x_train.T
x_test = x_test.T
y_train = y_train.T
y_test = y_test.T
def sigmoid(x):
return 1/(1+np.exp(-x))
def model(X, Y, learningRate, iterations):
m= x_train.shape[1]
n = x_train.shape[0]
weight = np.zeros((n,1)) # initialize weights with zeros
bias = 0.0
costlist = []
for i in range(iterations):
z = np.dot(weight.T, X) + bias #dot is vector multiplication & .T tranpose data
activation = sigmoid(z)
#cost function (propagate)
cost = -(1/m)*np.sum(Y*np.log(activation) + (1-Y)*np.log(1-activation))
#gradient (backward propagate)
dw = (1/m)*np.dot(activation-Y, X.T)
db = (1/m)*np.sum(activation - Y)
weigt = weight - learningRate*dw.T
bias = bias - learningRate*db
costlist.append(cost)
if (i%(iterations/10)==0):
#if i % 100 == 0:
print("cost after", i, "iterations is:", cost)
return weight, bias, costlist
def accuracy(X, Y, weight, bias):
z = np.dot(weight.T, X) + bias
activation = sigmoid(z)
activation = activation > 0.5
activation = np.array(activation, dtype = 'int64')
accuracy = (1 - np.sum(np.absolute(activation - Y))/Y.shape[1])*100
```