I'm trying to build a simple regression line with pandas in spyder. After executing the following code, I got this error:
Found input variables with inconsistent numbers of samples: [1, 99]
the code:
import numpy as np
import pandas as pd
dataset = pd.read_csv('Phil.csv')
x = dataset.iloc[:, 0].values
y = dataset.iloc[:, 2].values
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(x, y)
I think I know what is the problem, but I'm not quite sure how to deal with the syntax. In the variable explorer, the size of x (and y) is (99L,), and from what I remember it can't be a vector, and it must be size (99,1). same thing for y.
Saw a bunch of related topics, but none of them helped.
y
can just be(99,)
(need not be of shape(99,1)
), but X must be a 2-d shape. Tryx = x.reshape(-1,1)
before fitting. – Exodontist