错误:Python Range对象不可调用

时间:2018-05-04 16:33:56

标签: python python-3.x

我在Python 3.6中有下面的代码。关于为什么我得到以下错误的任何想法:

TypeError: 'range' object is not callable.

我正在使用该范围来构建NMF协作过滤器图。任何帮助深表感谢。错误发生在以下声明中。

sdrange = range(2,50,2)

完整代码 -

    import numpy as np
    import pandas as pd
    from surprise.prediction_algorithms.matrix_factorization import NMF
    from surprise.model_selection.validation import cross_validate
    from surprise import Dataset
    from surprise import Reader

    #read file
    rankings = pd.read_csv('ratings.csv')     

    dataframe = pd.DataFrame({'itemID': list(rankings.movieId), 'userID': 
    list(rankings.userId), 'rating': list(rankings.rating)})
    moviescales = Reader(rating_scale=(0.5, 5.0))
    mydataset = Dataset.load_from_df(dataframe[['userID', 'itemID', 
    'rating']], moviescales)

    sdrange = range(2,50,2)
    rmse, mae = [], []

    for k in sdrange:
       nmf = NMF()
       results = cross_validate(nmf, mydataset, measures=['RMSE', 'MAE'], 
       cv=10, verbose=False)
       rmse.append(np.mean(results['test_rmse']))
       mae.append(np.mean(results['test_mae']))

0 个答案:

没有答案