Reputation:
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"
Upvotes: 1
Views: 237
Reputation: 40993
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.])
Upvotes: 3