(Bing Image Creator で生成: プロンプト: Close up of blue and red Hydrangea macrophylla flowers, flowering is rainy days on the beautiful location, photo)
の続きです。今回はニューラルネットワークによる予測をします。nnet パッケージを使います。
まずは、パッケージの読み込みです。
nnet() 関数でモデルを作成します。size = 3 として隠れ層を3にしました。
predict() 関数で予測します。
結果を confusionMatrix() 関数で確認します。
accuracy は 0.8972 で、balanced accuracy は 0.6089 でした。
いままでの結果に追加します。
今回は以上です。
次回は
です。
初めから読むには、
です。
今回のコードは以下になります。
#
# 第5のモデル: ニューラルネットワーク
#
# nnet パッケージの読み込み
library(nnet)
#
# モデルの作成
set.seed(4321)
nnet_model <- nnet(factor(yes) ~ ., data = df_train, size = 3)
#
# nnet_model で予測
nnet_pred <- predict(nnet_model, df_test, type = "class")
#
# 成績
confusionMatrix(factor(nnet_pred),
factor(df_test$yes))
#
# 成績を保存
estimates_results <- estimates_results |>
rbind(
tibble(
model = "nnet",
accuracy = 0.8972,
b_accuracy = 0.6089
)
)
estimates_results
#