0

I am trying to fit data to my model,

This is the data

le = sklearn.preprocessing.LabelEncoder()
date = le.fit_transform(list(data["Date"]))
_open = le.fit_transform(list(data["Open"]))
high = le.fit_transform(list(data["High"]))
low = le.fit_transform(list(data["Low"]))
adj_close = le.fit_transform(list(data["Adj Close"]))
volume = le.fit_transform(list(data["Volume"]))

X = list(date)
y = list(zip(high, low, _open, adj_close, volume))

x_train, x_test, y_train, y_test = sklearn.model_selection.train_test_split(X, y, test_size=0.1)

But when I try to fit the data into the model as displayed below

linear = sklearn.linear_model.LinearRegression()
linear.fit(x_train, y_train)

I get this error

ValueError: Expected 2D array, got 1D array instead:
array=[2088  311 1839 ... 2422   64 1705].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or 
array.reshape(1, -1) if it contains a single sample.

Thanks

1
  • Logs literally tell you what to do. Commented May 6, 2021 at 8:34

1 Answer 1

1

Try this

x_train= x_train.reshape(-1, 1)
x_test = x_test.reshape(-1, 1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.