from sklearn import cross_validation as cv
train_data, test_data = cv.train_test_split(df, test_size=0.25)
#Create two user-item matrices, one for training and another for testing
train_data_matrix = np.zeros((n_users, n_items))
for line in train_data:
train_data_matrix[line[0]-1, line[1]-1] = line[2]
我收到错误:
File ".....", line 26, in <module>
train_data_matrix[line[0]-1, line[1]-1] = line[2]
TypeError: unsupported operand type(s) for -: 'str' and 'int'
有谁知道为什么?
答案 0 :(得分:1)
这是因为您的df
是train_data_matrix
的子集,其中包含字符列。你不能从一个字符中减去一个数字。您可能希望在循环中使用train_data
。在for循环中,您使用的是train_data_matrix
而不是index_booking
。