Rパッケージの関数を使用して、confusionMatrix
持っているデータの統計を計算しています。関数で使用されるテーブルを取得するために、予測と実際の値を関数に入れています。caret
table
confusionMatrix
table(predicted,actual)
ただし、複数の可能な結果 (例: A、B、C、D) があり、私の予測は常にすべての可能性を表すとは限りません (例: A、B、D のみ)。関数の結果の出力にtable
は、欠落している結果が含まれておらず、次のようになります。
A B C D
A n1 n2 n2 n4
B n5 n6 n7 n8
D n9 n10 n11 n12
# Note how there is no corresponding row for `C`.
関数はconfusionMatrix
不足している結果を処理できず、エラーが発生します。
Error in !all.equal(nrow(data), ncol(data)) : invalid argument type
関数を別の方法で使用しtable
て欠落している行をゼロで取得したり、関数を別の方法で使用して、欠落してconfusionMatrix
いる結果をゼロとして表示したりする方法はありますか?
注: テスト対象のデータをランダムに選択しているため、予測結果だけでなく、実際の結果でもカテゴリが表されない場合があります。これで解決策が変わるとは思いません。