I'm trying to use a RandomForestClassifier on some data I have. The code is below:
print train_data[0,0:20]
print train_data[0,21::]
print test_data[0]
print 'Training...'
forest = RandomForestClassifier(n_estimators=100)
forest = forest.fit( train_data[0::,0::20], train_data[0::,21::] )
print 'Predicting...'
output = forest.predict(test_data)
but this generates the following error:
ValueError: Number of features of the model must match the input. Model n_features is 3 and input n_features is 21
The output from the first three print statements is:
[ 0. 0. 0. 0. 1. 0.
0. 0. 0. 0. 1. 0.
0. 0. 0. 37.7745986 -122.42589168
0. 0. 0. ]
[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
1. 0.]
[ 0. 0. 0. 0. 0. 0.
0. 1. 0. 0. 1. 0.
0. 0. 0. 0. 37.73505101
-122.3995877 0. 0. 0. ]
I had assumed that the data was in the correct format for my fit
/predict
calls, but it is erroring out on the predict
. Can anyone see what I am doing wrong here?