0

I have two numpy arrays

import numpy as np
temp_1 = np.array([['19.78018766'],
 ['19.72487359'],
 ['19.70280336'],
 ['19.69589641'],
 ['19.69746018']])
temp 2 = np.array([['43.8'],
 ['43.9'],
 ['44'],
 ['44.1'],
 ['44.2']])

and I am preparing X = np.stack((temp_1,temp_2), axis=-1) which looks something like this

 X = [[['19.78018766' '43.8']]
 [['19.72487359' '43.9']]
 [['19.70280336' '44']]
 [['19.69589641' '44.1']]
 [['19.69746018' '44.2']]]

I have another variable Y which is also a numpy array

Y = np.array([['28.78'],
 ['32.72'],
 ['15.70'],
 ['32.69'],
 ['55.69']])

I am trying to run the RandomforestRegressor model

where

from sklearn.ensemble import RandomForestRegressor
clf = RandomForestRegressor()
clf.fit(X,Y)

However, it is giving me this error

ValueError: Found array with dim 3. Estimator expected <= 2.
Miguel Trejo
6,7376 gold badges30 silver badges53 bronze badges
asked Dec 13, 2021 at 2:15

1 Answer 1

2

This happens because X and Y shapes are different (5, 1, 2) != (5,1).

Just reshape your X data to the number of samples you have

# In this example 5 samples
X = X.reshape(5, 2)
answered Dec 13, 2021 at 14:46
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.