0

我正在努力将 LogisticRegression 文本分类从单字特征升级到双字母(两个词特征)。但是,当我在发送到 patsy.dmatrices 的公式中包含两个单词特征时,我收到以下错误...

y, X = dmatrices("is_host ~ dedicated + hosting + dedicated hosting", df, return_type="dataframe")

  File "<string>", line 1
    dedicated hosting
                ^
SyntaxError: unexpected EOF while parsing

我在网上四处寻找有关如何解决此问题的任何示例,但没有找到任何东西。我尝试在公式中抛出一些不同的语法选项,但似乎没有一个有效。

"is_host ~ dedicated + hosting + {dedicated hosting}"
"is_host ~ dedicated + hosting + (dedicated hosting)"
"is_host ~ dedicated + hosting + [dedicated hosting]"

在传递给 dmatricies 的公式中包含多词特征的正确方法是什么?

4

1 回答 1

0

你要:

y, X = dmatrices("is_host ~ dedicated + hosting + Q('dedicated hosting')", df, return_type="dataframe")

Q是报价的缩写

于 2016-04-11T02:56:38.660 回答