RobH
RobH

Reputation: 41

Python3 Sklearn Prediction Error Value Error

I have written a program to try and predict if a match will be won or lost against two other players based off of a dataset of wins and loses, but when I execute the code I get an error saying,

classifier = classifier.fit(features,labels)
ValueError: setting an array element with a sequence,".

My code:

#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]]
]))

What can I do to fix this???

Upvotes: 1

Views: 1721

Answers (1)

AndreyF
AndreyF

Reputation: 1838

The problem is that you use a sequence as a single feature. Currently your data has two feature for each row ([1,[8,4]]). The first is an integer (1) and the second is a sequence with two integers ([8,4]). I'm not sure what each feature represents however all features should be numeric.

A simple fix could be turning the sequence into two features:

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]))

The output of this code is:

[1]

Upvotes: 1

Related Questions