rulelearn-ripper-interactive 0.2.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. rulelearn_ri/__init__.py +6 -0
  2. rulelearn_ri/algorithms/__init__.py +0 -0
  3. rulelearn_ri/algorithms/r2n/__init__.py +0 -0
  4. rulelearn_ri/algorithms/r2n/base.py +28 -0
  5. rulelearn_ri/algorithms/r2n/functions.py +25 -0
  6. rulelearn_ri/algorithms/r2n/mask.py +58 -0
  7. rulelearn_ri/algorithms/r2n/preprocessing_layers.py +192 -0
  8. rulelearn_ri/algorithms/r2n/r2n_algo.py +287 -0
  9. rulelearn_ri/algorithms/r2n/simple_rulenet.py +75 -0
  10. rulelearn_ri/algorithms/r2n/training.py +34 -0
  11. rulelearn_ri/algorithms/r2n/utilities.py +117 -0
  12. rulelearn_ri/algorithms/rbm/__init__.py +0 -0
  13. rulelearn_ri/algorithms/rbm/boolean_rule_cg.py +65 -0
  14. rulelearn_ri/algorithms/rbm/rbm/BRCG.py +69 -0
  15. rulelearn_ri/algorithms/rbm/rbm/GLRM.py +98 -0
  16. rulelearn_ri/algorithms/rbm/rbm/__init__.py +6 -0
  17. rulelearn_ri/algorithms/rbm/rbm/beam_search.py +302 -0
  18. rulelearn_ri/algorithms/rbm/rbm/boolean_rule_cg.py +245 -0
  19. rulelearn_ri/algorithms/rbm/rbm/features.py +544 -0
  20. rulelearn_ri/algorithms/rbm/rbm/linear_regression.py +393 -0
  21. rulelearn_ri/algorithms/rbm/rbm/logistic_regression.py +447 -0
  22. rulelearn_ri/algorithms/rbm/utils.py +13 -0
  23. rulelearn_ri/algorithms/ripper/__init__.py +10 -0
  24. rulelearn_ri/algorithms/ripper/base.py +81 -0
  25. rulelearn_ri/algorithms/ripper/binding.py +541 -0
  26. rulelearn_ri/algorithms/ripper/mdl.py +97 -0
  27. rulelearn_ri/algorithms/ripper/pruning.py +212 -0
  28. rulelearn_ri/algorithms/ripper/ripper.py +600 -0
  29. rulelearn_ri/algorithms/ripper/ripper_ruleset_generator.py +26 -0
  30. rulelearn_ri/algorithms/ripper/single_rule.py +425 -0
  31. rulelearn_ri/dise.py +64 -0
  32. rulelearn_ri/trxf/__init__.py +0 -0
  33. rulelearn_ri/trxf/classifier/__init__.py +0 -0
  34. rulelearn_ri/trxf/classifier/ruleset_classifier.py +153 -0
  35. rulelearn_ri/trxf/core/__init__.py +5 -0
  36. rulelearn_ri/trxf/core/boolean_evaluator.py +15 -0
  37. rulelearn_ri/trxf/core/conjunction.py +50 -0
  38. rulelearn_ri/trxf/core/dnf_ruleset.py +64 -0
  39. rulelearn_ri/trxf/core/feature.py +155 -0
  40. rulelearn_ri/trxf/core/predicate.py +98 -0
  41. rulelearn_ri/trxf/core/ruleset_generator.py +25 -0
  42. rulelearn_ri/trxf/core/utils.py +40 -0
  43. rulelearn_ri/trxf/metrics.py +98 -0
  44. rulelearn_ri/trxf/pmml_export/__init__.py +4 -0
  45. rulelearn_ri/trxf/pmml_export/__version__.py +1 -0
  46. rulelearn_ri/trxf/pmml_export/models/__init__.py +24 -0
  47. rulelearn_ri/trxf/pmml_export/models/attribute.py +24 -0
  48. rulelearn_ri/trxf/pmml_export/models/characteristics.py +20 -0
  49. rulelearn_ri/trxf/pmml_export/models/data_dictionary.py +53 -0
  50. rulelearn_ri/trxf/pmml_export/models/mining_schema.py +25 -0
  51. rulelearn_ri/trxf/pmml_export/models/pmml_ruleset_model.py +16 -0
  52. rulelearn_ri/trxf/pmml_export/models/predicate.py +42 -0
  53. rulelearn_ri/trxf/pmml_export/models/rule.py +26 -0
  54. rulelearn_ri/trxf/pmml_export/models/ruleset.py +28 -0
  55. rulelearn_ri/trxf/pmml_export/models/ruleset_model.py +16 -0
  56. rulelearn_ri/trxf/pmml_export/models/scorecard.py +35 -0
  57. rulelearn_ri/trxf/pmml_export/pmml_exporter.py +18 -0
  58. rulelearn_ri/trxf/pmml_export/reader/__init__.py +2 -0
  59. rulelearn_ri/trxf/pmml_export/reader/abstract_reader.py +16 -0
  60. rulelearn_ri/trxf/pmml_export/reader/trxf_reader.py +113 -0
  61. rulelearn_ri/trxf/pmml_export/serializer/__init__.py +2 -0
  62. rulelearn_ri/trxf/pmml_export/serializer/abstract_serializer.py +11 -0
  63. rulelearn_ri/trxf/pmml_export/serializer/nyoka_serializer.py +162 -0
  64. rulelearn_ri/trxf/scorecard/__init__.py +3 -0
  65. rulelearn_ri/trxf/scorecard/bins.py +253 -0
  66. rulelearn_ri/trxf/scorecard/partition.py +71 -0
  67. rulelearn_ri/trxf/scorecard/scorecard.py +78 -0
  68. rulelearn_ripper_interactive-0.2.3.dist-info/METADATA +164 -0
  69. rulelearn_ripper_interactive-0.2.3.dist-info/RECORD +73 -0
  70. rulelearn_ripper_interactive-0.2.3.dist-info/WHEEL +5 -0
  71. rulelearn_ripper_interactive-0.2.3.dist-info/licenses/LICENSE +201 -0
  72. rulelearn_ripper_interactive-0.2.3.dist-info/licenses/NOTICE +11 -0
  73. rulelearn_ripper_interactive-0.2.3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,212 @@
