【问题标题】:Increase performance of Random Forest Regressor in sklearn提高 sklearn 中随机森林回归器的性能
【发布时间】:2020-03-12 16:41:19
【问题描述】:

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

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?

【问题讨论】:

    标签: python scikit-learn sklearn-pandas


    【解决方案1】:

    您可以使用 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)
    

    【讨论】:

      猜你喜欢
      • 2023-03-14
      • 2014-05-29
      • 2018-11-20
      • 2016-07-23
      • 2021-12-25
      • 2019-12-06
      • 2018-12-04
      • 2021-10-31
      • 2019-03-30
      相关资源
      最近更新 更多