我已经编写了一个程序来尝试预测是否会根据胜负数据集对其他两名玩家赢得或输掉一场比赛,但是当我执行代码时,我得到一个错误说,
classifier = classifier.fit(features,labels)
ValueError: setting an array element with a sequence,".
我的代码:
#code to predict if game will be won in rocket league...
#Recipe Collect Data->Train Classifier-Predict
from sklearn import tree
#Contains Team Ranks and Enemy Ranks
'''
1: Rookie
2: Semipro
3:Pro
4:Veteran
5:Expert
6:Master
7:Legend
8:Rocketeer
'''
#First Array Set is Team Second Enemy
#Doubles Stats
features = [
[1,[8,4]],
[3,[5,5]],
[3,[4,4]]
]
#games won/lost
# 0 for lose 1 for win
labels = [0,0,1]
classifier = tree.DecisionTreeClassifier()
#Learning Algorithm finds paterns
classifier = classifier.fit(features,labels)
print(classifier.predict([
[[2],[4,3]]
]))
我该怎么做才能解决这个问题?
答案 0 :(得分:0)
问题是您使用序列作为单个功能。
目前,您的数据每行有两个功能([1,[8,4]]
)。第一个是整数(1
),第二个是具有两个整数([8,4]
)的序列。
我不确定每个功能代表什么,但所有功能都应该是数字。
一个简单的修复方法可能是将序列转换为两个特征:
features = [
[1,8,4],
[3,5,5],
[3,4,4]
]
#games won/lost
# 0 for lose 1 for win
labels = [0,0,1]
classifier = tree.DecisionTreeClassifier()
#Learning Algorithm finds paterns
classifier = classifier.fit(features,labels)
print(classifier.predict([2,4,3]))
此代码的输出为:
[1]