【问题标题】:Logistic Regression Bigram Text Classification w/ Patsy带 Patsy 的 Logistic 回归 Bigram 文本分类
【发布时间】:2015-08-13 10:44:00
【问题描述】:

我正在努力将 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 的公式中包含多词特征的正确方法是什么?

【问题讨论】:

    标签: python machine-learning scikit-learn logistic-regression patsy


    【解决方案1】:

    你想要:

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

    Q is short for quote.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-19
      • 1970-01-01
      • 2015-01-06
      • 2015-08-13
      • 2021-04-22
      • 2016-11-15
      • 2019-03-11
      相关资源
      最近更新 更多