Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

index.html 47 KB

You have to be logged in to leave a comment. Sign In
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
  6. <meta name="generator" content="pdoc 0.10.0" />
  7. <link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
  8. <link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
  9. <link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
  10. <style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
  11. <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
  12. <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
  13. <script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
  14. <script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
  15. </head>
  16. <body>
  17. <main>
  18. <article id="content">
  19. <section id="section-intro">
  20. <p align="center">
  21. <img align="center" width=60% src="https://csinva.io/imodels/img/imodels_logo.svg?sanitize=True&kill_cache=1"> </img>
  22. <br/>
  23. Python package for concise, transparent, and accurate predictive modeling. <br/>
  24. All sklearn-compatible and easy to use. <br/>
  25. <i> For interpretability in NLP, check out our new package: <a href="https://github.com/csinva/imodelsX">imodelsX</a> </i>
  26. </p>
  27. <p align="center">
  28. <a href="https://csinva.github.io/imodels/">📚 docs</a> •
  29. <a href="#demo-notebooks">📖 demo notebooks</a>
  30. </p>
  31. <p align="center">
  32. <img src="https://img.shields.io/badge/license-mit-blue.svg">
  33. <img src="https://img.shields.io/badge/python-3.9--3.11-blue">
  34. <a href="https://doi.org/10.21105/joss.03192"><img src="https://joss.theoj.org/papers/10.21105/joss.03192/status.svg"></a>
  35. <a href="https://github.com/csinva/imodels/actions"><img src="https://github.com/csinva/imodels/workflows/tests/badge.svg"></a>
  36. <!--img src="https://img.shields.io/github/checks-status/csinva/imodels/master"-->
  37. <img src="https://img.shields.io/pypi/v/imodels?color=orange">
  38. <img src="https://static.pepy.tech/personalized-badge/imodels?period=total&units=none&left_color=gray&right_color=orange&left_text=downloads&kill_cache=12">
  39. </p>
  40. <p><img align="center" width=100% src="https://csinva.io/imodels/img/anim.gif"> </img></p>
  41. <p>Modern machine-learning models are increasingly complex, often making them difficult to interpret. This package provides a simple interface for fitting and using state-of-the-art interpretable models, all compatible with scikit-learn. These models can often replace black-box models (e.g. random forests) with simpler models (e.g. rule lists) while improving interpretability and computational efficiency, all without sacrificing predictive accuracy! Simply import a classifier or regressor and use the <code>fit</code> and <code>predict</code> methods, same as standard scikit-learn models.</p>
  42. <pre><code class="language-python">from sklearn.model_selection import train_test_split
  43. from imodels import get_clean_dataset, HSTreeClassifierCV # import any imodels model here
  44. # prepare data (a sample clinical dataset)
  45. X, y, feature_names = get_clean_dataset('csi_pecarn_pred')
  46. X_train, X_test, y_train, y_test = train_test_split(
  47. X, y, random_state=42)
  48. # fit the model
  49. model = HSTreeClassifierCV(max_leaf_nodes=4) # initialize a tree model and specify only 4 leaf nodes
  50. model.fit(X_train, y_train, feature_names=feature_names) # fit model
  51. preds = model.predict(X_test) # discrete predictions: shape is (n_test, 1)
  52. preds_proba = model.predict_proba(X_test) # predicted probabilities: shape is (n_test, n_classes)
  53. print(model) # print the model
  54. </code></pre>
  55. <pre><code>------------------------------
  56. Decision Tree with Hierarchical Shrinkage
  57. Prediction is made by looking at the value in the appropriate leaf of the tree
  58. ------------------------------
  59. |--- FocalNeuroFindings2 &lt;= 0.50
  60. | |--- HighriskDiving &lt;= 0.50
  61. | | |--- Torticollis2 &lt;= 0.50
  62. | | | |--- value: [0.10]
  63. | | |--- Torticollis2 &gt; 0.50
  64. | | | |--- value: [0.30]
  65. | |--- HighriskDiving &gt; 0.50
  66. | | |--- value: [0.68]
  67. |--- FocalNeuroFindings2 &gt; 0.50
  68. | |--- value: [0.42]
  69. </code></pre>
  70. <h3 id="installation">Installation</h3>
  71. <p>Install with <code>pip install <a title="imodels" href="#imodels">imodels</a></code> (see <a href="https://github.com/csinva/imodels/blob/master/docs/troubleshooting.md">here</a> for help).</p>
  72. <h3 id="supported-models">Supported models</h3>
  73. <table>
  74. <thead>
  75. <tr>
  76. <th style="text-align: left;">Model</th>
  77. <th>Reference</th>
  78. <th>Description</th>
  79. </tr>
  80. </thead>
  81. <tbody>
  82. <tr>
  83. <td style="text-align: left;">Rulefit rule set</td>
  84. <td><a href="https://csinva.io/imodels/rule_set/rule_fit.html">🗂️</a>, <a href="https://github.com/christophM/rulefit">🔗</a>, <a href="http://statweb.stanford.edu/~jhf/ftp/RuleFit.pdf">📄</a></td>
  85. <td>Fits a sparse linear model on rules extracted from decision trees</td>
  86. </tr>
  87. <tr>
  88. <td style="text-align: left;">Skope rule set</td>
  89. <td><a href="https://csinva.io/imodels/rule_set/skope_rules.html#imodels.rule_set.skope_rules.SkopeRulesClassifier">🗂️</a>, <a href="https://github.com/scikit-learn-contrib/skope-rules">🔗</a></td>
  90. <td>Extracts rules from gradient-boosted trees, deduplicates them,<br/>then linearly combines them based on their OOB precision</td>
  91. </tr>
  92. <tr>
  93. <td style="text-align: left;">Boosted rule set</td>
  94. <td><a href="https://csinva.io/imodels/rule_set/boosted_rules.html">🗂️</a>, <a href="https://github.com/jaimeps/adaboost-implementation">🔗</a>, <a href="https://www.sciencedirect.com/science/article/pii/S002200009791504X">📄</a></td>
  95. <td>Sequentially fits a set of rules with Adaboost</td>
  96. </tr>
  97. <tr>
  98. <td style="text-align: left;">Slipper rule set</td>
  99. <td><a href="https://csinva.io/imodels/rule_set/slipper.html">🗂️</a>, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;, ㅤㅤ<a href="https://www.aaai.org/Papers/AAAI/1999/AAAI99-049.pdf">📄</a></td>
  100. <td>Sequentially learns a set of rules with SLIPPER</td>
  101. </tr>
  102. <tr>
  103. <td style="text-align: left;">Bayesian rule set</td>
  104. <td><a href="https://csinva.io/imodels/rule_set/brs.html#imodels.rule_set.brs.BayesianRuleSetClassifier">🗂️</a>, <a href="https://github.com/wangtongada/BOA">🔗</a>, <a href="https://www.jmlr.org/papers/volume18/16-003/16-003.pdf">📄</a></td>
  105. <td>Finds concise rule set with Bayesian sampling (slow)</td>
  106. </tr>
  107. <tr>
  108. <td style="text-align: left;">Optimal rule list</td>
  109. <td><a href="https://csinva.io/imodels/rule_list/corels_wrapper.html#imodels.rule_list.corels_wrapper.OptimalRuleListClassifier">🗂️</a>, <a href="https://github.com/corels/pycorels">🔗</a>, <a href="https://www.jmlr.org/papers/volume18/17-716/17-716.pdf">📄</a></td>
  110. <td>Fits rule list using global optimization for sparsity (CORELS)</td>
  111. </tr>
  112. <tr>
  113. <td style="text-align: left;">Bayesian rule list</td>
  114. <td><a href="https://csinva.io/imodels/rule_list/bayesian_rule_list/bayesian_rule_list.html#imodels.rule_list.bayesian_rule_list.bayesian_rule_list.BayesianRuleListClassifier">🗂️</a>, <a href="https://github.com/tmadl/sklearn-expertsys">🔗</a>, <a href="https://arxiv.org/abs/1602.08610">📄</a></td>
  115. <td>Fits compact rule list distribution with Bayesian sampling (slow)</td>
  116. </tr>
  117. <tr>
  118. <td style="text-align: left;">Greedy rule list</td>
  119. <td><a href="https://csinva.io/imodels/rule_list/greedy_rule_list.html">🗂️</a>, <a href="https://medium.com/@penggongting/implementing-decision-tree-from-scratch-in-python-c732e7c69aea">🔗</a></td>
  120. <td>Uses CART to fit a list (only a single path), rather than a tree</td>
  121. </tr>
  122. <tr>
  123. <td style="text-align: left;">OneR rule list</td>
  124. <td><a href="https://csinva.io/imodels/rule_list/one_r.html">🗂️</a>, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;, <a href="https://link.springer.com/article/10.1023/A:1022631118932">📄</a></td>
  125. <td>Fits rule list restricted to only one feature</td>
  126. </tr>
  127. <tr>
  128. <td style="text-align: left;">Optimal rule tree</td>
  129. <td><a href="https://csinva.io/imodels/tree/gosdt/pygosdt.html#imodels.tree.gosdt.pygosdt.OptimalTreeClassifier">🗂️</a>, <a href="https://github.com/Jimmy-Lin/GeneralizedOptimalSparseDecisionTrees">🔗</a>, <a href="https://arxiv.org/abs/2006.08690">📄</a></td>
  130. <td>Fits succinct tree using global optimization for sparsity (GOSDT)</td>
  131. </tr>
  132. <tr>
  133. <td style="text-align: left;">Greedy rule tree</td>
  134. <td><a href="https://csinva.io/imodels/tree/cart_wrapper.html">🗂️</a>, <a href="https://scikit-learn.org/stable/modules/tree.html">🔗</a>, <a href="https://www.taylorfrancis.com/books/mono/10.1201/9781315139470/classification-regression-trees-leo-breiman-jerome-friedman-richard-olshen-charles-stone">📄</a></td>
  135. <td>Greedily fits tree using CART</td>
  136. </tr>
  137. <tr>
  138. <td style="text-align: left;">C4.5 rule tree</td>
  139. <td><a href="https://csinva.io/imodels/tree/c45_tree/c45_tree.html#imodels.tree.c45_tree.c45_tree.C45TreeClassifier">🗂️</a>, <a href="https://github.com/RaczeQ/scikit-learn-C4.5-tree-classifier">🔗</a>, <a href="https://link.springer.com/article/10.1007/BF00993309">📄</a></td>
  140. <td>Greedily fits tree using C4.5</td>
  141. </tr>
  142. <tr>
  143. <td style="text-align: left;">TAO rule tree</td>
  144. <td><a href="https://csinva.io/imodels/tree/tao.html">🗂️</a>, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;, ㅤㅤ<a href="https://proceedings.neurips.cc/paper/2018/hash/185c29dc24325934ee377cfda20e414c-Abstract.html">📄</a></td>
  145. <td>Fits tree using alternating optimization</td>
  146. </tr>
  147. <tr>
  148. <td style="text-align: left;">Iterative random<br/>forest</td>
  149. <td><a href="https://csinva.io/imodels/tree/iterative_random_forest/iterative_random_forest.html">🗂️</a>, <a href="https://github.com/Yu-Group/iterative-Random-Forest">🔗</a>, <a href="https://www.pnas.org/content/115/8/1943">📄</a></td>
  150. <td>Repeatedly fit random forest, giving features with<br/>high importance a higher chance of being selected</td>
  151. </tr>
  152. <tr>
  153. <td style="text-align: left;">Sparse integer<br/>linear model</td>
  154. <td><a href="https://csinva.io/imodels/algebraic/slim.html">🗂️</a>, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;, ㅤㅤ<a href="https://link.springer.com/article/10.1007/s10994-015-5528-6">📄</a></td>
  155. <td>Sparse linear model with integer coefficients</td>
  156. </tr>
  157. <tr>
  158. <td style="text-align: left;">Tree GAM</td>
  159. <td><a href="https://csinva.io/imodels/algebraic/tree_gam.html">🗂️</a>, <a href="https://github.com/interpretml/interpret">🔗</a>, <a href="https://dl.acm.org/doi/abs/10.1145/2339530.2339556">📄</a></td>
  160. <td>Generalized additive model fit with short boosted trees</td>
  161. </tr>
  162. <tr>
  163. <td style="text-align: left;"><b>Greedy tree sums</b></td>
  164. <td><a href="https://csinva.io/imodels/tree/figs.html#imodels.tree.figs">🗂️</a>, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;, ㅤㅤ<a href="https://arxiv.org/abs/2201.11931">📄</a></td>
  165. <td>Sum of small trees with very few total rules (FIGS)</td>
  166. </tr>
  167. <tr>
  168. <td style="text-align: left;"><b>Hierarchical<br/> shrinkage wrapper</b></td>
  169. <td><a href="https://csinva.io/imodels/tree/hierarchical_shrinkage.html">🗂️</a>, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;, ㅤㅤ<a href="https://arxiv.org/abs/2202.00858">📄</a></td>
  170. <td>Improve a decision tree, random forest, or<br/>gradient-boosting ensemble with ultra-fast, post-hoc regularization</td>
  171. </tr>
  172. <tr>
  173. <td style="text-align: left;">Distillation<br/>wrapper</td>
  174. <td><a href="https://csinva.io/imodels/util/distillation.html">🗂️</a></td>
  175. <td>Train a black-box model,<br/>then distill it into an interpretable model</td>
  176. </tr>
  177. <tr>
  178. <td style="text-align: left;">AutoML wrapper</td>
  179. <td><a href="https://csinva.io/imodels/util/automl.html">🗂️</a></td>
  180. <td>Automatically fit and select an interpretable model</td>
  181. </tr>
  182. <tr>
  183. <td style="text-align: left;">More models</td>
  184. <td>⌛</td>
  185. <td>(Coming soon!) Lightweight Rule Induction, MLRules, &hellip;</td>
  186. </tr>
  187. </tbody>
  188. </table>
  189. <p align="center">
  190. Docs <a href="https://csinva.io/imodels/">🗂️</a>, Reference code implementation 🔗, Research paper 📄
  191. </br>
  192. </p>
  193. <h2 id="demo-notebooks">Demo notebooks</h2>
  194. <p>Demos are contained in the <a href="notebooks">notebooks</a> folder.</p>
  195. <details>
  196. <summary><a href="https://github.com/csinva/imodels/blob/master/notebooks/imodels_demo.ipynb">Quickstart demo</a></summary>
  197. Shows how to fit, predict, and visualize with different interpretable models
  198. </details>
  199. <details>
  200. <summary><a href="https://auto.gluon.ai/dev/tutorials/tabular_prediction/tabular-interpretability.html">Autogluon demo</a></summary>
  201. Fit/select an interpretable model automatically using Autogluon AutoML
  202. </details>
  203. <details>
  204. <summary><a href="https://colab.research.google.com/drive/1WfqvSjegygT7p0gyqiWpRpiwz2ePtiao#scrollTo=bLnLknIuoWtQ">Quickstart colab demo</a> <a href="https://colab.research.google.com/drive/1WfqvSjegygT7p0gyqiWpRpiwz2ePtiao#scrollTo=bLnLknIuoWtQ"> <img src="https://colab.research.google.com/assets/colab-badge.svg"></a></summary>
  205. Shows how to fit, predict, and visualize with different interpretable models
  206. </details>
  207. <details>
  208. <summary><a href="https://github.com/csinva/iai-clinical-decision-rule/blob/master/notebooks/05_fit_interpretable_models.ipynb">Clinical decision rule notebook</a></summary>
  209. Shows an example of using <code>imodels</code> for deriving a clinical decision rule
  210. </details>
  211. <details>
  212. <summary>Posthoc analysis</summary>
  213. We also include some demos of posthoc analysis, which occurs after fitting models:
  214. <a href="https://github.com/csinva/imodels/blob/master/notebooks/posthoc_analysis.ipynb">posthoc.ipynb</a> shows different simple analyses to interpret a trained model and
  215. <a href="https://github.com/csinva/imodels/blob/master/notebooks/uncertainty_analysis.ipynb">uncertainty.ipynb</a> contains basic code to get uncertainty estimates for a model
  216. </details>
  217. <h2 id="whats-the-difference-between-the-models">What's the difference between the models?</h2>
  218. <p>The final form of the above models takes one of the following forms, which aim to be simultaneously simple to understand and highly predictive:</p>
  219. <table>
  220. <thead>
  221. <tr>
  222. <th style="text-align: center;">Rule set</th>
  223. <th style="text-align: center;">Rule list</th>
  224. <th style="text-align: center;">Rule tree</th>
  225. <th style="text-align: center;">Algebraic models</th>
  226. </tr>
  227. </thead>
  228. <tbody>
  229. <tr>
  230. <td style="text-align: center;"><img src="https://csinva.io/imodels/img/rule_set.jpg" width="100%"></td>
  231. <td style="text-align: center;"><img src="https://csinva.io/imodels/img/rule_list.jpg"></td>
  232. <td style="text-align: center;"><img src="https://csinva.io/imodels/img/rule_tree.jpg"></td>
  233. <td style="text-align: center;"><img src="https://csinva.io/imodels/img/algebraic_models.jpg"></td>
  234. </tr>
  235. </tbody>
  236. </table>
  237. <p>Different models and algorithms vary not only in their final form but also in different choices made during modeling, such as how they generate, select, and postprocess rules:</p>
  238. <table>
  239. <thead>
  240. <tr>
  241. <th style="text-align: center;">Rule candidate generation</th>
  242. <th style="text-align: center;">Rule selection</th>
  243. <th style="text-align: center;">Rule postprocessing</th>
  244. </tr>
  245. </thead>
  246. <tbody>
  247. <tr>
  248. <td style="text-align: center;"><img src="https://csinva.io/imodels/img/rule_candidates.jpg"></td>
  249. <td style="text-align: center;"><img src="https://csinva.io/imodels/img/rule_overfit.jpg"></td>
  250. <td style="text-align: center;"><img src="https://csinva.io/imodels/img/rule_pruned.jpg"></td>
  251. </tr>
  252. </tbody>
  253. </table>
  254. <details>
  255. <summary>Ex. RuleFit vs. SkopeRules</summary>
  256. RuleFit and SkopeRules differ only in the way they prune rules: RuleFit uses a linear model whereas SkopeRules heuristically deduplicates rules sharing overlap.
  257. </details>
  258. <details>
  259. <summary>Ex. Bayesian rule lists vs. greedy rule lists</summary>
  260. Bayesian rule lists and greedy rule lists differ in how they select rules; bayesian rule lists perform a global optimization over possible rule lists while Greedy rule lists pick splits sequentially to maximize a given criterion.
  261. </details>
  262. <details>
  263. <summary>Ex. FPSkope vs. SkopeRules</summary>
  264. FPSkope and SkopeRules differ only in the way they generate candidate rules: FPSkope uses FPgrowth whereas SkopeRules extracts rules from decision trees.
  265. </details>
  266. <h2 id="support-for-different-tasks">Support for different tasks</h2>
  267. <p>Different models support different machine-learning tasks. Current support for different models is given below (each of these models can be imported directly from imodels (e.g. <code>from <a title="imodels" href="#imodels">imodels</a> import RuleFitClassifier</code>):</p>
  268. <table>
  269. <thead>
  270. <tr>
  271. <th style="text-align: left;">Model</th>
  272. <th style="text-align: center;">Binary classification</th>
  273. <th style="text-align: center;">Regression</th>
  274. <th>Notes</th>
  275. </tr>
  276. </thead>
  277. <tbody>
  278. <tr>
  279. <td style="text-align: left;">Rulefit rule set</td>
  280. <td style="text-align: center;"><a href="https://csinva.io/imodels/rule_set/rule_fit.html#imodels.rule_set.rule_fit.RuleFitClassifier">RuleFitClassifier</a></td>
  281. <td style="text-align: center;"><a href="https://csinva.io/imodels/rule_set/rule_fit.html#imodels.rule_set.rule_fit.RuleFitRegressor">RuleFitRegressor</a></td>
  282. <td></td>
  283. </tr>
  284. <tr>
  285. <td style="text-align: left;">Skope rule set</td>
  286. <td style="text-align: center;"><a href="https://csinva.io/imodels/rule_set/skope_rules.html#imodels.rule_set.skope_rules.SkopeRulesClassifier">SkopeRulesClassifier</a></td>
  287. <td style="text-align: center;"></td>
  288. <td></td>
  289. </tr>
  290. <tr>
  291. <td style="text-align: left;">Boosted rule set</td>
  292. <td style="text-align: center;"><a href="https://csinva.io/imodels/rule_set/boosted_rules.html#imodels.rule_set.boosted_rules.BoostedRulesClassifier">BoostedRulesClassifier</a></td>
  293. <td style="text-align: center;"><a href="https://csinva.io/imodels/rule_set/boosted_rules.html#imodels.rule_set.boosted_rules.BoostedRulesRegressor">BoostedRulesRegressor</a></td>
  294. <td></td>
  295. </tr>
  296. <tr>
  297. <td style="text-align: left;">SLIPPER rule set</td>
  298. <td style="text-align: center;"><a href="https://csinva.io/imodels/rule_set/slipper.html#imodels.rule_set.slipper.SlipperClassifier">SlipperClassifier</a></td>
  299. <td style="text-align: center;"></td>
  300. <td></td>
  301. </tr>
  302. <tr>
  303. <td style="text-align: left;">Bayesian rule set</td>
  304. <td style="text-align: center;"><a href="https://csinva.io/imodels/rule_set/brs.html#imodels.rule_set.brs.BayesianRuleSetClassifier">BayesianRuleSetClassifier</a></td>
  305. <td style="text-align: center;"></td>
  306. <td>Fails for large problems</td>
  307. </tr>
  308. <tr>
  309. <td style="text-align: left;">Optimal rule list (CORELS)</td>
  310. <td style="text-align: center;"><a href="https://csinva.io/imodels/rule_list/corels_wrapper.html#imodels.rule_list.corels_wrapper.OptimalRuleListClassifier">OptimalRuleListClassifier</a></td>
  311. <td style="text-align: center;"></td>
  312. <td>Requires <a href="https://pypi.org/project/corels/">corels</a>, fails for large problems</td>
  313. </tr>
  314. <tr>
  315. <td style="text-align: left;">Bayesian rule list</td>
  316. <td style="text-align: center;"><a href="https://csinva.io/imodels/rule_list/bayesian_rule_list/bayesian_rule_list.html#imodels.rule_list.bayesian_rule_list.bayesian_rule_list.BayesianRuleListClassifier">BayesianRuleListClassifier</a></td>
  317. <td style="text-align: center;"></td>
  318. <td></td>
  319. </tr>
  320. <tr>
  321. <td style="text-align: left;">Greedy rule list</td>
  322. <td style="text-align: center;"><a href="https://csinva.io/imodels/rule_list/greedy_rule_list.html#imodels.rule_list.greedy_rule_list.GreedyRuleListClassifier">GreedyRuleListClassifier</a></td>
  323. <td style="text-align: center;"></td>
  324. <td></td>
  325. </tr>
  326. <tr>
  327. <td style="text-align: left;">OneR rule list</td>
  328. <td style="text-align: center;"><a href="https://csinva.io/imodels/rule_list/one_r.html#imodels.rule_list.one_r.OneRClassifier">OneRClassifier</a></td>
  329. <td style="text-align: center;"></td>
  330. <td></td>
  331. </tr>
  332. <tr>
  333. <td style="text-align: left;">Optimal rule tree (GOSDT)</td>
  334. <td style="text-align: center;"><a href="https://csinva.io/imodels/tree/gosdt/pygosdt.html#imodels.tree.gosdt.pygosdt.OptimalTreeClassifier">OptimalTreeClassifier</a></td>
  335. <td style="text-align: center;"></td>
  336. <td>Requires <a href="https://pypi.org/project/gosdt/">gosdt</a>, fails for large problems</td>
  337. </tr>
  338. <tr>
  339. <td style="text-align: left;">Greedy rule tree (CART)</td>
  340. <td style="text-align: center;"><a href="https://csinva.io/imodels/tree/cart_wrapper.html#imodels.tree.cart_wrapper.GreedyTreeClassifier">GreedyTreeClassifier</a></td>
  341. <td style="text-align: center;"><a href="https://csinva.io/imodels/tree/cart_wrapper.html#imodels.tree.cart_wrapper.GreedyTreeRegressor">GreedyTreeRegressor</a></td>
  342. <td></td>
  343. </tr>
  344. <tr>
  345. <td style="text-align: left;">C4.5 rule tree</td>
  346. <td style="text-align: center;"><a href="https://csinva.io/imodels/tree/c45_tree/c45_tree.html#imodels.tree.c45_tree.c45_tree.C45TreeClassifier">C45TreeClassifier</a></td>
  347. <td style="text-align: center;"></td>
  348. <td></td>
  349. </tr>
  350. <tr>
  351. <td style="text-align: left;">TAO rule tree</td>
  352. <td style="text-align: center;"><a href="https://csinva.io/imodels/tree/tao.html#imodels.tree.tao.TaoTreeClassifier">TaoTreeClassifier</a></td>
  353. <td style="text-align: center;"><a href="https://csinva.io/imodels/tree/tao.html#imodels.tree.tao.TaoTreeRegressor">TaoTreeRegressor</a></td>
  354. <td></td>
  355. </tr>
  356. <tr>
  357. <td style="text-align: left;">Iterative random forest</td>
  358. <td style="text-align: center;"><a href="https://csinva.io/imodels/tree/iterative_random_forest/iterative_random_forest.html#imodels.tree.iterative_random_forest.iterative_random_forest.IRFClassifier">IRFClassifier</a></td>
  359. <td style="text-align: center;"></td>
  360. <td>Requires <a href="https://pypi.org/project/irf/">irf</a></td>
  361. </tr>
  362. <tr>
  363. <td style="text-align: left;">Sparse integer linear model</td>
  364. <td style="text-align: center;"><a href="https://csinva.io/imodels/algebraic/slim.html#imodels.algebraic.slim.SLIMClassifier">SLIMClassifier</a></td>
  365. <td style="text-align: center;"><a href="https://csinva.io/imodels/algebraic/slim.html#imodels.algebraic.slim.SLIMRegressor">SLIMRegressor</a></td>
  366. <td>Requires extra dependencies for speed</td>
  367. </tr>
  368. <tr>
  369. <td style="text-align: left;">Tree GAM</td>
  370. <td style="text-align: center;"><a href="https://csinva.io/imodels/algebraic/tree_gam.html">TreeGAMClassifier</a></td>
  371. <td style="text-align: center;"><a href="https://csinva.io/imodels/algebraic/tree_gam.html">TreeGAMRegressor</a></td>
  372. <td></td>
  373. </tr>
  374. <tr>
  375. <td style="text-align: left;">Greedy tree sums (FIGS)</td>
  376. <td style="text-align: center;"><a href="https://csinva.io/imodels/tree/figs.html#imodels.tree.figs.FIGSClassifier">FIGSClassifier</a></td>
  377. <td style="text-align: center;"><a href="https://csinva.io/imodels/tree/figs.html#imodels.tree.figs.FIGSRegressor">FIGSRegressor</a></td>
  378. <td></td>
  379. </tr>
  380. <tr>
  381. <td style="text-align: left;">Hierarchical shrinkage</td>
  382. <td style="text-align: center;"><a href="https://csinva.io/imodels/tree/hierarchical_shrinkage.html#imodels.tree.hierarchical_shrinkage.HSTreeClassifierCV">HSTreeClassifierCV</a></td>
  383. <td style="text-align: center;"><a href="https://csinva.io/imodels/tree/hierarchical_shrinkage.html#imodels.tree.hierarchical_shrinkage.HSTreeRegressorCV">HSTreeRegressorCV</a></td>
  384. <td>Wraps any sklearn tree-based model</td>
  385. </tr>
  386. <tr>
  387. <td style="text-align: left;">Distillation</td>
  388. <td style="text-align: center;"></td>
  389. <td style="text-align: center;"><a href="https://csinva.io/imodels/util/distillation.html#imodels.util.distillation.DistilledRegressor">DistilledRegressor</a></td>
  390. <td>Wraps any sklearn-compatible models</td>
  391. </tr>
  392. <tr>
  393. <td style="text-align: left;">AutoML model</td>
  394. <td style="text-align: center;"><a href="https://csinva.io/imodels/util/automl.html">AutoInterpretableClassifier️</a></td>
  395. <td style="text-align: center;"><a href="https://csinva.io/imodels/util/automl.html">AutoInterpretableRegressor️</a></td>
  396. <td></td>
  397. </tr>
  398. </tbody>
  399. </table>
  400. <h3 id="extras">Extras</h3>
  401. <details>
  402. <summary><a href="https://csinva.io/imodels/util/data_util.html#imodels.util.data_util.get_clean_dataset">Data-wrangling functions</a> for working with popular tabular datasets (e.g. compas).</summary>
  403. These functions, in conjunction with <a href="https://github.com/csinva/imodels-data">imodels-data</a> and <a href="https://github.com/Yu-Group/imodels-experiments">imodels-experiments</a>, make it simple to download data and run experiments on new models.
  404. </details>
  405. <details>
  406. <summary><a href="https://csinva.io/imodels/util/explain_errors.html">Explain classification errors</a> with a simple posthoc function.</summary>
  407. Fit an interpretable model to explain a previous model's errors (ex. in <a href="https://github.com/csinva/imodels/blob/master/notebooks/error_detection_demo.ipynb">this notebook📓</a>).
  408. </details>
  409. <details>
  410. <summary><a href="https://csinva.io/imodels/discretization/index.html">Fast and effective discretizers</a> for data preprocessing.</summary>
  411. <table>
  412. <thead>
  413. <tr>
  414. <th>Discretizer</th>
  415. <th>Reference</th>
  416. <th>Description</th>
  417. </tr>
  418. </thead>
  419. <tbody>
  420. <tr>
  421. <td>MDLP</td>
  422. <td><a href="https://csinva.io/imodels/discretization/mdlp.html#imodels.discretization.mdlp.MDLPDiscretizer">🗂️</a>, <a href="https://github.com/navicto/Discretization-MDLPC">🔗</a>, <a href="https://trs.jpl.nasa.gov/handle/2014/35171">📄</a></td>
  423. <td>Discretize using entropy minimization heuristic</td>
  424. </tr>
  425. <tr>
  426. <td>Simple</td>
  427. <td><a href="https://csinva.io/imodels/discretization/simple.html#imodels.discretization.simple.SimpleDiscretizer">🗂️</a>, <a href="https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.KBinsDiscretizer.html">🔗</a></td>
  428. <td>Simple KBins discretization</td>
  429. </tr>
  430. <tr>
  431. <td>Random Forest</td>
  432. <td><a href="https://csinva.io/imodels/discretization/discretizer.html#imodels.discretization.discretizer.RFDiscretizer">🗂️</a></td>
  433. <td>Discretize into bins based on random forest split popularity</td>
  434. </tr>
  435. </tbody>
  436. </table>
  437. </details>
  438. <details>
  439. <summary><a href="https://csinva.io/imodels/util/index.html">Rule-based utils</a> for customizing models</summary>
  440. The code here contains many useful and customizable functions for rule-based learning in the <a href="https://csinva.io/imodels/util/index.html">util folder</a>. This includes functions / classes for rule deduplication, rule screening, and converting between trees, rulesets, and neural networks.
  441. </details>
  442. <h2 id="our-favorite-models">Our favorite models</h2>
  443. <p>After developing and playing with <code><a title="imodels" href="#imodels">imodels</a></code>, we developed a few new models to overcome limitations of existing interpretable models.</p>
  444. <h3 id="figs-fast-interpretable-greedy-tree-sums">FIGS: Fast interpretable greedy-tree sums</h3>
  445. <p><a href="https://arxiv.org/abs/2201.11931">📄 Paper</a>, <a href="https://csinva.io/imodels/figs.html">🔗 Post</a>, <a href="https://scholar.google.com/scholar?hl=en&amp;as_sdt=0%2C5&amp;q=fast+interpretable+greedy-tree+sums&amp;oq=fast#d=gs_cit&amp;u=%2Fscholar%3Fq%3Dinfo%3ADnPVL74Rop0J%3Ascholar.google.com%2F%26output%3Dcite%26scirp%3D0%26hl%3Den">📌 Citation</a></p>
  446. <p>Fast Interpretable Greedy-Tree Sums (FIGS) is an algorithm for fitting concise rule-based models. Specifically, FIGS generalizes CART to simultaneously grow a flexible number of trees in a summation. The total number of splits across all the trees can be restricted by a pre-specified threshold, keeping the model interpretable. Experiments across a wide array of real-world datasets show that FIGS achieves state-of-the-art prediction performance when restricted to just a few splits (e.g. less than 20).</p>
  447. <p align="center">
  448. <img src="https://demos.csinva.io/figs/diabetes_figs.svg?sanitize=True" width="50%">
  449. </p>
  450. <p align="center">
  451. <i><b>Example FIGS model.</b> FIGS learns a sum of trees with a flexible number of trees; to make its prediction, it sums the result from each tree.</i>
  452. </p>
  453. <h3 id="hierarchical-shrinkage-post-hoc-regularization-for-tree-based-methods">Hierarchical shrinkage: post-hoc regularization for tree-based methods</h3>
  454. <p><a href="https://arxiv.org/abs/2202.00858">📄 Paper</a> (ICML 2022), <a href="https://csinva.io/imodels/shrinkage.html">🔗 Post</a>, <a href="https://scholar.google.com/scholar?hl=en&amp;as_sdt=0%2C5&amp;q=hierarchical+shrinkage+singh&amp;btnG=&amp;oq=hierar#d=gs_cit&amp;u=%2Fscholar%3Fq%3Dinfo%3Azc6gtLx-aL4J%3Ascholar.google.com%2F%26output%3Dcite%26scirp%3D0%26hl%3Den">📌 Citation</a></p>
  455. <p>Hierarchical shrinkage is an extremely fast post-hoc regularization method which works on any decision tree (or tree-based ensemble, such as Random Forest). It does not modify the tree structure, and instead regularizes the tree by shrinking the prediction over each node towards the sample means of its ancestors (using a single regularization parameter). Experiments over a wide variety of datasets show that hierarchical shrinkage substantially increases the predictive performance of individual decision trees and decision-tree ensembles.</p>
  456. <p align="center">
  457. <img src="https://demos.csinva.io/shrinkage/shrinkage_intro.svg?sanitize=True" width="75%">
  458. </p>
  459. <p align="center">
  460. <i><b>HS Example.</b> HS applies post-hoc regularization to any decision tree by shrinking each node towards its parent.</i>
  461. </p>
  462. <h3 id="mdi-flexible-tree-based-feature-importance">MDI+: Flexible Tree-Based Feature Importance</h3>
  463. <p><a href="https://arxiv.org/pdf/2307.01932.pdf">📄 Paper</a>, <a href="https://scholar.google.com/scholar?hl=en&amp;as_sdt=0%2C23&amp;q=MDI%2B%3A+A+Flexible+Random+Forest-Based+Feature+Importance+Framework&amp;btnG=#d=gs_cit&amp;t=1690399844081&amp;u=%2Fscholar%3Fq%3Dinfo%3Axc0LcHXE_lUJ%3Ascholar.google.com%2F%26output%3Dcite%26scirp%3D0%26hl%3Den">📌 Citation</a></p>
  464. <p>MDI+ is a novel feature importance framework, which generalizes the popular mean decrease in impurity (MDI) importance score for random forests. At its core, MDI+ expands upon a recently discovered connection between linear regression and decision trees. In doing so, MDI+ enables practitioners to (1) tailor the feature importance computation to the data/problem structure and (2) incorporate additional features or knowledge to mitigate known biases of decision trees. In both real data case studies and extensive real-data-inspired simulations, MDI+ outperforms commonly used feature importance measures (e.g., MDI, permutation-based scores, and TreeSHAP) by substantional margins.</p>
  465. <h2 id="references">References</h2>
  466. <details>
  467. <summary>Readings</summary>
  468. <ul>
  469. <li>Interpretable ML good quick overview: murdoch et al. 2019, <a href="https://arxiv.org/pdf/1901.04592.pdf">pdf</a></li>
  470. <li>Interpretable ML book: molnar 2019, <a href="https://christophm.github.io/interpretable-ml-book/">pdf</a></li>
  471. <li>Case for interpretable models rather than post-hoc explanation: rudin 2019, <a href="https://arxiv.org/pdf/1811.10154.pdf">pdf</a></li>
  472. <li>Review on evaluating interpretability: doshi-velez & kim 2017, <a href="https://arxiv.org/pdf/1702.08608.pdf">pdf</a></li>
  473. </ul>
  474. </details>
  475. <details>
  476. <summary>Reference implementations (also linked above)</summary>
  477. The code here heavily derives from the wonderful work of previous projects. We seek to to extract out, unify, and maintain key parts of these projects.
  478. <ul>
  479. <li><a href="https://github.com/corels/pycorels">pycorels</a> - by <a href="https://github.com/fingoldin">@fingoldin</a> and the <a href="https://github.com/corels/corels">original CORELS team</a>
  480. <li><a href="https://github.com/tmadl/sklearn-expertsys">sklearn-expertsys</a> - by <a href="https://github.com/tmadl">@tmadl</a> and <a href="https://github.com/kenben">@kenben</a> based on original code by <a href="http://lethalletham.com/">Ben Letham</a></li>
  481. <li><a href="https://github.com/christophM/rulefit">rulefit</a> - by <a href="https://github.com/christophM">@christophM</a></li>
  482. <li><a href="https://github.com/scikit-learn-contrib/skope-rules">skope-rules</a> - by the <a href="https://github.com/scikit-learn-contrib/skope-rules/blob/master/AUTHORS.rst">skope-rules team</a> (including <a href="https://github.com/ngoix">@ngoix</a>, <a href="https://github.com/floriangardin">@floriangardin</a>, <a href="https://github.com/datajms">@datajms</a>, <a href="">Bibi Ndiaye</a>, <a href="">Ronan Gautier</a>)</li>
  483. <li><a href="https://github.com/wangtongada/BOA">boa</a> - by <a href="https://github.com/wangtongada">@wangtongada</a></li>
  484. </ul>
  485. </details>
  486. <details>
  487. <summary>Related packages</summary>
  488. <ul>
  489. <li><a href="https://github.com/trevorstephens/gplearn/tree/ad57cb18caafdb02cca861aea712f1bf3ed5016e">gplearn</a>: symbolic regression/classification</li>
  490. <li><a href="https://github.com/MilesCranmer/PySR">pysr</a>: fast symbolic regression</li>
  491. <li><a href="https://github.com/dswah/pyGAM">pygam</a>: generative additive models</li>
  492. <li><a href="https://github.com/interpretml/interpret">interpretml</a>: boosting-based gam</li>
  493. <li><a href="https://github.com/h2oai/h2o-3">h20 ai</a>: gams + glms (and more)</li>
  494. <li><a href="https://github.com/guillermo-navas-palencia/optbinning">optbinning</a>: data discretization / scoring models</li>
  495. </ul>
  496. </details>
  497. <details>
  498. <summary>Updates</summary>
  499. <ul>
  500. <li>For updates, star the repo, <a href="https://github.com/csinva/csinva.github.io">see this related repo</a>, or follow <a href="https://twitter.com/csinva_">@csinva_</a></li>
  501. <li>Please make sure to give authors of original methods / base implementations appropriate credit!</li>
  502. <li>Contributing: pull requests <a href="https://github.com/csinva/imodels/blob/master/docs/contributing.md">very welcome</a>!</li>
  503. </ul>
  504. </details>
  505. <p>Please cite the package if you use it in an academic work :)</p>
  506. <pre><code class="language-r">@software{
  507. imodels2021,
  508. title = {imodels: a python package for fitting interpretable models},
  509. journal = {Journal of Open Source Software},
  510. publisher = {The Open Journal},
  511. year = {2021},
  512. author = {Singh, Chandan and Nasseri, Keyan and Tan, Yan Shuo and Tang, Tiffany and Yu, Bin},
  513. volume = {6},
  514. number = {61},
  515. pages = {3192},
  516. doi = {10.21105/joss.03192},
  517. url = {https://doi.org/10.21105/joss.03192},
  518. }
  519. </code></pre>
  520. <details class="source">
  521. <summary>
  522. <span>Expand source code</span>
  523. </summary>
  524. <pre><code class="python">&#34;&#34;&#34;
  525. .. include:: ../readme.md
  526. &#34;&#34;&#34;
  527. # Python `imodels` package for interpretable models compatible with scikit-learn.
  528. # Github repo available [here](https://github.com/csinva/imodels)
  529. from .algebraic.slim import SLIMRegressor, SLIMClassifier
  530. from .algebraic.tree_gam import TreeGAMClassifier, TreeGAMRegressor
  531. from .algebraic.marginal_shrinkage_linear_model import (
  532. MarginalShrinkageLinearModelRegressor,
  533. )
  534. from .discretization.discretizer import RFDiscretizer, BasicDiscretizer
  535. from .discretization.mdlp import MDLPDiscretizer, BRLDiscretizer
  536. from .experimental.bartpy import BART
  537. from .rule_list.bayesian_rule_list.bayesian_rule_list import BayesianRuleListClassifier
  538. from .rule_list.corels_wrapper import OptimalRuleListClassifier
  539. from .rule_list.greedy_rule_list import GreedyRuleListClassifier
  540. from .rule_list.one_r import OneRClassifier
  541. from .rule_set import boosted_rules
  542. from .rule_set.boosted_rules import *
  543. from .rule_set.boosted_rules import BoostedRulesClassifier
  544. from .rule_set.brs import BayesianRuleSetClassifier
  545. from .rule_set.fplasso import FPLassoRegressor, FPLassoClassifier
  546. from .rule_set.fpskope import FPSkopeClassifier
  547. from .rule_set.rule_fit import RuleFitRegressor, RuleFitClassifier
  548. from .rule_set.skope_rules import SkopeRulesClassifier
  549. from .rule_set.slipper import SlipperClassifier
  550. from .tree.c45_tree.c45_tree import C45TreeClassifier
  551. from .tree.cart_ccp import (
  552. DecisionTreeCCPClassifier,
  553. DecisionTreeCCPRegressor,
  554. HSDecisionTreeCCPClassifierCV,
  555. HSDecisionTreeCCPRegressorCV,
  556. )
  557. # from .tree.iterative_random_forest.iterative_random_forest import IRFClassifier
  558. # from .tree.optimal_classification_tree import OptimalTreeModel
  559. from .tree.cart_wrapper import GreedyTreeClassifier, GreedyTreeRegressor
  560. from .tree.figs import FIGSRegressor, FIGSClassifier, FIGSRegressorCV, FIGSClassifierCV
  561. from .tree.gosdt.pygosdt import OptimalTreeClassifier
  562. from .tree.gosdt.pygosdt_shrinkage import (
  563. HSOptimalTreeClassifier,
  564. HSOptimalTreeClassifierCV,
  565. )
  566. from .tree.hierarchical_shrinkage import (
  567. HSTreeRegressor,
  568. HSTreeClassifier,
  569. HSTreeRegressorCV,
  570. HSTreeClassifierCV,
  571. )
  572. from .tree.tao import TaoTreeClassifier, TaoTreeRegressor
  573. from .util.automl import AutoInterpretableClassifier, AutoInterpretableRegressor
  574. from .util.data_util import get_clean_dataset
  575. from .util.distillation import DistilledRegressor
  576. from .util.explain_errors import explain_classification_errors
  577. CLASSIFIERS = [
  578. BayesianRuleListClassifier,
  579. GreedyRuleListClassifier,
  580. SkopeRulesClassifier,
  581. BoostedRulesClassifier,
  582. SLIMClassifier,
  583. SlipperClassifier,
  584. BayesianRuleSetClassifier,
  585. C45TreeClassifier,
  586. OptimalTreeClassifier,
  587. OptimalRuleListClassifier,
  588. OneRClassifier,
  589. SlipperClassifier,
  590. RuleFitClassifier,
  591. TaoTreeClassifier,
  592. TreeGAMClassifier,
  593. FIGSClassifier,
  594. HSTreeClassifier,
  595. HSTreeClassifierCV,
  596. GreedyTreeClassifier,
  597. AutoInterpretableClassifier,
  598. ] # , IRFClassifier
  599. REGRESSORS = [
  600. RuleFitRegressor,
  601. SLIMRegressor,
  602. GreedyTreeRegressor,
  603. FIGSRegressor,
  604. TaoTreeRegressor,
  605. TreeGAMRegressor,
  606. HSTreeRegressor,
  607. HSTreeRegressorCV,
  608. BART,
  609. AutoInterpretableRegressor,
  610. ]
  611. ESTIMATORS = CLASSIFIERS + REGRESSORS
  612. DISCRETIZERS = [RFDiscretizer, BasicDiscretizer,
  613. MDLPDiscretizer, BRLDiscretizer]</code></pre>
  614. </details>
  615. </section>
  616. <section>
  617. <h2 class="section-title" id="header-submodules">Sub-modules</h2>
  618. <dl>
  619. <dt><code class="name"><a title="imodels.algebraic" href="algebraic/index.html">imodels.algebraic</a></code></dt>
  620. <dd>
  621. <div class="desc"><p>Generic class for models that take the form of algebraic equations (e.g. linear models).</p></div>
  622. </dd>
  623. <dt><code class="name"><a title="imodels.discretization" href="discretization/index.html">imodels.discretization</a></code></dt>
  624. <dd>
  625. <div class="desc"></div>
  626. </dd>
  627. <dt><code class="name"><a title="imodels.experimental" href="experimental/index.html">imodels.experimental</a></code></dt>
  628. <dd>
  629. <div class="desc"></div>
  630. </dd>
  631. <dt><code class="name"><a title="imodels.importance" href="importance/index.html">imodels.importance</a></code></dt>
  632. <dd>
  633. <div class="desc"><p>Feature importance methods for black box models</p></div>
  634. </dd>
  635. <dt><code class="name"><a title="imodels.rule_list" href="rule_list/index.html">imodels.rule_list</a></code></dt>
  636. <dd>
  637. <div class="desc"><p>Generic class for models that take the form of a list of rules.</p></div>
  638. </dd>
  639. <dt><code class="name"><a title="imodels.rule_set" href="rule_set/index.html">imodels.rule_set</a></code></dt>
  640. <dd>
  641. <div class="desc"><p>Generic class for models that take the form of a set of (potentially overlapping) rules.</p></div>
  642. </dd>
  643. <dt><code class="name"><a title="imodels.tree" href="tree/index.html">imodels.tree</a></code></dt>
  644. <dd>
  645. <div class="desc"><p>Generic class for models that take the form of a tree of rules.</p></div>
  646. </dd>
  647. <dt><code class="name"><a title="imodels.util" href="util/index.html">imodels.util</a></code></dt>
  648. <dd>
  649. <div class="desc"><p>Shared utilities for implementing different interpretable models.</p></div>
  650. </dd>
  651. </dl>
  652. </section>
  653. <section>
  654. </section>
  655. <section>
  656. </section>
  657. <section>
  658. </section>
  659. </article>
  660. <nav id="sidebar">
  661. <h1>Index 🔍</h1>
  662. <div class="toc">
  663. <ul>
  664. <li><a href="#installation">Installation</a></li>
  665. <li><a href="#supported-models">Supported models</a></li>
  666. <li><a href="#demo-notebooks">Demo notebooks</a></li>
  667. <li><a href="#whats-the-difference-between-the-models">What's the difference between the models?</a></li>
  668. <li><a href="#support-for-different-tasks">Support for different tasks</a><ul>
  669. <li><a href="#extras">Extras</a></li>
  670. </ul>
  671. </li>
  672. <li><a href="#our-favorite-models">Our favorite models</a><ul>
  673. <li><a href="#figs-fast-interpretable-greedy-tree-sums">FIGS: Fast interpretable greedy-tree sums</a></li>
  674. <li><a href="#hierarchical-shrinkage-post-hoc-regularization-for-tree-based-methods">Hierarchical shrinkage: post-hoc regularization for tree-based methods</a></li>
  675. <li><a href="#mdi-flexible-tree-based-feature-importance">MDI+: Flexible Tree-Based Feature Importance</a></li>
  676. </ul>
  677. </li>
  678. <li><a href="#references">References</a></li>
  679. </ul>
  680. </div>
  681. <ul id="index">
  682. <li><h3>Our favorite models</h3>
  683. <ul>
  684. <li><a href="https://csinva.io/imodels/shrinkage.html">Hierarchical shrinkage: post-hoc regularization for tree-based methods</a></li>
  685. <li><a href="https://csinva.io/imodels/figs.html">FIGS: Fast interpretable greedy-tree sums</a></li>
  686. </ul>
  687. </li>
  688. <li><h3><a href="#header-submodules">Sub-modules</a></h3>
  689. <ul>
  690. <li><code><a title="imodels.algebraic" href="algebraic/index.html">imodels.algebraic</a></code></li>
  691. <li><code><a title="imodels.discretization" href="discretization/index.html">imodels.discretization</a></code></li>
  692. <li><code><a title="imodels.experimental" href="experimental/index.html">imodels.experimental</a></code></li>
  693. <li><code><a title="imodels.importance" href="importance/index.html">imodels.importance</a></code></li>
  694. <li><code><a title="imodels.rule_list" href="rule_list/index.html">imodels.rule_list</a></code></li>
  695. <li><code><a title="imodels.rule_set" href="rule_set/index.html">imodels.rule_set</a></code></li>
  696. <li><code><a title="imodels.tree" href="tree/index.html">imodels.tree</a></code></li>
  697. <li><code><a title="imodels.util" href="util/index.html">imodels.util</a></code></li>
  698. </ul>
  699. </li>
  700. </ul>
  701. <p><img align="center" width=100% src="https://csinva.io/imodels/img/anim.gif"> </img></p>
  702. <!-- add wave animation -->
  703. </nav>
  704. </main>
  705. <footer id="footer">
  706. </footer>
  707. </body>
  708. </html>
  709. <!-- add github corner -->
  710. <a href="https://github.com/csinva/imodels" class="github-corner" aria-label="View source on GitHub"><svg width="120" height="120" viewBox="0 0 250 250" style="fill:#70B7FD; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="m128.3,109.0 c113.8,99.7 119.0,89.6 119.0,89.6 c122.0,82.7 120.5,78.6 120.5,78.6 c119.2,72.0 123.4,76.3 123.4,76.3 c127.3,80.9 125.5,87.3 125.5,87.3 c122.9,97.6 130.6,101.9 134.4,103.2" fill="currentcolor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
  711. <!-- add wave animation stylesheet -->
  712. <link rel="stylesheet" href="github.css">
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...