用于多项Logistic回归的混淆矩阵&有序logit

时间:2018-01-30 11:42:01

标签: r statistics logistic-regression confusion-matrix multinomial

我想为多项逻辑回归以及比例赔率模型创建混淆矩阵,但我坚持使用R中的实现。我的下面的尝试似乎没有给出所需的输出。

到目前为止,这是我的代码:

CH <- read.table("http://data.princeton.edu/wws509/datasets/copen.dat", header=TRUE)
CH$housing <- factor(CH$housing)
CH$influence <- factor(CH$influence)
CH$satisfaction <- factor(CH$satisfaction)
CH$contact <- factor(CH$contact)
CH$satisfaction <- factor(CH$satisfaction,levels=c("low","medium","high"))
CH$housing <- factor(CH$housing,levels=c("tower","apartments","atrium","terraced"))
CH$influence <- factor(CH$influence,levels=c("low","medium","high"))
CH$contact <- relevel(CH$contact,ref=2)
model <- multinom(satisfaction ~ housing + influence + contact, weights=n, data=CH)
summary(model)
preds <- predict(model)
table(preds,CH$satisfaction)

omodel <- polr(satisfaction ~ housing + influence + contact, weights=n, data=CH, Hess=TRUE)
preds2 <- predict(omodel)
table(preds2,CH$satisfaction)

我非常感谢有关如何为我的2个模型正确生成混淆矩阵的一些建议!

1 个答案:

答案 0 :(得分:0)

你可以参考 - Predict() - Maybe I'm not understanding it

在predict()中,您需要传递看不见的数据进行预测。