【发布时间】:2017-12-06 17:09:59
【问题描述】:
我已经建立了一个二项式 glm 模型。该模型预测两个潜在类别之间的输出:AD 或 Control。这些变量是具有水平的因子:{AD, Control}。我使用这个模型来预测并获得每个样本的概率,但我不清楚超过 0.5 的概率是表示 AD 还是 Control。
这是我的数据集:
> head(example)
cleaned_mayo$Diagnosis pca_results$x[, 1]
1052_TCX AD 0.9613241
1104_TCX AD -0.9327390
742_TCX AD 1.6908874
1945_TCX Control 0.6819104
134_TCX AD 0.5184748
11386_TCX Control 0.4669661
这是我计算模型和进行预测的代码:
# Randomize rows of top performer
example<- example[sample(nrow(example)),]
# Subset data for training and testing
N_train<- round(nrow(example)*0.75)
train<- example[1:N_train,]
test<- example[(N_train+1):nrow(example),]
colnames(train)[1:2]<- c("Diagnosis", "Eigen_gene")
colnames(test)[1:2]<- c("Diagnosis", "Eigen_gene")
# Build model and predict
model_IFGyel<- glm(Diagnosis ~ Eigen_gene, data = train, family = binomial())
pred<- predict(model_IFGyel, newdata= test, type= "response")
# Convert predictions to accuracy metric
pred[which(pred<0.5)]<- "AD"
pred[which(pred!="AD")]<- "Control"
test$Diagnosis<- as.character(test$Diagnosis)
example_acc<- sum(test$Diagnosis==pred, na.rm = T)/nrow(test)
感谢任何帮助澄清这些预测概率所指示的内容。
【问题讨论】:
标签: r regression prediction glm