1

Why doesn't this work in python?

 x = [] y = [] for ii in range(0,100): x.append(ii) y.append(ii) clf = LinearRegression() clf.fit(x, y) clf.predict(101) 

I get the error "tuple index out of range"

1
  • 1
    X should be 2-dimensional array, not 1-dimensional. Commented Dec 31, 2014 at 16:02

1 Answer 1

3

Make a list for each row so that in the end you have a 2D structure [[0], [1], [2], ...]:

x = [] y = [] for ii in range(0,100): x.append([ii]) <----- y.append(ii) clf = LinearRegression() clf.fit(x, y) clf.predict(101) 

Output:

array([ 101.])

Sign up to request clarification or add additional context in comments.

Comments