【发布时间】:2020-11-09 17:55:08
【问题描述】:
我的代码在 google colab 上可用
我制作了一种算法,使用决策树进行多概率预测
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X1, Y1
, test_size=0.4,
random_state=1)
model = tree.DecisionTreeClassifier(criterion='entropy')
# Train the model using the training sets and check score
model.fit(X_train,y_train)
score= model.score(X1, Y1)
print('Score:- \n',score)
multi2 = model.predict_proba(X_test)
我收到了
[array([[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.]]),
array([[1., 0.],
[1., 0.],
[1., 0.],
[0., 1.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[0., 1.],
[1., 0.]])]
在尝试解码时遇到此问题
vnc = OneHotEncoder(handle_unknown='ignore')
vnc.fit(Y1)
vnc.inverse_transform(multi2)
ValueError: could not broadcast input array from shape (38,1) into shape (38)
我的输出应该是:
[[decode_value1,decode_value2,decode_value3,decode_value4]]
【问题讨论】:
标签: python-3.x machine-learning scikit-learn decision-tree