AttributeError: 模块“sklearn”没有属性“model_selection”

hkw*_*wei 6 python scikit-learn

当我想用来sklearn.model_selection.train_test_split拆分训练集和测试集时,它会引发如下错误:

AttributeError: module 'sklearn' has no attribute 'model_selection'
Run Code Online (Sandbox Code Playgroud)

我的代码如下:

import pandas as pd
import sklearn
data = pd.read_csv('SpeedVideoDataforModeling.csv',header=0,)
data_x = data.iloc[:,1:4]
data_y = data.iloc[:,4:]
x_train , x_test, y_train, y_test = 
sklearn.model_selection.train_test_split(data_x,data_y,test_size = 0.2)
Run Code Online (Sandbox Code Playgroud)

在 Pycharm 中,scikit-learn 包版本为 0.19.1。 在此处输入图片描述 感谢您的帮助!

blu*_*ote 9

你需要

import sklearn.model_selection
Run Code Online (Sandbox Code Playgroud)

在调用你的函数之前