java索引器,单位置索引器是越界索引错误

user_ratings_matrix = training_df.pivot(index='userId', columns='movieId', values='rating')

users = user_ratings_matrix.index.values

print('Creating corated data frame...')

with open('similarities/UsersCorated.csv', 'w') as result_file:

print('user1,user2,corated', file=result_file)

print('Calculating corated between users...')

for u1 in tqdm(users, total=len(users)):

for u2 in users:

movies_u1 = ~np.isnan(user_ratings_matrix.iloc[u1 - 1])

movies_u2 = ~np.isnan(user_ratings_matrix.iloc[u2 - 1])

same_movies = np.logical_and(movies_u1, movies_u2)

num_same_movies = list(same_movies).count(True)

print(f"{u1},{u2},{num_same_movies}", file=result_file)

错误

IndexError Traceback(最近一次调用last)in()1 ----> 2 Similarities_Functions.Corated_Matrix()3 Similarities_Functions.Corated_Similarity()4 5 print('finished !!!')〜/ Documents / PhD / IntelliSys19 / journal Corated_Matrix()中的/ColdStart_Experiment/Similarities_Functions.py 145用户中的u2:146 ratings1 = np.nan_to_num(np.array(user_ratings_matrix.iloc [u1 - 1] .values)) - > 147 ratings2 = np.nan_to_num(np .array(user_ratings_matrix.iloc [u2 - 1] .values))148 149 sim = pearsonr(ratings1,ratings2)〜/ anaconda3 / lib / python3.6 / site-packages / pandas / core / indexing.py in getitem(self ,键)1371 1372 maybe_callable = com._apply_if_callable(key,self.obj) - > 1373 return self._getitem_axis(maybe_callable,axis = axis)1374 1375 def _is_scalar_access(self,key):〜/ anaconda3 / lib / python3.6 _site-packages/pandas/core/indexing.py in _getitem_axis(self,key,axis)1828 1829#validate location - > 1830 self._is_valid_integer(key,axis)1831 1832 return self._get_loc(key,axis = axis )〜/ anaconda3 / lib / p _is_valid_integer中的ython3.6 / site-packages / pandas / core / indexing.py(self,key,axis)1711 l = len(ax)1712如果key> = l或key 1713引发IndexError(“单个位置索引器超出界限“)1714返回True 1715 IndexError:单个位置索引器超出范围

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值