Hi, Sasha,
So based on your Y array, it seems that you have 6 training samples. Now, in 
scikit-learn, each sample is represented as a row in the X array (and the 
columns are the “features” — you have 1 feature here, right?).

Now, if you do 
> X = X.reshape(-1, 1)
> X.shape
your array will have the shape (1, 5), but what you want is (5, 1). Thus, the 
solution is to do

> X = X.reshape(-1, 1)

The complete code would be then

import numpy as np
X = np.array([10, 20, 30, 60, 108])
y = np.array([11, 23, 43, 170.5, 934.6])
X = X.reshape(-1, 1)
model.fit(X, y)

There’s also a problem in your predict call since you only have 6 samples, you 
can’t have a “12” in there, only values from 0, 5. E.g., 

print("Predict for number 6 {}".format(model.predict([5])))
Predict for number 6 [-146.58922645]

Best,
Sebastian

> On Feb 6, 2016, at 11:52 AM, Sasha Kacanski <skacan...@gmail.com> wrote:
> 
> X = np.array([10, 20, 30, 60, 108])
> Y = np.array([11, 23, 43, 170.5, 934.6])
> model = LinearRegression()
> x = X.reshape(-1,1)
> model.fit(x,y)
> print("Predict for number 12 {}".format(model.predict([12])[0]))
> 


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
Scikit-learn-general mailing list
Scikit-learn-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

Reply via email to