如何在 Jython UDF for Pig 中使用 pickled scikit-learn 模型?

How to use pickled scikit-learn model in Jython UDF for Pig?

我已经从 scikit-learn 训练了一个 MultinomialNB 模型,现在我想在 S3 集群上的很多很多 json 文本文件上使用它。我腌制了模型(称之为 "nb.pickle")。我如何将它加载到 Pig 脚本中并使用它?假设我有一个包含文本行的文件,每个文本行都需要被归类为垃圾邮件或非垃圾邮件:

    "im bored tonight, come chat with me",
    "hi good looking msg me sometime",
    "I'm walking the dog",
    "check me out",
    "I went to the store earlier",
    "here much at all but im always on there at i get on there alot more, my id is orangewolf77",
    "I like to play baseball",
    "what are you doing?",
    "i had a picture on my profile did u not see it?",
    "look at my b00bs",
    "go to my website http://we.scam.u
    "you are so pretty"

Jython 不能使用 numpy、scipy 和 scikit-learn,因为它们都有 Jython 不支持的本机编译扩展。因此,无法在 Jython 中使用 scikit-learn 模型,也无法从 pickle 文件加载它们。

你可以做什么它反省 MNB 的代码 class 以了解要导出哪些参数(例如在 json 文件中)并重写一个新的预测方法,该方法可以根据这些参数计算预测Jython 中的固定参数。

或者,您可以在您的 hadoop 节点上安装 CPython、numpy、scipy 和 scikit-learn(例如使用 Anaconda 发行版)并通过 hadoop 流接口调用 scikit-learn。