def dafu_prediction(line): line = text_classifier.process_line(line) leibie = text_classifier.predict(line)[0] line_xl = text_classifier.features([line]).todense() # print(line_xl) # print(leibie) pipei_xl = jibing_xl_dict.get(leibie, 0) #输出对应的诊断 nearest = ComputerNearestNeighbor(line_xl, pipei_xl)[0][1] yuanshujv_dict = { 'diagnosis': df_zhenduan_list, 'treatment': df_zhiliao_list, 'symptom': df_zhengzhuang_list, 'pathogeny': df_bingyin_list } pipei_shujv = yuanshujv_dict.get(leibie, 0) recommenddation = pipei_shujv.loc[nearest, 'dafu1'] # print(recommenddation) return leibie, recommenddation
zhiliao_xl = text_classifier.features(zhiliao_list).todense() zhengzhuang_xl = text_classifier.features(zhengzhuang_list).todense() zhenduan_xl = text_classifier.features(zhenduan_list).todense() jibing_xl_dict = { 'diagnosis': zhenduan_xl, 'treatment': zhiliao_xl, 'symptom': zhengzhuang_xl, 'pathogeny': bingyin_xl } # print(zhenduan_xl) #输出预测类别 line = input('请输入:') line = text_classifier.process_line(line) leibie = text_classifier.predict(line)[0] line_xl = text_classifier.features([line]).todense() # print(line_xl) print(leibie) pipei_xl = jibing_xl_dict.get(leibie, 0) #输出对应的诊断 nearest = ComputerNearestNeighbor(line_xl, pipei_xl)[0][1] yuanshujv_dict = { 'diagnosis': df_zhenduan_list, 'treatment': df_zhiliao_list, 'symptom': df_zhengzhuang_list, 'pathogeny': df_bingyin_list } pipei_shujv = yuanshujv_dict.get(leibie, 0) recommenddation = pipei_shujv.loc[nearest, 'dafu1'] print(recommenddation)