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

rule_set.py 1.3 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
  1. import numpy as np
  2. import pandas as pd
  3. from sklearn.utils.validation import check_array, check_is_fitted
  4. class RuleSet:
  5. def _extract_rules(self, X, y):
  6. pass
  7. def _score_rules(self, X, y, rules):
  8. pass
  9. def _prune_rules(self, rules):
  10. pass
  11. def _eval_weighted_rule_sum(self, X) -> np.ndarray:
  12. check_is_fitted(self, ['rules_without_feature_names_', 'n_features_', 'feature_placeholders'])
  13. X = check_array(X)
  14. if X.shape[1] != self.n_features_:
  15. raise ValueError("X.shape[1] = %d should be equal to %d, the number of features at training time."
  16. " Please reshape your data."
  17. % (X.shape[1], self.n_features_))
  18. df = pd.DataFrame(X, columns=self.feature_placeholders)
  19. selected_rules = self.rules_without_feature_names_
  20. scores = np.zeros(X.shape[0])
  21. for r in selected_rules:
  22. features_r_uses = list(map(lambda x: x[0], r.agg_dict.keys()))
  23. scores[df[features_r_uses].query(str(r)).index.values] += r.args[0]
  24. return scores
  25. def _get_complexity(self):
  26. check_is_fitted(self, ['rules_without_feature_names_'])
  27. return sum([len(rule.agg_dict) for rule in self.rules_without_feature_names_])
Tip!

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

Comments

Loading...