scikit-learn-contrib / skope-rules

machine learning with logical rules in Python
http://skope-rules.readthedocs.io
Other
615 stars 95 forks source link

No rules are generated using single-feature dataset #25

Open TKlerx opened 5 years ago

TKlerx commented 5 years ago

Hey there,

I wanted to use this package to derive very basic rules for one feature and one label. It works well for more than one feature, but using only one feature, the output is empty. I also tried with the iris dataset and the code looks like this:


from skrules import SkopeRules

dataset = load_iris()
feature_names = ['sepal_length']
clf = SkopeRules(max_depth_duplication=2,
                 n_estimators=30,
                 precision_min=0.3,
                 recall_min=0.1,
                 feature_names=feature_names)

for idx, species in enumerate(dataset.target_names):
    X, y = dataset.data, dataset.target
    clf.fit(X[::,0].reshape(-1, 1), y == idx)
    rules = clf.rules_[0:3]
    print("Rules for iris", species)
    for rule in rules:
        print(rule)
    print()
    print(20*'=')
    print()```
ngoix commented 5 years ago

Thanks for reporting the issue, do you want to open a pull request to fix it?