-
Notifications
You must be signed in to change notification settings - Fork 1
/
introduction.html
469 lines (431 loc) · 37.5 KB
/
introduction.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Introduction to prcbench • prcbench</title>
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha256-bZLfwXAP04zRMK2BjiO8iu9pf4FbLqX6zitd+tIvLhE=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script><!-- bootstrap-toc --><link rel="stylesheet" href="../bootstrap-toc.css">
<script src="../bootstrap-toc.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="Introduction to prcbench">
<meta property="og:description" content="prcbench">
<meta property="og:image" content="https://evalclass.github.io/prcbench/logo.svg">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body data-spy="scroll" data-target="#toc">
<div class="container template-article">
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand">
<a class="navbar-link" href="../index.html">prcbench</a>
<span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">1.0.1</span>
</span>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="../articles/introduction.html">Introduction</a>
</li>
<li>
<a href="../reference/index.html">Reference</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/evalclass/prcbench/">
<span class="fab fa-github fa-lg"></span>
</a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container -->
</div>
<!--/.navbar -->
</header><script src="introduction_files/accessible-code-block-0.0.1/empty-anchor.js"></script><div class="row">
<div class="col-md-9 contents">
<div class="page-header toc-ignore">
<h1 data-toc-skip>Introduction to prcbench</h1>
<h4 class="date">2021-04-06</h4>
<small class="dont-index">Source: <a href="https://github.com/evalclass/prcbench/blob/main/vignettes/introduction.Rmd"><code>vignettes/introduction.Rmd</code></a></small>
<div class="hidden name"><code>introduction.Rmd</code></div>
</div>
<p>The <code>prcbench</code> package is a testing workbench for evaluating Precision-Recall curves.</p>
<div id="tool-interface" class="section level2">
<h2 class="hasAnchor">
<a href="#tool-interface" class="anchor"></a>1. Tool interface</h2>
<p>The <code>prcbench</code> package provides predefined interfaces for the following five tools that calculate Precision-Recall curves.</p>
<table class="table">
<thead><tr class="header">
<th align="left">Tool</th>
<th align="left">Language</th>
<th align="left">Link</th>
</tr></thead>
<tbody>
<tr class="odd">
<td align="left">ROCR</td>
<td align="left">R</td>
<td align="left">
<a href="https://ipa-tys.github.io/ROCR/">Tool web site</a>, <a href="https://cran.r-project.org/package=ROCR">CRAN</a>
</td>
</tr>
<tr class="even">
<td align="left">AUCCalculator</td>
<td align="left">Java</td>
<td align="left"><a href="http://mark.goadrich.com/programs/AUC/">Tool web site</a></td>
</tr>
<tr class="odd">
<td align="left">PerfMeas</td>
<td align="left">R</td>
<td align="left"><a href="https://cran.r-project.org/package=PerfMeas">CRAN</a></td>
</tr>
<tr class="even">
<td align="left">PRROC</td>
<td align="left">R</td>
<td align="left"><a href="https://cran.r-project.org/package=PRROC">CRAN</a></td>
</tr>
<tr class="odd">
<td align="left">precrec</td>
<td align="left">R</td>
<td align="left">
<a href="https://evalclass.github.io/precrec/">Tool web site</a>, <a href="https://cran.r-project.org/package=precrec">CRAN</a>
</td>
</tr>
</tbody>
</table>
<div id="create-a-tool-set" class="section level3">
<h3 class="hasAnchor">
<a href="#create-a-tool-set" class="anchor"></a>Create a tool set</h3>
<p>The <code>create_toolset</code> function generates a tool set with a combination of the five tools.</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://evalclass.github.io/prcbench/">prcbench</a></span><span class="op">)</span>
<span class="co">## A single tool</span>
<span class="va">toolsetA</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_toolset.html">create_toolset</a></span><span class="op">(</span><span class="st">"ROCR"</span><span class="op">)</span>
<span class="co">## Multiple tools</span>
<span class="va">toolsetB</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_toolset.html">create_toolset</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"PerfMeas"</span>, <span class="st">"PRROC"</span><span class="op">)</span><span class="op">)</span>
<span class="co">## Tool sets can be manually combined to a single set</span>
<span class="va">toolsetAB</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="va">toolsetA</span>, <span class="va">toolsetB</span><span class="op">)</span></code></pre></div>
<p>The <code>create_toolset</code> function accepts partially matched tool names. Tool names may also be case-insensitive.</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://evalclass.github.io/prcbench/">prcbench</a></span><span class="op">)</span>
<span class="co">## A single tool - lower case</span>
<span class="va">toolsetA2</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_toolset.html">create_toolset</a></span><span class="op">(</span><span class="st">"rocr"</span><span class="op">)</span>
<span class="co">## Multiple tools - lower case and partially matched </span>
<span class="va">toolsetB2</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_toolset.html">create_toolset</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"perf"</span>, <span class="st">"prr"</span><span class="op">)</span><span class="op">)</span></code></pre></div>
</div>
<div id="use-predefined-tool-sets" class="section level3">
<h3 class="hasAnchor">
<a href="#use-predefined-tool-sets" class="anchor"></a>Use predefined tool sets</h3>
<p>The <code>create_toolset</code> function takes two additional arguments - <code>calc_auc</code> and <code>store_res</code>. The <code>calc_auc</code> argument makes tools calculate and retrieve the AUC score, and the <code>store_res</code> argument forces tools to calculate and store the curve values.</p>
<p>The following six tool sets are predefined with a different combination of tools and their argument values.</p>
<table class="table">
<thead><tr class="header">
<th align="left">Set name</th>
<th align="left">Tools</th>
<th align="left">calc_auc</th>
<th align="left">store_res</th>
</tr></thead>
<tbody>
<tr class="odd">
<td align="left">def5</td>
<td align="left">ROCR, AUCCalculator, PerfMeas, PRROC, precrec</td>
<td align="left">TRUE</td>
<td align="left">TRUE</td>
</tr>
<tr class="even">
<td align="left">auc5</td>
<td align="left">ROCR, AUCCalculator, PerfMeas, PRROC, precrec</td>
<td align="left">TRUE</td>
<td align="left">FALSE</td>
</tr>
<tr class="odd">
<td align="left">crv5</td>
<td align="left">ROCR, AUCCalculator, PerfMeas, PRROC, precrec</td>
<td align="left">FALSE</td>
<td align="left">TRUE</td>
</tr>
<tr class="even">
<td align="left">def4</td>
<td align="left">ROCR, AUCCalculator, PerfMeas, precrec</td>
<td align="left">TRUE</td>
<td align="left">TRUE</td>
</tr>
<tr class="odd">
<td align="left">auc4</td>
<td align="left">ROCR, AUCCalculator, PerfMeas, precrec</td>
<td align="left">TRUE</td>
<td align="left">FALSE</td>
</tr>
<tr class="even">
<td align="left">crv4</td>
<td align="left">ROCR, AUCCalculator, PerfMeas, precrec</td>
<td align="left">FALSE</td>
<td align="left">TRUE</td>
</tr>
</tbody>
</table>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">## Use 'set_names'</span>
<span class="va">toolsetC</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_toolset.html">create_toolset</a></span><span class="op">(</span>set_names <span class="op">=</span> <span class="st">"auc5"</span><span class="op">)</span>
<span class="co">## Multiple sets are automatically combined to a single set</span>
<span class="va">toolsetD</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_toolset.html">create_toolset</a></span><span class="op">(</span>set_names <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"auc5"</span>, <span class="st">"crv4"</span><span class="op">)</span><span class="op">)</span></code></pre></div>
</div>
</div>
<div id="test-data-interface" class="section level2">
<h2 class="hasAnchor">
<a href="#test-data-interface" class="anchor"></a>2. Test data interface</h2>
<p>The <code>prcbench</code> package provides two different types of test data. The first one is for benchmarking, and the second one is for evaluating the accuracy of Precision-Recall curves.</p>
<p>The <code>create_testset</code> function offers both types of test data by setting the first argument either as “bench” or “curve”.</p>
<div id="create-a-test-dataset-for-benchmarking" class="section level3">
<h3 class="hasAnchor">
<a href="#create-a-test-dataset-for-benchmarking" class="anchor"></a>Create a test dataset for benchmarking</h3>
<p>The <code>create_testset</code> function uses a naming convention for randomly generated data for benchmarking. The format is a prefix (‘b’ or ‘i’) followed by the number of dataset. The prefix ‘b’ indicates a balanced dataset, whereas ‘i’ indicates an imbalanced dataset. The number can be used with a suffix ‘k’ or ‘m’, indicating respectively 1000 or 1 million.</p>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">## A balanced data set with 50 positives and 50 negatives</span>
<span class="va">testset1A</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_testset.html">create_testset</a></span><span class="op">(</span><span class="st">"bench"</span>, <span class="st">"b100"</span><span class="op">)</span>
<span class="co">## An imbalanced data set with 2500 positives and 7500 negatives</span>
<span class="va">testset1B</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_testset.html">create_testset</a></span><span class="op">(</span><span class="st">"bench"</span>, <span class="st">"i10k"</span><span class="op">)</span>
<span class="co">## Test data sets can be manually combined to a single set</span>
<span class="va">testset1AB</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="va">testset1A</span>, <span class="va">testset1B</span><span class="op">)</span>
<span class="co">## Multiple sets are automatically combined to a single set</span>
<span class="va">testset1C</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_testset.html">create_testset</a></span><span class="op">(</span><span class="st">"bench"</span>, <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"i10"</span>, <span class="st">"b10"</span><span class="op">)</span><span class="op">)</span></code></pre></div>
</div>
<div id="create-a-test-dataset-for-curve-evaluation" class="section level3">
<h3 class="hasAnchor">
<a href="#create-a-test-dataset-for-curve-evaluation" class="anchor"></a>Create a test dataset for curve evaluation</h3>
<p>The <code>create_testset</code> function takes predefined set names for curve evaluation. These data sets contain pre-calculated precision and recall values. The pre-calculated values must be correct so that they can be compared with the results of specified tools.</p>
<p>The following three test sets are currently available.</p>
<ul>
<li>c1</li>
<li>c2</li>
<li>c3</li>
</ul>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">## C1 test set</span>
<span class="va">testset2A</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_testset.html">create_testset</a></span><span class="op">(</span><span class="st">"curve"</span>, <span class="st">"c1"</span><span class="op">)</span>
<span class="co">## C2 test set</span>
<span class="va">testset2B</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_testset.html">create_testset</a></span><span class="op">(</span><span class="st">"curve"</span>, <span class="st">"c2"</span><span class="op">)</span>
<span class="co">## Test data sets can be manually combined to a single set</span>
<span class="va">testset2AB</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="va">testset2A</span>, <span class="va">testset2B</span><span class="op">)</span>
<span class="co">## Multiple sets are automatically combined to a single set</span>
<span class="va">testset2C</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_testset.html">create_testset</a></span><span class="op">(</span><span class="st">"curve"</span>, <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"c1"</span>, <span class="st">"c2"</span><span class="op">)</span><span class="op">)</span></code></pre></div>
</div>
</div>
<div id="benchmarking" class="section level2">
<h2 class="hasAnchor">
<a href="#benchmarking" class="anchor"></a>3. Benchmarking</h2>
<p>The <code>run_benchmark</code> function internally calls the <code>microbenchmark</code> function provided by the <a href="https://cran.r-project.org/package=microbenchmark">microbenchmark</a> package. It takes a test set and a tool set and returns the result of <code>microbenchmark</code>.</p>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">## Run microbenchmark for aut5 on b10</span>
<span class="va">testset</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_testset.html">create_testset</a></span><span class="op">(</span><span class="st">"bench"</span>, <span class="st">"b10"</span><span class="op">)</span>
<span class="va">toolset</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_toolset.html">create_toolset</a></span><span class="op">(</span>set_names <span class="op">=</span> <span class="st">"auc5"</span><span class="op">)</span>
<span class="va">res</span> <span class="op"><-</span> <span class="fu"><a href="../reference/run_benchmark.html">run_benchmark</a></span><span class="op">(</span><span class="va">testset</span>, <span class="va">toolset</span><span class="op">)</span>
<span class="va">res</span></code></pre></div>
<pre><code>## testset toolset toolname min lq mean median uq max neval
## 1 b10 auc5 AUCCalculator 1.595 2.170 4.85 2.804 3.744 14.0 5
## 2 b10 auc5 PerfMeas 0.057 0.062 55.04 0.064 0.081 274.9 5
## 3 b10 auc5 precrec 5.153 5.165 24.23 5.359 9.474 96.0 5
## 4 b10 auc5 PRROC 0.133 0.134 0.68 0.140 0.151 2.9 5
## 5 b10 auc5 ROCR 1.459 1.461 7.68 1.569 12.142 21.8 5</code></pre>
</div>
<div id="evaluation-of-precision-recall-curves" class="section level2">
<h2 class="hasAnchor">
<a href="#evaluation-of-precision-recall-curves" class="anchor"></a>4. Evaluation of Precision-Recall curves</h2>
<p>The <code>run_evalcurve</code> function evaluates Precision-Recall curves with the following five test cases.</p>
<table class="table">
<thead><tr class="header">
<th align="left">Test case</th>
<th align="left">Description</th>
</tr></thead>
<tbody>
<tr class="odd">
<td align="left">x_range</td>
<td align="left">Evaluate the range of recall values</td>
</tr>
<tr class="even">
<td align="left">y_range</td>
<td align="left">Evaluate the range of precision values</td>
</tr>
<tr class="odd">
<td align="left">fpoint</td>
<td align="left">Check the first point</td>
</tr>
<tr class="even">
<td align="left">int_pts</td>
<td align="left">Check the intermediate points</td>
</tr>
<tr class="odd">
<td align="left">epoint</td>
<td align="left">Check the end point</td>
</tr>
</tbody>
</table>
<div id="evaluation-scores" class="section level3">
<h3 class="hasAnchor">
<a href="#evaluation-scores" class="anchor"></a>Evaluation scores</h3>
<p>The <code>run_evalcurve</code> function calculates the scores of the test cases and summarizes them to a data frame.</p>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">## Evaluate Precision-Recall curves for ROCR and precrec with c1 test set</span>
<span class="va">testset</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_testset.html">create_testset</a></span><span class="op">(</span><span class="st">"curve"</span>, <span class="st">"c1"</span><span class="op">)</span>
<span class="va">toolset</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_toolset.html">create_toolset</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"ROCR"</span>, <span class="st">"precrec"</span><span class="op">)</span><span class="op">)</span>
<span class="va">scores</span> <span class="op"><-</span> <span class="fu"><a href="../reference/run_evalcurve.html">run_evalcurve</a></span><span class="op">(</span><span class="va">testset</span>, <span class="va">toolset</span><span class="op">)</span>
<span class="va">scores</span></code></pre></div>
<pre><code>## testset toolset toolname score
## 1 c1 precrec precrec 8/8
## 2 c1 ROCR ROCR 5/8</code></pre>
<p>The result of each test case can be displayed by specifying <code>data_type</code> = <code>all</code> of the <code>print</code> function.</p>
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">## Print all results</span>
<span class="fu"><a href="https://rdrr.io/r/base/print.html">print</a></span><span class="op">(</span><span class="va">scores</span>, data_type <span class="op">=</span> <span class="st">"all"</span><span class="op">)</span></code></pre></div>
<pre><code>## testset toolset toolname testitem testcat success total
## 1 c1 precrec precrec x_range Rg 1 1
## 2 c1 precrec precrec y_range Rg 1 1
## 3 c1 precrec precrec fpoint SE 1 1
## 4 c1 precrec precrec intpts Ip 4 4
## 5 c1 precrec precrec epoint SE 1 1
## 6 c1 ROCR ROCR x_range Rg 1 1
## 7 c1 ROCR ROCR y_range Rg 1 1
## 8 c1 ROCR ROCR fpoint SE 0 1
## 9 c1 ROCR ROCR intpts Ip 2 4
## 10 c1 ROCR ROCR epoint SE 1 1</code></pre>
</div>
<div id="visualization-of-the-result" class="section level3">
<h3 class="hasAnchor">
<a href="#visualization-of-the-result" class="anchor"></a>Visualization of the result</h3>
<p>The <code>autoplot</code> shows a plot with the result of the <code>run_evalcurve</code> function.</p>
<div class="sourceCode" id="cb12"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">## ggplot2 is necessary to use autoplot</span>
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://ggplot2.tidyverse.org">ggplot2</a></span><span class="op">)</span>
<span class="co">## Plot base points and the result of precrec on c1, c2, and c3 test sets</span>
<span class="va">testset</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_testset.html">create_testset</a></span><span class="op">(</span><span class="st">"curve"</span>, <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"c1"</span>, <span class="st">"c2"</span>, <span class="st">"c3"</span><span class="op">)</span><span class="op">)</span>
<span class="va">toolset</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_toolset.html">create_toolset</a></span><span class="op">(</span><span class="st">"precrec"</span><span class="op">)</span>
<span class="va">scores1</span> <span class="op"><-</span> <span class="fu"><a href="../reference/run_evalcurve.html">run_evalcurve</a></span><span class="op">(</span><span class="va">testset</span>, <span class="va">toolset</span><span class="op">)</span>
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/autoplot.html">autoplot</a></span><span class="op">(</span><span class="va">scores1</span><span class="op">)</span>
<span class="co">## Plot the results of PerfMeas and PRROC on c1, c2, and c3 test sets</span>
<span class="va">toolset</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_toolset.html">create_toolset</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"PerfMeas"</span>, <span class="st">"PRROC"</span><span class="op">)</span><span class="op">)</span>
<span class="va">scores2</span> <span class="op"><-</span> <span class="fu"><a href="../reference/run_evalcurve.html">run_evalcurve</a></span><span class="op">(</span><span class="va">testset</span>, <span class="va">toolset</span><span class="op">)</span>
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/autoplot.html">autoplot</a></span><span class="op">(</span><span class="va">scores2</span>, base_plot <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></code></pre></div>
<p><img src="introduction_files/figure-html/unnamed-chunk-9-1.png" width="672"><img src="introduction_files/figure-html/unnamed-chunk-9-2.png" width="672"></p>
</div>
</div>
<div id="create-a-user-defined-tool-interface" class="section level2">
<h2 class="hasAnchor">
<a href="#create-a-user-defined-tool-interface" class="anchor"></a>5. Create a user-defined tool interface</h2>
<p>In addition to the predefined five tools, users can add new tool interfaces for their own tools to run benchmarking and curve evaluation. The <code>create_usrtool</code> function takes a name of the tool and a function for calculating a Precision-Recall curve.</p>
<div class="sourceCode" id="cb13"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">## Create a new tool set for 'xyz' </span>
<span class="va">toolname</span> <span class="op"><-</span> <span class="st">"xyz"</span>
<span class="va">calcfunc</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_example_func.html">create_example_func</a></span><span class="op">(</span><span class="op">)</span>
<span class="va">toolsetU</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_usrtool.html">create_usrtool</a></span><span class="op">(</span><span class="va">toolname</span>, <span class="va">calcfunc</span><span class="op">)</span>
<span class="co">## User-defined tools can be combined with predefined tools</span>
<span class="va">toolsetA</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_toolset.html">create_toolset</a></span><span class="op">(</span><span class="st">"ROCR"</span><span class="op">)</span>
<span class="va">toolsetU2</span> <span class="op"><-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="va">toolsetA</span>, <span class="va">toolsetU</span><span class="op">)</span></code></pre></div>
<p>Like the predefined tool sets, user-defined tool sets can be used for both <code>run_benchmark</code> and <code>run_evalcurve</code>.</p>
<div class="sourceCode" id="cb14"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">## Curve evaluation</span>
<span class="va">testset3</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_testset.html">create_testset</a></span><span class="op">(</span><span class="st">"curve"</span>, <span class="st">"c2"</span><span class="op">)</span>
<span class="va">scores3</span> <span class="op"><-</span> <span class="fu"><a href="../reference/run_evalcurve.html">run_evalcurve</a></span><span class="op">(</span><span class="va">testset3</span>, <span class="va">toolsetU2</span><span class="op">)</span>
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/autoplot.html">autoplot</a></span><span class="op">(</span><span class="va">scores3</span>, base_plot <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></code></pre></div>
<p><img src="introduction_files/figure-html/unnamed-chunk-11-1.png" width="672"></p>
<div id="the-format-of-the-function-for-calculating-a-precision-recall-curve" class="section level3">
<h3 class="hasAnchor">
<a href="#the-format-of-the-function-for-calculating-a-precision-recall-curve" class="anchor"></a>The format of the function for calculating a Precision-Recall curve</h3>
<p>The <code>create_example_func</code> function creates an example for the second argument of the <code>create_usrtool</code> function. The actual function should also take a <code>testset</code> generated by the <code>create_testset</code> function and returns a list with three elements - <code>x</code>, <code>y</code>, and <code>auc</code>.</p>
<div class="sourceCode" id="cb15"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">## Show an example of the second argument</span>
<span class="va">calcfunc</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_example_func.html">create_example_func</a></span><span class="op">(</span><span class="op">)</span>
<span class="fu"><a href="https://rdrr.io/r/base/print.html">print</a></span><span class="op">(</span><span class="va">calcfunc</span><span class="op">)</span></code></pre></div>
<pre><code>## function (single_testset)
## {
## scores <- single_testset$get_scores()
## labels <- single_testset$get_labels()
## pred <- list(x = seq(0, 1, 1/length(scores)), y = seq(0,
## 1, 1/length(scores)), auc = 0.5)
## }
## <bytecode: 0x562e3843a998>
## <environment: 0x562e383002f0></code></pre>
<p>The <code>create_testset</code> function produces a <code>testset</code> as either <code>TestDataB</code> or <code>TestDataC</code> object. See the help files of the R6 classes - <code><a href="../reference/TestDataB.html">help(TestDataB)</a></code> and <code><a href="../reference/TestDataC.html">help(TestDataC)</a></code> - for the methods that can be used with the Precision-Recall calculation.</p>
</div>
</div>
<div id="create-a-user-defined-test-data-interface" class="section level2">
<h2 class="hasAnchor">
<a href="#create-a-user-defined-test-data-interface" class="anchor"></a>6. Create a user-defined test data interface</h2>
<p>The <code>prcbench</code> package also supports user-defined test data interfaces. The <code>create_usrdata</code> function creates two types of test datasets.</p>
<div id="create-a-user-defined-test-dataset-for-benchmarking" class="section level3">
<h3 class="hasAnchor">
<a href="#create-a-user-defined-test-dataset-for-benchmarking" class="anchor"></a>Create a user-defined test dataset for benchmarking</h3>
<p>The first argument of the <code>create_usrdata</code> function should be “bench” to create a test data for benchmarking. Additionally, scores and labels are required.</p>
<div class="sourceCode" id="cb17"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">## Create a test dataset 'b5' for benchmarking</span>
<span class="va">testsetB</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_usrdata.html">create_usrdata</a></span><span class="op">(</span><span class="st">"bench"</span>, scores <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0.1</span>, <span class="fl">0.2</span><span class="op">)</span>, labels <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">1</span>, <span class="fl">0</span><span class="op">)</span>,
tsname <span class="op">=</span> <span class="st">"b5"</span><span class="op">)</span></code></pre></div>
<p>It can be used in the same way as the predefined test datasets for benchmarking.</p>
<div class="sourceCode" id="cb18"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">## Run microbenchmark for ROCR and precrec on a predefined test dataset</span>
<span class="va">toolset</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_toolset.html">create_toolset</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"ROCR"</span>, <span class="st">"precrec"</span><span class="op">)</span><span class="op">)</span>
<span class="va">res</span> <span class="op"><-</span> <span class="fu"><a href="../reference/run_benchmark.html">run_benchmark</a></span><span class="op">(</span><span class="va">testsetB</span>, <span class="va">toolset</span><span class="op">)</span>
<span class="va">res</span></code></pre></div>
<pre><code>## testset toolset toolname min lq mean median uq max neval
## 1 b5 precrec precrec 3.9 3.9 4.2 3.9 4.1 5.2 5
## 2 b5 ROCR ROCR 1.5 1.5 1.5 1.5 1.5 1.7 5</code></pre>
</div>
<div id="create-a-user-defined-test-dataset-for-curve-evaluation" class="section level3">
<h3 class="hasAnchor">
<a href="#create-a-user-defined-test-dataset-for-curve-evaluation" class="anchor"></a>Create a user-defined test dataset for curve evaluation</h3>
<p>The first argument of the <code>create_usrdata</code> function should be “curve” to create a test dataset for curve evaluation. Scores and labels as well as pre-calculated recall and precision values are required. These pre-calculated values are used to compare with the corresponding values predicted by the specified tools.</p>
<div class="sourceCode" id="cb20"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">## Create a test dataset 'c5' for benchmarking</span>
<span class="va">testsetC</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_usrdata.html">create_usrdata</a></span><span class="op">(</span><span class="st">"curve"</span>, scores <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0.1</span>, <span class="fl">0.2</span><span class="op">)</span>, labels <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">1</span>, <span class="fl">0</span><span class="op">)</span>,
tsname <span class="op">=</span> <span class="st">"c5"</span>, base_x <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0.0</span>, <span class="fl">1.0</span><span class="op">)</span>,
base_y <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">0.0</span>, <span class="fl">0.5</span><span class="op">)</span><span class="op">)</span></code></pre></div>
<p>It can be used in the same way as the predefined test datasets for curve evaluation.</p>
<div class="sourceCode" id="cb21"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co">## Run curve evaluation for ROCR and precrec on a predefined test dataset</span>
<span class="va">toolset2</span> <span class="op"><-</span> <span class="fu"><a href="../reference/create_toolset.html">create_toolset</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"ROCR"</span>, <span class="st">"precrec"</span><span class="op">)</span><span class="op">)</span>
<span class="va">scores2</span> <span class="op"><-</span> <span class="fu"><a href="../reference/run_evalcurve.html">run_evalcurve</a></span><span class="op">(</span><span class="va">testsetC</span>, <span class="va">toolset2</span><span class="op">)</span>
<span class="fu"><a href="https://ggplot2.tidyverse.org/reference/autoplot.html">autoplot</a></span><span class="op">(</span><span class="va">scores2</span>, base_plot <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></code></pre></div>
<p><img src="introduction_files/figure-html/unnamed-chunk-16-1.png" width="672"></p>
</div>
</div>
<div id="external-links" class="section level2">
<h2 class="hasAnchor">
<a href="#external-links" class="anchor"></a>7. External links</h2>
<p>See our website - <a href="https://classeval.wordpress.com/">Classifier evaluation with imbalanced datasets</a> – for useful tips for performance evaluation on binary classifiers. In addition, we have summarized potential pitfalls of ROC plots with imbalanced datasets. See our paper – <a href="https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0118432">The Precision-Recall Plot Is More Informative than the ROC Plot When Evaluating Binary Classifiers on Imbalanced Datasets</a> - for more details.</p>
</div>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
<nav id="toc" data-toggle="toc"><h2 data-toc-skip>Contents</h2>
</nav>
</div>
</div>
<footer><div class="copyright">
<p>Developed by Takaya Saito, Marc Rehmsmeier.</p>
</div>
<div class="pkgdown">
<p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.6.1.</p>
</div>
</footer>
</div>
</body>
</html>