如何从 ROCR 包导出数据

发布于 2024-08-11 00:33:36 字数 1096 浏览 6 评论 0原文

我正在尝试使用 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
    .......

这会产生几个插槽。我想使用以下方法将结果值导出到文本文件中进行 Excel 修改:

write(pred, "filename")

但是,当我尝试写入文件时,收到一条错误消息:

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

是否存在有什么办法解决这个问题吗?

我将不胜感激任何建议。谢谢你!

马特·彼得森

I am trying to export biometric data from an analysis using the ROCR package. Here is the code that I've done so far:

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
    .......

This results in several Slots. I would like to export the resulting values into a text file for Excel modification using:

write(pred, "filename")

However, when I try to write the file, I get an error stating:

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

Is there any way around this?

I'd appreciate any advice. Thank you!

Matt Peterson

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把回忆走一遍 2024-08-18 00:33:36

使用 str 检查生成的 S4 对象的类结构,提取相关变量以构建数据帧并使用 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
  ..@ predictions:List of 1
  .. ..$ : num [1:200] 0.613 0.364 0.432 0.14 0.385 ...
  ..@ labels     :List of 1
  .. ..$ : Ord.factor w/ 2 levels "0"<"1": 2 2 1 1 1 2 2 2 2 1 ...
  ..@ cutoffs    :List of 1
  .. ..$ : num [1:201] Inf 0.991 0.985 0.985 0.983 ...
  ..@ fp         :List of 1
  .. ..$ : num [1:201] 0 0 0 0 1 1 2 3 3 3 ...
  ..@ tp         :List of 1
  .. ..$ : num [1:201] 0 1 2 3 3 4 4 4 5 6 ...
  ..@ tn         :List of 1
  .. ..$ : num [1:201] 107 107 107 107 106 106 105 104 104 104 ...
  ..@ fn         :List of 1
  .. ..$ : num [1:201] 93 92 91 90 90 89 89 89 88 87 ...
  ..@ n.pos      :List of 1
  .. ..$ : int 93
  ..@ n.neg      :List of 1
  .. ..$ : int 107
  ..@ n.pos.pred :List of 1
  .. ..$ : num [1:201] 0 1 2 3 4 5 6 7 8 9 ...
  ..@ n.neg.pred :List of 1
  .. ..$ : num [1:201] 200 199 198 197 196 195 194 193 192 191 ...

R> write.csv(data.frame(fp=pred@fp, fn=pred@fn), file="result_pred.csv")

和对于性能 perf

R> str(perf)
Formal class 'performance' [package "ROCR"] with 6 slots
  ..@ x.name      : chr "False positive rate"
  ..@ y.name      : chr "False negative rate"
  ..@ alpha.name  : chr "Cutoff"
  ..@ x.values    :List of 1
  .. ..$ : num [1:201] 0 0 0 0 0.00935 ...
  ..@ y.values    :List of 1
  .. ..$ : num [1:201] 1 0.989 0.978 0.968 0.968 ...
  ..@ 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")

Check the class structure of the resulting S4 objects with str, extract the relevant variables to build a dataframe and use write.table/write.csv to export the results. For instance, for the prediction 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
  ..@ predictions:List of 1
  .. ..$ : num [1:200] 0.613 0.364 0.432 0.14 0.385 ...
  ..@ labels     :List of 1
  .. ..$ : Ord.factor w/ 2 levels "0"<"1": 2 2 1 1 1 2 2 2 2 1 ...
  ..@ cutoffs    :List of 1
  .. ..$ : num [1:201] Inf 0.991 0.985 0.985 0.983 ...
  ..@ fp         :List of 1
  .. ..$ : num [1:201] 0 0 0 0 1 1 2 3 3 3 ...
  ..@ tp         :List of 1
  .. ..$ : num [1:201] 0 1 2 3 3 4 4 4 5 6 ...
  ..@ tn         :List of 1
  .. ..$ : num [1:201] 107 107 107 107 106 106 105 104 104 104 ...
  ..@ fn         :List of 1
  .. ..$ : num [1:201] 93 92 91 90 90 89 89 89 88 87 ...
  ..@ n.pos      :List of 1
  .. ..$ : int 93
  ..@ n.neg      :List of 1
  .. ..$ : int 107
  ..@ n.pos.pred :List of 1
  .. ..$ : num [1:201] 0 1 2 3 4 5 6 7 8 9 ...
  ..@ n.neg.pred :List of 1
  .. ..$ : num [1:201] 200 199 198 197 196 195 194 193 192 191 ...

R> write.csv(data.frame(fp=pred@fp, fn=pred@fn), file="result_pred.csv")

and for performance perf:

R> str(perf)
Formal class 'performance' [package "ROCR"] with 6 slots
  ..@ x.name      : chr "False positive rate"
  ..@ y.name      : chr "False negative rate"
  ..@ alpha.name  : chr "Cutoff"
  ..@ x.values    :List of 1
  .. ..$ : num [1:201] 0 0 0 0 0.00935 ...
  ..@ y.values    :List of 1
  .. ..$ : num [1:201] 1 0.989 0.978 0.968 0.968 ...
  ..@ 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")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文