R !!!判別分析 library(MASS) *カテゴリー変数が二値 *2つ以上のスコア !全体のデータをランダムに半分ずつに分ける sample() *トレーニングデータ *テストデータ !トレーニングデータを使って判別モデルを作成 モデル <- <>(カテゴリー変数 ~ 変数A + 変数B, トレーニングデータ) !テストデータで検証 *モデルを使って、テストデータを予測して(あてはめて)みる 予測結果 <- <>(モデル, テストデータ) !判別率の確認 install.packages("caret", dependencies =T) library(caret) <>を使う *このとき、予測結果のオブジェクトの中の class に予測値が入っている {{pre > confusionMatrix(予測結果$class, テストデータ$gender) Confusion Matrix and Statistics Reference Prediction Female Male Female 2306 191 Male 198 2305 Accuracy : 0.9222 95% CI : (0.9144, 0.9295) No Information Rate : 0.5008 P-Value [Acc > NIR] : <2e-16 Kappa : 0.8444 Mcnemar's Test P-Value : 0.761 Sensitivity : 0.9209 Specificity : 0.9235 Pos Pred Value : 0.9235 Neg Pred Value : 0.9209 Prevalence : 0.5008 Detection Rate : 0.4612 Detection Prevalence : 0.4994 Balanced Accuracy : 0.9222 'Positive' Class : Female }} !!群馬大の青木先生の「判別分析」スクリプト