S.Shiro
S.Shiro

Reputation: 167

sklearn.model_selection module not found

I am trying linear regression from a data but when I try the following:

from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression

it gives me this error:

line 4, in <module>
    from sklearn.model_selection import train_test_split
KeyError: 32

sklearn, numpy and scipy are all installed but then also I am not able to use sklearn.model_selection and linear_model.

How can I solve this problem? I have already tried upgrading every module.

Upvotes: 1

Views: 356

Answers (1)

Ralf
Ralf

Reputation: 16505

What version of sklearn are you using?

In versions 0.19 and prior, the function train_test_split() was located in sklearn.cross_validation. To use it:

from sklearn.cross_validation import train_test_split

From version 0.20 onwards it can be found in sklearn.model_selection To use it:

from sklearn.model_selection import train_test_split

Does that help?

Upvotes: 3

Related Questions