1212from sklearn import metrics
1313import numpy as np
1414
15- from tests .utils import get_test_cases , assert_rules_are_equals , assert_accuracy_is_greater
15+ from tests .utils import (
16+ dir_path ,
17+ get_test_cases ,
18+ assert_rules_are_equals ,
19+ assert_accuracy_is_greater ,
20+ )
1621
1722
1823class TestClassifier (unittest .TestCase ):
@@ -152,7 +157,7 @@ def test_compare_with_java_results(self):
152157 def test_predict_proba (self ):
153158 test_case = get_test_cases ('ClassificationSnCTest' )[0 ]
154159 params = test_case .induction_params
155- clf = classification .ExpertRuleClassifier (** params )
160+ clf = classification .RuleClassifier (** params )
156161 example_set = test_case .example_set
157162 clf .fit (
158163 example_set .values ,
@@ -174,6 +179,24 @@ def test_predict_proba(self):
174179 'Predicted probabilities should be in range [0, 1]'
175180 )
176181
182+ def test_fit_and_predict_on_boolean_columns (self ):
183+ test_case = get_test_cases ('ClassificationSnCTest' )[0 ]
184+ params = test_case .induction_params
185+ clf = classification .RuleClassifier (** params )
186+ X , y = test_case .example_set .values , test_case .example_set .labels
187+ X ['boolean_column' ] = np .random .randint (
188+ low = 0 , high = 2 , size = X .shape [0 ]).astype (bool )
189+ clf .fit (X , y )
190+ clf .predict (X )
191+
192+ y = y .astype (bool )
193+ clf .fit (X , y )
194+ clf .predict (X )
195+
196+ y = pd .Series (y )
197+ clf .fit (X , y )
198+ clf .predict (X )
199+
177200
178201class TestExperClassifier (unittest .TestCase ):
179202
@@ -222,6 +245,46 @@ def test_predict_proba(self):
222245 'Predicted probabilities should be in range [0, 1]'
223246 )
224247
248+ # Issue #17
249+ def test_left_open_intervals_in_expert_induction (self ):
250+ df = pd .DataFrame (arff .loadarff (
251+ f'{ dir_path } /resources/data/seismic-bumps-train-minimal.arff' )[0 ]
252+ )
253+ X = df .drop ('class' , axis = 1 )
254+ y = df ['class' ]
255+
256+ expert_rules = [
257+ ('rule-0' , 'IF [[gimpuls = <-inf, 750)]] THEN class = {0}' ),
258+ ('rule-1' , 'IF [[gimpuls = (750, inf)]] THEN class = {1}' )
259+ ]
260+
261+ expert_preferred_conditions = [
262+ ('preferred-condition-0' ,
263+ '1: IF [[seismic = {a}]] THEN class = {0}' ),
264+ ('preferred-attribute-0' ,
265+ '1: IF [[gimpuls = Any]] THEN class = {1}' )
266+ ]
267+
268+ expert_forbidden_conditions = [
269+ ('forb-attribute-0' ,
270+ '1: IF [[seismoacoustic = Any]] THEN class = {0}' ),
271+ ('forb-attribute-1' , 'inf: IF [[ghazard = Any]] THEN class = {1}' )
272+ ]
273+ clf = classification .ExpertRuleClassifier (
274+ minsupp_new = 8 ,
275+ max_growing = 0 ,
276+ extend_using_preferred = True ,
277+ extend_using_automatic = True ,
278+ induce_using_preferred = True ,
279+ induce_using_automatic = True
280+ )
281+ clf .fit (
282+ X , y ,
283+ expert_rules = expert_rules ,
284+ expert_preferred_conditions = expert_preferred_conditions ,
285+ expert_forbidden_conditions = expert_forbidden_conditions
286+ )
287+
225288
226289if __name__ == '__main__' :
227290 unittest .main ()
0 commit comments