在R中,运行"随机森林"模型后,我可以save.image("***.RData")
用来存储模型.之后,我可以加载模型直接进行预测.
你能在python中做类似的事吗?我将模型和预测分成两个文件.在模型文件中:
rf= RandomForestRegressor(n_estimators=250, max_features=9,compute_importances=True) fit= rf.fit(Predx, Predy)
我试图返回rf
或fit
,但仍然无法在预测文件中加载模型.
您可以使用sklearn随机森林包分离模型和预测吗?
... import cPickle rf = RandomForestRegresor() rf.fit(X, y) with open('path/to/file', 'wb') as f: cPickle.dump(rf, f) # in your prediction file with open('path/to/file', 'rb') as f: rf = cPickle.load(f) preds = rf.predict(new_X)