提高sklearn中随机森林回归器的性能

4

我有一个优化问题,需要调用随机森林回归器的预测函数数千次。

from sklearn.ensemble import RandomForestRegressor
rfr = RandomForestRegressor(n_estimators=10)
rfr = rfr.fit(X, Y)
for iteration in range(0, 100000):
    # code that adapts the input data according to fitness of the last output
    output_data = rfr.predict(input_data)
    # code that evaluates the fitness of output data

在这种情况下有没有办法提高预测函数的速度?可能可以使用Cython来实现。

1个回答

5

您可以使用SKompiler (https://github.com/konstantint/SKompiler)将其转换为C或C++代码,然后在那里运行。

from skompiler import skompile
expr = skompile(rfr.predict)
with open("output.cpp", "w") as text_file: print(expr.to('sympy/cxx'), file=text_file)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接