0

I am trying to input data into a random-forest classifier, but it keeps telling me I'm using a sequence. I'm not sure how to convert the sequence into anything that is acceptable

I have tried feeding it into the classifier inside a list(), but that didn't work either.

this is an example of X_train[1]:

array([30, array([[0, 0, 1]]), 5.2304265, 7.233890799999999,
       array([[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]),
       array([[0, 1, 0, 0, 0, 0, 0]]), array([[0, 0, 0, 0, 1]]), 0, 0, 0,
       2, 10000.0, 13000.0, 30, 1], dtype=object)

.

clf = RandomForestClassifier(n_estimators=100, max_depth=2, random_state=0)
clf.fit(X_train, y_train)

...produces... ValueError: setting an array element with a sequence.

I expected it to accept the data, since it it is numerical, but it appears to reject the data

Muaaz Kasker
  • 87
  • 2
  • 9
  • Possible duplicate of [ValueError: setting an array element with a sequence. while using SVM in scikit-learn](https://stackoverflow.com/questions/25485503/valueerror-setting-an-array-element-with-a-sequence-while-using-svm-in-scikit) – Heath Raftery Jun 19 '19 at 21:43
  • Googling your error along with "RandomForestClassifier" or "scikit-learn" gives the answer. – Heath Raftery Jun 19 '19 at 21:45
  • Your data is a mix of numbers and arrays. And the arrays vary in shape. An array is a sequence. – hpaulj Jun 19 '19 at 22:25

1 Answers1

1

Have a look at the documentation for the fit() method from sci-kit learn.

It clearly states that the training features X must be of the following format

X : array-like or sparse matrix of shape = [n_samples, n_features]

It is expecting a 2D array. You will have to modify your training data to match the required format.

skillsmuggler
  • 1,862
  • 1
  • 11
  • 16