2017-03-06 2 views
0

MASSパッケージのqda関数を使ってスイス銀行券のデータセットを練習していましたが、適合モデルで予測するとエラーが発生しました。問題は、qdaが「qda」クラスではなく「リスト」を返すことです。R qda {MASS} qdaクラスではないリストクラスを返す

`str(swiss)` 
`'data.frame':200 obs. of 7 variables: 
$ Status : Factor w/ 2 levels "counterfeit",..: 2 2 2 2 2 2 2 2 2 2 ... 
$ Length : num 215 215 215 215 215 ... 
$ Left : num 131 130 130 130 130 ... 
$ Right : num 131 130 130 130 130 ... 
$ Bottom : num 9 8.1 8.7 7.5 10.4 9 7.9 7.2 8.2 9.2 ... 
$ Top  : num 9.7 9.5 9.6 10.4 7.7 10.1 9.6 10.7 11 10 ... 
$ Diagonal: num 141 142 142 142 142 ...` 

`qda.fit <- qda(Status ~., data = swiss, prior = c(0.99, 0.01), CV = TRUE) 
test <- data.frame(Length = 214.9, Left = 130.1, Right = 129.9, Bottom = 9, Top = 10.6, Diagonal = 140.5) 
qda.pred <- predict(qda.fit, test) 
Error in UseMethod("predict") : 
    no applicable method for 'predict' applied to an object of class "list" 
Class(qda.fit) 
    [1] "list"` 


`sessionInfo() 
R version 3.3.2 (2016-10-31) 
Platform: x86_64-w64-mingw32/x64 (64-bit) 
Running under: Windows 7 x64 (build 7601) Service Pack 1` 

`locale: 
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252 
[3] LC_MONETARY=English_United States.1252 
[4] LC_NUMERIC=C       
[5] LC_TIME=English_United States.1252 ` 

`attached base packages: 
[1] stats  graphics grDevices utils  datasets methods 
[7] base ` 

`other attached packages: 
[1] MASS_7.3-45` 

`loaded via a namespace (and not attached): 
[1] tools_3.3.2` 

希望します。

おかげで、

XPの

答えて

0

注手動での注意点:

クラスのオブジェクト "QDA" を含む下記の成分:

...

CV = TRUEでない場合、戻り値がの場合リスト wiその後、

...

設定CV = Fpredictでオブジェクトを使用します:番目のコンポーネント

qda.fit <- qda(Status ~., data = banknote, prior = c(0.99, 0.01), CV = F) 
test <- data.frame(Length = 214.9, Left = 130.1, 
        Right = 129.9, Bottom = 9, 
        Top = 10.6, Diagonal = 140.5) 
qda.pred <- predict(qda.fit, test) 

qda.pred 
$class 
[1] genuine 
Levels: counterfeit genuine 

$posterior 
    counterfeit genuine 
1 0.02416251 0.9758375 
+0

は、あなたの迅速な答えをいただき、ありがとうございます。はい、私はそれを試みましたが、SASの 'proc discrim data = combined pool = test crossvalidate testdata = test testout = a;クロス検証を経て、私に事後確率を与えます:偽造:0.000002526、 Rケースの分類には影響しないが、正確である。私は私の質問があったはずだと思います:私はこの場合qda()とのクロスバリデーションを行い、SAS出力と同様の結果を得たいと考えています。 –

関連する問題