ModuleNotFoundError: No module named ‘sklearn.cross_validation‘

目录

问题描述

问题原理

问题解决


问题描述

ModuleNotFoundError: No module named 'sklearn.cross_validation'

我的代码

# Split data into training and testing sets
from sklearn.metrics import accuracy_score, fbeta_score, roc_curve, auc, roc_auc_score
from sklearn.cross_validation import train_test_split


X_train_ADA, X_test_ADA, y_train_ADA, y_test_ADA = train_test_split(features_ADA, popular_label, test_size = 0.1, random_state = 0)

X_train_LR, X_test_LR, y_train_LR, y_test_LR = train_test_split(features_LR, popular_label, test_size = 0.1, random_state = 0)

X_train_RF, X_test_RF, y_train_RF, y_test_RF = train_test_split(features_RF, popular_label, test_size = 0.1, random_state = 0)

print("Training set has {} samples.".format(X_train_ADA.shape[0]))
print("Testing set has {} samples.".format(X_test_ADA.shape[0]))

问题原理

因为当版本升级后,函数的用法或者属性有所改变。

新版本的sklearn没有这个模块,所以需要用另一个模块代替。

问题解决

将代码

from sklearn.cross_validation import train_test_split

改为

from sklearn.model_selection import train_test_split

ModuleNotFoundError: No module named ‘sklearn.cross_validation‘_第1张图片

 引用:

ModuleNotFoundError: No module named ‘sklearn.cross_validation‘ - 知乎问题描述ModuleNotFoundError: No module named 'sklearn.cross_validation' 我的代码 # Split data into training and testing sets from sklearn.metrics import accuracy_score, fbeta_score, roc_curv…https://zhuanlan.zhihu.com/p/511132273

你可能感兴趣的:(#,Python各种问题报错,python,sklearn)