如何使用python保存多个SVM模型

我正在尝试通过使用for循环范围从列表中获取名称来保存多个模型以保存在路径中。

我的模型工作正常,但是尝试将每个名称保存为唯一名称时出错。

city_id = ['1', '2', '18', '19', '21', '23', '26', '27', '28', '32', '35', '36', '37', '38', '39', '40', '41',
       '42', '43', '44', '45', '46', '47', '49', '50', '51', '58', '65', '67', '68', '69', '70', '71']


for i in range(len(city_id)):

    joblib.dump(model, 'D:/Model/model_Predict_Locality_predictor_'+ str(city_id[i]) +'.pkl', compress=1)


但是得到out of range error我也有检查范围,但是两个范围都相同。

错误

1Model Pipeline Created Successfully...Data fitted Successfully...Data Predicted Successfully...Accuracy: 0.9908892595919415list index out of range2Model Pipeline Created Successfully...Data fitted Successfully...Data Predicted Successfully...Accuracy: 0.9790685504971219list index out of range

精度提高后,出现上述错误。

请建议

最佳答案

您已将i用作两个for循环的索引变量。更正该问题,然后尝试!

关于python - 如何使用python保存多个模型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53720860/

10-10 19:34