2017-05-02 2 views
1

Rでは、glmの概要は多くの有用な情報を与えます。しかし、私は分類ミス率/精度メトリックを見つけられませんでした。私がこれらのメトリクスを望むたびに、予測を再実行し、グランド・トゥルース・ラベルと比較する必要があります。もっと良い方法はありますか?たとえば、glmの結果から抽出しますか?グラム結果から分類精度とCohens 'Kappaを得ることはできますか?

> summary(glm(am~wt,mtcars,family = "binomial")) 

Call: 
glm(formula = am ~ wt, family = "binomial", data = mtcars) 

Deviance Residuals: 
    Min  1Q Median  3Q  Max 
-2.11400 -0.53738 -0.08811 0.26055 2.19931 

Coefficients: 
      Estimate Std. Error z value Pr(>|z|) 
(Intercept) 12.040  4.510 2.670 0.00759 ** 
wt   -4.024  1.436 -2.801 0.00509 ** 
--- 
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

(Dispersion parameter for binomial family taken to be 1) 

    Null deviance: 43.230 on 31 degrees of freedom 
Residual deviance: 19.176 on 30 degrees of freedom 
AIC: 23.176 

Number of Fisher Scoring iterations: 6 
+0

、第一段階で 'glm'オブジェクトを保存します。その後、推定ルーチンを再実行する必要なしに、保存されたオブジェクトに対するすべての事後分析を実行できます。 – lmo

+0

@lmo、ありがとうございますが、私はglm結果から正確さを得ることができれば幸いです。残念なことに、私は個人的に考えると便利です。 – hxd1011

答えて

1

ここでは、モデルの予測能力を評価するためのヒントを示します。

set.seed(1234) 
# Generate a training and a testing set 
idx <- sample(1:nrow(mtcars), size=round(0.5*nrow(mtcars))) 
train <- mtcars[idx,] 
test <- mtcars[-idx,] 

# Fit model and evaluate prediction probabilities 
glmfit <- glm(am ~ wt, train, family = "binomial") 
test$pred <- predict(glmfit, type="response", newdata=test) 

# Calculate the area under the ROC curve 
library(pROC) 
roc.curve <- roc(test$am, test$pred, ci=T) 

# Plot the ROC curve 
plot(roc.curve) 

enter image description here

# Calculates a cross-tabulation of observed and predicted classes 
# with associated statistics 
library(caret) 
threshold <- 0.5 
confusionMatrix(factor(test$pred>threshold), factor(test$am==1), positive="TRUE") 

confusionMatrixコマンドの出力は次のとおり

中間ステップとして多分
Confusion Matrix and Statistics 

      Reference 
Prediction FALSE TRUE 
    FALSE  8 0 
    TRUE  3 5 

       Accuracy : 0.8125   
       95% CI : (0.5435, 0.9595) 
    No Information Rate : 0.6875   
    P-Value [Acc > NIR] : 0.2134   

        Kappa : 0.625   
Mcnemar's Test P-Value : 0.2482   

      Sensitivity : 1.0000   
      Specificity : 0.7273   
     Pos Pred Value : 0.6250   
     Neg Pred Value : 1.0000   
      Prevalence : 0.3125   
     Detection Rate : 0.3125   
    Detection Prevalence : 0.5000   
     Balanced Accuracy : 0.8636   

     'Positive' Class : TRUE 
+0

ありがとう+1、私はprocとキャレットの混乱の行列に精通しています。私の質問は、glm fitオブジェクトから直接取得できるかどうかです。 – hxd1011

+0

私の経験では、これらの情報を 'glm'オブジェクトから直接取得することはできません。 –

関連する問題