繁体   English   中英

R中的glm逻辑回归

[英]glm logistic regression in R

我正在尝试对我拥有的数据集进行逻辑回归

model <- glm(feature1 ~ feature2, data=df, family="binomial")

但是glm出人意料。 它将“feature2”的所有值作为变量,并将它们分配给模型中的logit参数。

摘要输出(型号):

> summary(model)

Call:

glm(formula = feature1 ~ price, family = binomial(logit), data = df)

Deviance Residuals: 
     Min        1Q    Median        3Q       Max  
-2.22931  -0.00008   0.00008   0.82033   1.97277  

Coefficients:
               Estimate Std. Error z value Pr(>|z|)
(Intercept)   6.931e-01  1.225e+00   0.566    0.571
price0.06     1.887e+01  1.075e+04   0.002    0.999
price0.1     -6.931e-01  1.871e+00  -0.371    0.711
price0.11     1.887e+01  1.075e+04   0.002    0.999
price0.2      1.887e+01  1.075e+04   0.002    0.999
price0.9      1.887e+01  1.075e+04   0.002    0.999
price0.99     1.092e-01  1.269e+00   0.086    0.931
price1        1.253e+00  1.626e+00   0.771    0.441
price1.01     1.887e+01  1.075e+04   0.002    0.999
price1.02     1.887e+01  1.075e+04   0.002    0.999
price1.04     1.887e+01  1.075e+04   0.002    0.999

> typeof(nonNPpriceDf$price)
[1] "integer"

我希望价格只是一个预测变量。 我无法理解为什么所有价格都被追加并作为变量处理。

这是typeof和class方法之间的混淆。 因子2的类型是整数,但类是因子。 我将factor2转换为数字,它按预期工作正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM