当前,我正在尝试将模型从sklearn导出到Android。为此,我使用了库sklearn-porter
(sklearn-porter)。
这将从经过训练的模型中生成一个Java类,如下所示:
class DecisionTreeClassifier {
public static int predict(double[] features) {
int[] classes = new int[2];
if (features[350] <= 0.5156863033771515) {
if (features[568] <= 0.0019607844296842813) {
if (features[430] <= 0.0019607844296842813) {
if (features[405] <= 0.009803921915590763) {
...
}
此文件的大小约为1 MB,因此在Android Studio中出现错误“代码太大”。
是否有解决此问题的方法?
答案 0 :(得分:4)
当您使用export_data=True
执行搬运工时,您还将获得一个小的Java类,该类从.json
文件中读取DecisionTree参数:
porter = Porter(clf, language='java')
output = porter.export(export_data=True)
print(output)