The problem with slicing is when the index column is not the first one. Would 
there be a way to do it with slicing.

I’m also not sure about the first method. The inputs of reshape should be 
vector, new shape and order. What does the line below do?

Thank yuou,


From: Artem [mailto:barmaley....@gmail.com]
Sent: Wednesday, February 11, 2015 1:39 PM
To: scikit-learn-general@lists.sourceforge.net
Subject: Re: [Scikit-learn-general] regression with one independent variable

​fit expects 2-dimensional input, whereas X[:, 0] is one dimensional. You can 
either reshape it manually:

​regr.fit(x_train[:, 0].reshape((x_train.shape[0], 1)), x_train[:, 1])

or use slices to select continuous range of columns:

​regr.fit(x_train[:, :1], x_train[:, 1])

What exception tells you is that x_train is of wrong shape. If x_train was 
2-dimensional, it's shape would have a 2nd element (with index 1).

On Wed, Feb 11, 2015 at 9:26 PM, Pagliari, Roberto 
<rpagli...@appcomsci.com<mailto:rpagli...@appcomsci.com>> wrote:
I’m trying to make a linear regression with one independent variable and one or 
more dependent variables.

That does not seem to work. Is that a limitation of regression function?

regr.fit(x_train[:, 0], x_train[:, 1])

  File "/usr/local/lib/python2.7/dist-packages/sklearn/linear_model/base.py", 
line 355, in fit
    X, y, self.fit_intercept, self.normalize, self.copy_X)
  File "/usr/local/lib/python2.7/dist-packages/sklearn/linear_model/base.py", 
line 104, in center_data
    X_std = np.ones(X.shape[1])
IndexError: tuple index out of range

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Scikit-learn-general mailing list
Scikit-learn-general@lists.sourceforge.net<mailto:Scikit-learn-general@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Scikit-learn-general mailing list
Scikit-learn-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

Reply via email to