我有一个挑战,我正在做的是模拟我的服务器接收实时信息,这样我只能逐行进行预测。我使用随机森林回归-优化速度。在
问题不在于predict()函数,而是逐行调用它会产生大量开销。在
我能做些什么来提高运行时性能吗?
或者另一种方法,在提高运行时间的同时达到相同的模型精度?在
也许另一个库中的predict()函数不需要如此大的开销?在
尝试了不同的sklearn模型,从复杂到简单(线性回归)和性能问题仍然存在。这表明问题在于predict函数所需的开销,而不是模型本身。在
我试图在一个有300k标签的样本数据集上进行预测,而预先训练的模型在4秒钟内就可以预测到。在Class test(b):
def predict(self, data, model):
#form feature dataframe X using data
prediction = model.predict()
return prediction[0]
def run(self):
model = pickle.load("model.pkl")
streaming_data_row = #gets a row of data. Dimensions 1x11
prediction = predict(streaming_data_row, model)
self.submit(prediction)
#MUST EXECUTE self.submit() before next streaming_data_row can be received.