【问题标题】:ValueError: labels ['timestamp'] not contained in axisValueError:标签 ['timestamp'] 未包含在轴中
【发布时间】:2016-06-11 12:26:44
【问题描述】:

我正在学习机器学习,我遇到了这个code。 我正在尝试从上述源运行文件"Recommender-Systems.py"。但是会报错
ValueError: labels ['timestamp'] not contained in axis.
怎么去掉?

这是 linku.data 文件的保管箱。

【问题讨论】:

  • 您有u.data 文件吗?你能提供一个样本吗?
  • 我已经从here下载了数据集

标签: python machine-learning svm data-science


【解决方案1】:

您的数据缺少标题,因此被第一行错误地推断出来。

您需要稍微更改Recommender-Systems.py 并手动通知标头。

您的数据集中的README 文件中提供了正确的标题。

把你的文件改成这样:

## Explore the data (line 27)
data = pd.read_table('u.data', header=None)  # header=None avoid getting the columns automatically
data.columns = ['userID', 'itemID',
                'rating', 'timestamp']       # Manually set the columns.
data = data.drop('timestamp', axis=1)        # Continue with regular work.

...

## Load user information (line 75)
users_info = pd.read_table('u.user', sep='|', header=None)
users_info.columns = ['useID', 'age', 'gender',
                      'occupation' 'zipcode']
users_info = users_info.set_index('userID')

...

## Load movie information (line 88)
movies_info = pd.read_table('u.item', sep='|', header=None)
movies_info.columns = ['movieID', 'movie title', 'release date',
                       'video release date', 'IMDb URL', 'unknown',
                       'Action', 'Adventure', 'Animation', "Children's",
                       'Comedy', 'Crime', 'Documentary', 'Drama',
                       'Fantasy', 'Film-Noir', 'Horror', 'Musical',
                       'Mystery', 'Romance', 'Sci-Fi',' Thriller',
                       'War', 'Western']
movies_info = movies_info.set_index('movieID')#.drop(low_count_movies)


这应该可以工作(但我不确定我是否得到了所有正确的列名称)。

【讨论】:

    猜你喜欢
    • 2016-10-12
    • 2017-09-18
    • 2016-07-07
    • 2019-12-13
    • 2018-12-06
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 2019-07-25
    相关资源
    最近更新 更多