【发布时间】:2016-01-10 18:19:17
【问题描述】:
我正在尝试做一些接近于 shallow 引导的事情,但我正在为数据类型而苦苦挣扎。这是脚本:
library(languageR)
data(dative)
sub1<-dative[grepl("S10|S11",dative$Speaker),]
mod_sub1<-glm(RealizationOfRecipient~Verb+SemanticClass+LengthOfRecipient+AnimacyOfRec+DefinOfRec+PronomOfRec+LengthOfTheme+AnimacyOfTheme+DefinOfTheme+PronomOfTheme+AccessOfRec+AccessOfTheme,family='binomial',data=sub1)
comp_sub1<-dative[!grepl("S10|S11",dative$Speaker),]
expected_compsub1 <- comp_sub1$RealizationOfRecipient
predicted_compsub1 <- predict(mod_sub1,ndata=comp_sub1,type="response")
predictions_sub1 <- prediction(predicted_compsub1,expected_compsub1)
performance_sub1 <- performance(predictions_sub1,"tpr","fpr")
plot(performance_sub1)
在全球环境窗口中:
- expected_compsub1 : Factor w/ 2 levels "NP","PP" : 1 1 1 ...
- predicted_compsub1 : Named num [1:1076] 0.1561 0.9889 ...
我尝试使用ifelse (predicted_compsub1 >0.5,"NP","PP"),但它也不起作用。
我得到以下错误:
predictions_sub1 <- prediction(y_predicted_compsub1,expected_compsub1)
Error in prediction(y_predicted_compsub1, expected_compsub1) :
Number of predictions in each run must be equal to the number of labels for each run.
我可以看出这是类型问题,但我不知道如何解决问题。 感谢您的洞察力!
【问题讨论】:
-
predict() 函数从何而来?它没有加载那个包。
-
通常的
predict函数,如predict.glm采用type参数。您指定type = "response"以获取预测的 y 值,而不是线性预测器。查看prediction函数的文档 - 无论它来自什么包 - 看看它是否有类似的东西。 -
prediction() 来自 ROCR 库。在文档中,它的工作方式如下: prediction(predictions, labels, label.ordering = NULL) ...我看不出它与“类型”(我在 predict() 中使用)的关系。
-
@Parselmouthintraining : 那为什么 ROCR 没有库调用???
-
@42 : 脚本写得比较高,我忘记复制了...
标签: r logistic-regression prediction glm