如何在jythonudf中使用pig的pickled scikit学习模型?

pobjuy32  于 2021-06-25  发布在  Pig
关注(0)|答案(1)|浏览(228)

我已经从scikitlearn训练了一个多项式nb模型,现在我想在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"
yyyllmsg

yyyllmsg1#

jython不能使用numpy、scipy和scikit learn,因为它们都有jython不支持的本机编译扩展。因此,既不能在jython中使用scikit学习模型,也不能从pickle文件中加载它们。
你能做什么呢?内省mnb类的代码,以了解要导出哪些参数(例如,在json文件中),并重写一个新的predict方法,该方法可以从jython中的那些固定参数计算预测。
或者,您可以在hadoop节点上安装cpython、numpy、scipy和scikit learn(例如,使用anaconda发行版),并通过hadoop流接口调用scikit learn。

相关问题