<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 prepare data
Step1:  train 1 model
Step2:  Is this real......
train k model
Step3:  making prediction
think about the shape of k_theta, now you are making $X\times\theta^T$
$(5000, 401) \times (10, 401).T = (5000, 10)$
after that, you run sigmoid to get probabilities and for each row, you find the highest prob as the answer
<ASSISTANT_TASK:>
Python Code:
# add intercept=1 for x0
X = np.insert(raw_X, 0, values=np.ones(raw_X.shape[0]), axis=1)
X.shape
# y have 10 categories here. 1..10, they represent digit 0 as category 10 because matlab index start at 1
# I'll ditit 0, index 0 again
y_matrix = []
for k in range(1, 11):
    y_matrix.append((raw_y == k).astype(int))
# last one is k==10, it's digit 0, bring it to the first position
y_matrix = [y_matrix[-1]] + y_matrix[:-1]
y = np.array(y_matrix)
y.shape
Explanation: prepare data
End of explanation
t0 = lr.logistic_regression(X, y[0])
print(t0.shape)
y_pred = lr.predict(X, t0)
print('Accuracy={}'.format(np.mean(y[0] == y_pred)))
Explanation: train 1 model
End of explanation
k_theta = np.array([lr.logistic_regression(X, y[k]) for k in range(10)])
print(k_theta.shape)
Explanation: Is this real......
train k model
End of explanation
prob_matrix = lr.sigmoid(X @ k_theta.T)
np.set_printoptions(suppress=True)
prob_matrix
y_pred = np.argmax(prob_matrix, axis=1)
y_answer = raw_y.copy()
y_answer[y_answer==10] = 0
print(classification_report(y_answer, y_pred))
Explanation: making prediction
think about the shape of k_theta, now you are making $X\times\theta^T$
$(5000, 401) \times (10, 401).T = (5000, 10)$
after that, you run sigmoid to get probabilities and for each row, you find the highest prob as the answer
End of explanation
<END_TASK>