I have a predictions probabilities for multiclasses [0, 1], and I need to save the correct prediction probability for each row in my data set:
probs = model.predict_proba(X_test)
idx_1 = np.where(y_test == 1)[0]
idx_0 = np.where(y_test == 0)[0]
probs includes pairs of values, the first value in each pair is the probability for class 0 and the second is the probability for class 1 (both summing up to 1).
The shape of probs differs cause am calling it during cross_validation, but let's take an example of one iteration: (568, 2) and for y_test: 568
I tried the following to save the correct probability for each labeled data:
probs_per_class = [probs[idx_1, 1][i] if i in idx_1 else probs[idx_0, 0][i] for i in range(len(y_test))]
but getting
out of bound
error
if I expand it to simulate verbus mode:
probs_per_class = []
for i in range(len(y_test)):
if i in idx_1:
probs_per_class.append(probs[idx_1, 1][i])
print(i, probs[idx_1, 1][i])
elif i in idx_0:
probs_per_class.append(probs[idx_0, 0][i])
print(i, probs[idx_0, 0][i])
failing on:
IndexError: index 194 is out of bounds for axis 0 with size 191
What is going wrong?