Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用sklearn\u porter将sklearn python代码导出为C代码?_Python_C_Scikit Learn - Fatal编程技术网

如何使用sklearn\u porter将sklearn python代码导出为C代码?

如何使用sklearn\u porter将sklearn python代码导出为C代码?,python,c,scikit-learn,Python,C,Scikit Learn,我试图使用sklearn\u porter在python中训练一个随机林模型,然后将其导出到C代码中 这是我的代码: from sklearn_porter import Porter from sklearn.ensemble import RandomForestClassifier from sklearn.datasets import load_iris import sys sys.path.append('../../../../..') iris_data = load_iris

我试图使用
sklearn\u porter
在python中训练一个随机林模型,然后将其导出到C代码中

这是我的代码:

from sklearn_porter import Porter
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_iris
import sys
sys.path.append('../../../../..')
iris_data = load_iris()

X = iris_data.data
y = iris_data.target

print(X.shape, y.shape)
clf = RandomForestClassifier(n_estimators=15, max_depth=None,
                             min_samples_split=2, random_state=0)
clf.fit(X, y)
porter = Porter(clf, language='c')
output = porter.export(embed_data=True)

print(output)
但会出现以下错误:

...AppData\Local\Programs\Python\Python38\lib\site-packages\sklearn_porter\Porter.py", line 10, in <module>
    from sklearn.tree.tree import DecisionTreeClassifier
ModuleNotFoundError: No module named 'sklearn.tree.tree
所以我改正了,但是又发生了一个错误

...AppData\Local\Programs\Python\Python38\lib\site-packages\sklearn_porter\Porter.py", line 117, in __init__
    error = "Currently the given model '{algorithm_name}' " \
KeyError: 'algorithm_name'
但是我不能纠正这个错误

我做错了什么

我正在使用python 3.8.8和scikit learn 0.24.1


编辑:在Python3.7.10中也尝试了它,因为on声明它只适用于Python2.7、3.4、3.5、3.6和3.7。在3.7上,同样的错误也会发生

代码使用scikit学习版本0.22.2工作。还有Python 3.7.9

问题似乎在于
sklearn-porter
与最新版本的scikit-learn不兼容,例如,请参见。您可能想问他们是否计划支持最新的scikit学习版本

作为替代方案,您可能需要查看

...AppData\Local\Programs\Python\Python38\lib\site-packages\sklearn_porter\Porter.py", line 117, in __init__
    error = "Currently the given model '{algorithm_name}' " \
KeyError: 'algorithm_name'