8000 Vague Error Message for Linear Regression when X is 1D · Issue #4466 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

Vague Error Message for Linear Regression when X is 1D #4466

@ahwillia

Description

@ahwillia

I was recently trying to do just a very simple linear regression on x vs. y -- I got this error message:

IndexError: tuple index out of range

I wasted 3 minutes trying to figure out if my x and y vectors didn't have the same lengths (they did), whether the problem was that they were lists, not numpy arrays (they were). Then I found the culprit, through stackoverflow:

http://stackoverflow.com/questions/27107057/sklearn-linear-regression-python

The trick is to replace:

regr.fit(x,y)

With:

regr.fit(x[:,np.newaxis],y)

I know this is only a small inconvenience for me, but I think this needs to be addressed for the sake of usability. This provides an unnecessarily difficult entry barrier to new users.

A related thought/comment: Do the inputs have to be numpy arrays? Why not try to salvage the input if the user passes lists?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0