1
+ import numba as nb
2
+ import numpy as np
3
+
4
+ from rulelearn_ri.algorithms.ripper.binding import _rule_predict, _rule_list_predict
5
+ from rulelearn_ri.algorithms.ripper.mdl import _mdl
6
+
7
+
8
+ @nb.njit(
9
+ 'double(int64, int64, int64, int64)',
10
+ nogil=True,
11
+ cache=True,
12
+ error_model='numpy'
13
+ )
14
+ def accuracy_tp_fp(
15
+ p0,
16
+ n0,
17
+ tp,
18
+ fp
19
+ ):
20
+ """
21
+ Calculate accuracy using true positive and false positive.
22
+ """
23
+ return (tp + n0 - float(fp)) / (p0 + float(n0))
24
+
25
+
26
+ @nb.njit(
27
+ 'double(int64, int64)',
28
+ nogil=True,
29
+ cache=True,
30
+ error_model='numpy'
31
+ )
32
+ def irep_pm(
33
+ p,
34
+ n
35
+ ):
36
+ """
37
+ Calculate pruning measure for IREP*
38
+ """
39
+ # p + n == 0 is meaningless
40
+ if p + n == 0:
41
+ return -2.0
42
+ else:
43
+ return (p - float(n)) / (p + float(n))
44
+
45
+
46
+ def __last_sequences(
47
+ input_list,
48
+ inverted,
49
+ accept_zero
50
+ ):
51
+ """
52
+ Last sequences of items.
53
+
54
+ Parameters
55
+ ----------
56
+ input_list : list
57
+ Input item list
58
+ inverted : boolean
59
+ If inverted=True, then the resulted sequence starts with full length
60
+ accept_zero : boolean
61
+ If accept_zero=True, then the resulted sequences contains empty
62
+
63
+ Returns
64
+ -------
65
+ list
66
+ Last sequences of original list
67
+ """
68
+ if inverted:
69
+ step = -1
70
+ if accept_zero:
71
+ begin = len(input_list) + 1
72
+ end = -1
73
+ else:
74
+ begin = len(input_list) + 1
75
+ end = 0
76
+ else:
77
+ step = 1
78
+ if accept_zero:
79
+ begin = 0
80
+ end = len(input_list) + 1
81
+ else:
82
+ begin = 1
83
+ end = len(input_list) + 1
84
+
85
+ return [input_list[: possible_length] for possible_length in range(begin, end, step)]
86
+
87
+
88
+ def __error_rate_rule_list(
89
+ pos,
90
+ neg,
91
+ rule_list
92
+ ):
93
+ """
94
+ Calculate error rate of rules in pruning data set
95
+
96
+ Parameters
97
+ ----------
98
+ pos : const double[::1, :]
99
+ Positive instances of pruning data set
100
+ neg : const double[::1, :]
101
+ Negative instances of pruning data set
102
+ rule_list: list
103
+ Input rule list
104
+
105
+ Returns
106
+ -------
107
+ double
108
+ Error rate
109
+ """
110
+ return 1.0 - accuracy_tp_fp(
111
+ len(pos),
112
+ len(neg),
113
+ np.count_nonzero(_rule_list_predict(pos, rule_list)),
114
+ np.count_nonzero(_rule_list_predict(neg, rule_list))
115
+ )
116
+
117
+
118
+ def _pruning_irep(
119
+ pos,
120
+ neg,
121
+ rule
122
+ ):
123
+ """
124
+ Pruning literals in a rule
125
+
126
+ Parameters
127
+ ----------
128
+ pos : const double[::1, :]
129
+ Positive instances of pruning data set
130
+ neg : const double[::1, :]
131
+ Negative instances of pruning data set
132
+ rule: list
133
+ Input rule
134
+
135
+ Returns
136
+ -------
137
+ double
138
+ Pruned rule
139
+ """
140
+ return max(
141
+ __last_sequences(rule, True, False),
142
+ key=lambda rule_iter: irep_pm(
143
+ np.count_nonzero(_rule_predict(pos, rule_iter)),
144
+ np.count_nonzero(_rule_predict(neg, rule_iter))
145
+ )
146
+ )
147
+
148
+
149
+ def _minimize_rule_list(
150
+ pos,
151
+ neg,
152
+ rules,
153
+ n
154
+ ):
155
+ """
156
+ Pruning rules in a rule list
157
+
158
+ Parameters
159
+ ----------
160
+ pos : const double[::1, :]
161
+ Positive instances of pruning data set
162
+ neg : const double[::1, :]
163
+ Negative instances of pruning data set
164
+ rules: list
165
+ Input rule list
166
+
167
+ Returns
168
+ -------
169
+ double
170
+ Pruned rule list
171
+ """
172
+ return min(
173
+ __last_sequences(rules, True, True),
174
+ key=lambda rule_list_iter: _mdl(pos, neg, rule_list_iter, n)
175
+ )
176
+
177
+
178
+ def _pruning_optimization(
179
+ pos_prune,
180
+ neg_prune,
181
+ rule,
182
+ rules,
183
+ index
184
+ ):
185
+ """
186
+ Pruning rules in a rule list for the optimization step
187
+
188
+ Parameters
189
+ ----------
190
+ pos_prune : const double[::1, :]
191
+ Positive instances of data set
192
+ neg_prune : const double[::1, :]
193
+ Negative instances of data set
194
+ rule: list
195
+ Selected rule
196
+ rules: list
197
+ The rest of rules in that rule list
198
+
199
+ Returns
200
+ -------
201
+ double
202
+ Pruned rule
203
+ """
204
+ return min(
205
+ __last_sequences(rule, True, False),
206
+ key=lambda rule_iter: __error_rate_rule_list(
207
+ pos_prune,
208
+ neg_prune,
209
+ rules[:index] + [rule_iter] + rules[index + 1:]
210
+ if len(rule_iter) > 0 else rules[:index] + rules[index + 1:]
211
+ )
212
+ )