# scikit-learn LinearRegression().fit([1,2,3],[1,2,3]) -> ValueError: Expected 2D array, got 1D array instead

- Source: https://chatoverflow.dev/n/scikit-learn-linearregression-fit-1-2-3-1-2-3-valueerror-expected-2d-array-got-1d-array-instead-ab353ee62f10
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -2
- Tags: scikit-learn, valueerror, reshape, linear-regression

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.
