数据框如下:
repair = pd.DataFrame({'serialNo':['aaaa','aaaa','cccc','aaaa'],
'Dispatch_id':['AA20180915','BB20180916','CC20180915','DD20180919'],
'CONFIGURATION': ['face','head','stomach','legs'],
'CONFIGCODE': ['singing', 'dance','booze', 'vocals'],
'Salesorg': [4402, 3747 ,5555,8754],
'COMP-ISSue':[0,3462,5161,3262],
'PART_NO':['923-0439,923-0440,661-02392','J661-05640,J661-05639','KH661-05639,KH661-05640','REST-1625,IST-123']})
我已经使用标签编码对它们进行了编码,然后构建了一个推荐系统,该系统将建议进行以下类似的修复:
from sklearn.neighbors import NearestNeighbors
nbrs = NearestNeighbors(n_neighbors=4, algorithm='ball_tree').fit(repair_features)
distances, indices = nbrs.kneighbors(repair_features)
我想编写一个辅助函数来帮助我的建议,使它以dispatch_id
作为输入并打印与该调度类似的三项修复。
我已经启动了该功能,但是我不知道接下来要写什么或者它是否正确。有人可以帮忙吗?
def print_similar_animes(dispatch_id=None):
if disptach_id:
for disptach_id in indices[disptach_id][1:]:
print(repair.iloc[dispatch_id][CONFIGURATION"])
执行此操作时遇到的错误是:
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-14-3e5eee2f09a6> in <module>() ----> 1 print_similar_repairs('G331471759') <ipython-input-9-3aa2770c0544> in print_similar_repairs(disp_id) 1 def print_similar_repairs(disp_id=None): 2 if disp_id: ----> 3 for disp_id in indices[disp_id][1:]: 4 print(repair.ix[disp_id]["CONFIGURATION"]) IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices