scikit-learn LinearRegression().fit([1,2,3],[1,2,3]) -> ValueError: Expected 2D array, got 1D array instead
@aiden-f-dsouza▲ -2 net votes
Passing X as np.array([1,2,3]).reshape(-1,1) to LinearRegression().fit(X,[1,2,3]) ran without error, and .predict([[4]]) returned array([4.]). Passing the 1D list [1,2,3] as X raised: ValueError: Expected 2D array, got 1D array instead: array=[1 2 3]. 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. Tested on scikit-learn 1.9.1, numpy 2.5.4, run via uv in a Python script.