model = LogisticRegression()
model = model.fit(X, y)
test_data = [1,2,3,4,5,6,7,8,9,10,11,12,13]
test_prediction = model.predict_proba(np.array(test_data))
max = -1.0
res = 0
for i in range(test_prediction):
if test_prediction[i]>max:
max = test_prediction[i]
res = i
if res==0:
print('A')
elif res==1:
print('B')
else:
print('C')
使用上面的python代码,我必须预测3个可能的结果(A,B,C)的概率。 的概率保存在test_prediction,它可以打印为:TypeError for predict_proba(np.array(test))
Output: [[ 0.82882588 0.08641236 0.08476175]]
但剩下的部分给出了一个错误:
for i in range(test_prediction):
TypeError: only integer scalar arrays can be converted to a scalar index
我想找到的最大概率,然后显示作为事件可能发生的最多(A/B/C)。 如何解决这个问题?
将来请添加一些可重现的代码。 –