当我想用来sklearn.model_selection.train_test_split拆分训练集和测试集时,它会引发如下错误:AttributeError: module 'sklearn' has no attribute 'model_selection'我的代码如下:import pandas as pdimport sklearndata = 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)在 Pycharm 中,scikit-learn 包版本为 0.19.1。 在此处输入图片描述 感谢您的帮助!
2 回答
噜噜哒
TA贡献1784条经验 获得超7个赞
您可以像from sklearn.model_selection import train_test_split. 官方文档中的一个例子:)
>>> import numpy as np
>>> from sklearn.model_selection import train_test_split
>>> X, y = np.arange(10).reshape((5, 2)), range(5)
>>> X
array([[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9]])
>>> list(y)
[0, 1, 2, 3, 4]
>>> X_train, X_test, y_train, y_test = train_test_split(
... X, y, test_size=0.33, random_state=42)
...
>>> X_train
array([[4, 5],
[0, 1],
[6, 7]])
>>> y_train
[2, 0, 3]
>>> X_test
array([[2, 3],
[8, 9]])
>>> y_test
[1, 4]
添加回答
举报
0/150
提交
取消