【发布时间】:2018-03-25 17:10:48
【问题描述】:
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 中,可以打印为:
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)。 这个怎么办?
【问题讨论】:
-
以后请添加一些可重现的代码。
标签: python python-3.x numpy scikit-learn typeerror