【问题标题】:Input parameter for model as string in Text classification模型的输入参数作为文本分类中的字符串
【发布时间】:2018-08-05 23:25:16
【问题描述】:

我正在使用 scikit-learn 构建文档分类系统,它运行良好。我正在将模型转换为 Core ML 模型格式。但是模型格式除了输入参数为multiArrayType。我想让它排除字符串或字符串数​​组,以便我可以轻松地从 IOS 应用程序中预测。我尝试了以下方法:

from sklearn.linear_model import LogisticRegression

logreg = LogisticRegression()
logreg.fit(X_train_dtm, y_train)

#testing a value
docs_new = ['get exclusive prize offer']
docs_pred_class = nb.predict(count_vect.transform(docs_new))

#Exporting to coremodel
import coremltools

coreml_model = coremltools.converters.sklearn.convert(logreg)
#print model
coreml_model

打印 coreml 模型会得到以下输出:

 input {
     name: "input"
     type {
     multiArrayType {
      shape: 7505
      dataType: DOUBLE
    }
  }
}
output {
  name: "classLabel"
  type {
    int64Type {
    }
  }
}
output {
  name: "classProbability"
  type {
    dictionaryType {
      int64KeyType {
      }
    }
  }
  }
  predictedFeatureName: "classLabel"
predictedProbabilitiesName: "classProbability" 

我检查了 GitHub 库中的Core ML model,我可以看到有不同的输入和输出。

我怎样才能做到这一点,以便我可以从 IOS 应用程序传递一个简单的参数来进行预测。

【问题讨论】:

    标签: python scikit-learn text-classification coreml coremltools


    【解决方案1】:

    听起来您发现的其他 mlmodel 使用 DictVectorizer 将字符串转换为索引(可能后跟 OneHotEncoder)。

    您可以通过在 sklearn 中创建管道并将该管道转换为 Core ML 来做到这一点。

    【讨论】:

      猜你喜欢
      • 2016-07-26
      • 2011-01-03
      • 2013-11-26
      • 2011-07-29
      • 1970-01-01
      • 1970-01-01
      • 2019-05-29
      • 2015-09-24
      • 2016-09-04
      相关资源
      最近更新 更多