gpt4 book ai didi

python - 属性错误: module 'sklearn' has no attribute 'model_selection'

转载 作者:行者123 更新时间:2023-12-01 01:21:52 25 4
gpt4 key购买 nike

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

AttributeError: module 'sklearn' has no attribute 'model_selection'

我的代码如下:

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)

在Pycharm中,scikit-learn包版本是0.19.1。

enter image description here

感谢您的帮助!

最佳答案

你需要

import sklearn.model_selection

在调用函数之前

关于python - 属性错误: module 'sklearn' has no attribute 'model_selection' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53742441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com