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に保存され、それがとして印刷することができます。predict_proba(np.array(test))のTypeError
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)。 これについてはどうすればいいですか?
今後、再生可能なコードを追加してください。 –