【发布时间】:2017-10-19 00:23:31
【问题描述】:
我正在使用下面的代码来保存一个随机森林模型。我正在使用 cPickle 来保存经过训练的模型。当我看到新数据时,我可以增量训练模型吗? 目前,训练集有大约 2 年的数据。有没有办法再训练 2 年并将其(有点)附加到现有的保存模型中。
rf = RandomForestRegressor(n_estimators=100)
print ("Trying to fit the Random Forest model --> ")
if os.path.exists('rf.pkl'):
print ("Trained model already pickled -- >")
with open('rf.pkl', 'rb') as f:
rf = cPickle.load(f)
else:
df_x_train = x_train[col_feature]
rf.fit(df_x_train,y_train)
print ("Training for the model done ")
with open('rf.pkl', 'wb') as f:
cPickle.dump(rf, f)
df_x_test = x_test[col_feature]
pred = rf.predict(df_x_test)
编辑 1:我没有计算能力一次用 4 年的数据训练模型。
【问题讨论】:
标签: python pickle random-forest training-data