2009-11-11 3 views
0

ROCR 패키지를 사용하여 분석에서 생체 인식 데이터를 내보내려고합니다. 지금까지 수행 한 코드는 다음과 같습니다.ROCR 패키지에서 데이터를 내보내는 방법

pred = performance(Matching.Score,Distribution) 
perf = prediction(pred,"fnr", "fpr") 

An object of class “performance” 

Slot "x.name": 

[1] "False positive rate" 

Slot "y.name": 

[1] "False negative rate" 

Slot "alpha.name": 

[1] "Cutoff" 

Slot "x.values": 

[[1]] 

[1] 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 
[15] 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 
    ...... 

Slot "y.values": 

[[1]] 

[1] 1.00000 0.99999 0.99998 0.99997 0.99996 0.99995 
[15] 0.99986 0.99985 0.99984 0.99983 0.99982 0.99981 
    ...... 

Slot "alpha.values": 

[[1]] 

[1] Inf  1.0427800 1.0221150 1.0056240 1.0032630 0.9999599 
[12] 0.9644779 0.9633058 0.9628996 0.9626501 0.9607665 0.9605930 
    ....... 

결과적으로 여러 슬롯이 생성됩니다. 내가 사용하는 엑셀 수정을위한 텍스트 파일로 결과 값을 내보낼 것이다 :

Error in cat(list(...), file, sep, fill, labels, append) : 
    argument 1 (type 'S4') cannot be handled by 'cat' 

인가 :

write(pred, "filename")

그러나

내가 파일을 작성하려고 할 때, 나는라는 오류가 이 주변에 어떤 방법이 있니?

나는 조언을 주시면 감사하겠습니다. 고맙습니다!

매트 피터슨

답변

3

확인 str와 결과 S4 오브젝트의 클래스 구조는 dataframe를 구축하고 그 결과를 내보낼 write.table/write.csv 사용할 수있는 관련 변수를 추출합니다. 예를 들어, 예측 pred에 대한 :

R> library("ROCR") 
R> data(ROCR.simple) 
R> pred <- prediction(ROCR.simple$predictions, ROCR.simple$labels) 
R> perf <- performance(pred, "fnr", "fpr") 
R> str(pred) 
Formal class 'prediction' [package "ROCR"] with 11 slots 
    [email protected] predictions:List of 1 
    .. ..$ : num [1:200] 0.613 0.364 0.432 0.14 0.385 ... 
    [email protected] labels  :List of 1 
    .. ..$ : Ord.factor w/ 2 levels "0"<"1": 2 2 1 1 1 2 2 2 2 1 ... 
    [email protected] cutoffs :List of 1 
    .. ..$ : num [1:201] Inf 0.991 0.985 0.985 0.983 ... 
    [email protected] fp   :List of 1 
    .. ..$ : num [1:201] 0 0 0 0 1 1 2 3 3 3 ... 
    [email protected] tp   :List of 1 
    .. ..$ : num [1:201] 0 1 2 3 3 4 4 4 5 6 ... 
    [email protected] tn   :List of 1 
    .. ..$ : num [1:201] 107 107 107 107 106 106 105 104 104 104 ... 
    [email protected] fn   :List of 1 
    .. ..$ : num [1:201] 93 92 91 90 90 89 89 89 88 87 ... 
    [email protected] n.pos  :List of 1 
    .. ..$ : int 93 
    [email protected] n.neg  :List of 1 
    .. ..$ : int 107 
    [email protected] n.pos.pred :List of 1 
    .. ..$ : num [1:201] 0 1 2 3 4 5 6 7 8 9 ... 
    [email protected] n.neg.pred :List of 1 
    .. ..$ : num [1:201] 200 199 198 197 196 195 194 193 192 191 ... 

R> write.csv(data.frame([email protected], [email protected]), file="result_pred.csv") 

perf 성능 : 속임수를 썼는지

R> str(perf) 
Formal class 'performance' [package "ROCR"] with 6 slots 
    [email protected] x.name  : chr "False positive rate" 
    [email protected] y.name  : chr "False negative rate" 
    [email protected] alpha.name : chr "Cutoff" 
    [email protected] x.values :List of 1 
    .. ..$ : num [1:201] 0 0 0 0 0.00935 ... 
    [email protected] y.values :List of 1 
    .. ..$ : num [1:201] 1 0.989 0.978 0.968 0.968 ... 
    [email protected] alpha.values:List of 1 
    .. ..$ : num [1:201] Inf 0.991 0.985 0.985 0.983 ... 

R> write.csv(data.frame([email protected], 
         [email protected], 
         [email protected]), 
      file="result_perf.csv") 
+0

. 나는 구조 논증을 놓쳤다. 고마워요! –

관련 문제