I was trying to use an extra trees classifier on this dataset, and for some reason at the
model.fit(trainx,trainy)
part, it throws me a
ValueError: Unknown label type: array([[ 0.11],
[ 0.12],
[ 0.64],
[ 0.83],
[ 0.33],
[ 0.72],
[ 0.49],
error. The array([0.11] is my trainy data. I've searched stack overflow and apparently its due to sklearn not recognizing the data type, but ive tried everything from
trainy = np.asarray(trainy,dtype=float)
trainy=trainy.astype(float)
and it doesnt work, even though type(trainy) shows that its numpy.ndarray. Can anyone point me in the right direction here?
Here's the code:
import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder
from sklearn import metrics
from sklearn.ensemble import ExtraTreesClassifier
from sklearn import cross_validation
def preProcess():
df= pd.read_csv('C:/Users/X/Desktop/Managerial_and_Decision_Economics_2013_Video_Games_Dataset.csv',encoding ='ISO-8859-1')
#drop non EA
df = df[df['EA'] ==1]
#change categorical variables
le = LabelEncoder()
nonnumeric_columns=['Console','Title','Publisher','Genre']
for feature in nonnumeric_columns:
df[feature] = le.fit_transform(df[feature])
#set dataset and target variables
dataset =df.ix[:, df.columns != 'US Sales (millions)']
target = df['US Sales (millions)']
trainx, testx, trainy, testy = cross_validation.train_test_split(
dataset, target, test_size=0.3, random_state=0)
#attempt to fix error?
trainx=np.array(trainx)
trainy = np.asarray(trainy, dtype="float")
return trainx,testx,trainy,testy
def classifier():
model = ExtraTreesClassifier(n_estimators=250,
random_state=0)
model.fit(trainx,trainy)
return model.score(testx,testy)
trainx,testx,trainy,testy=preProcess()
I'm using scikit-learn 0.17 on python 3.5
Your labels [[0.11], [ 0.12],....
.
You should use ExtraTreesRegressor
instead of ExtraTreesClassifier
From source code of ForestClassifier
:
y : array-like, shape = [n_samples] or [n_samples, n_outputs]
The target values (class labels in classification, real numbers in
regression).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With