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)。 如何解決這個問題?
將來請添加一些可重現的代碼。 –