从sklearn导入train_test_split时发生scipy library错误

2024-04-24 05:30:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在应用implementing recommendation system的教程,从导入时遇到了一个问题sklearn.selection_模型为进行列车/试验分段,进行列车/试验分段。在

import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split

#create columns name
header = ['user_id', 'item_id', 'rating', 'timestamp']
#read data containing the full dataset of ratings
df = pd.read_csv('ml-100k/u.data', sep='\t', names=header)

n_users = df.user_id.unique().shape[0]
n_items = df.item_id.unique().shape[0]

print 'Number of users = ' + str(n_users) + ' | Number of movies = ' + str(n_items)
#train_data, test_data = train_test_split(df,test_size=0.25)

#print 'train shape = ' + str(train_data.shape)

日志错误:

Traceback (most recent call last): File "C:/Users/PycharmProjects/recommendation_system_trials/engine.py", line 3, in from sklearn.model_selection import train_test_split File "C:\Users\hello2\lib\site-packages\sklearn__init__.py", line 57, in from .base import clone File "C:\Users\hello2\lib\site-packages\sklearn\base.py", line 10, in from scipy import sparse ImportError: No module named scipy

为什么我得到这个错误,我没有使用scipy,我只是想导入train_test_split。在

谢谢你的帮助。在


Tags: offromtestimportiddfdatatrain