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

fplasso.py 2.2 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
  1. from typing import List
  2. import pandas as pd
  3. from sklearn.base import ClassifierMixin, RegressorMixin
  4. from imodels.rule_set.rule_fit import RuleFit
  5. from imodels.util.convert import itemsets_to_rules
  6. from imodels.util.extract import extract_fpgrowth
  7. class FPLasso(RuleFit):
  8. def __init__(self,
  9. minsupport=0.1,
  10. maxcardinality=2,
  11. verbose=False,
  12. n_estimators=100,
  13. tree_size=4,
  14. sample_fract='default',
  15. max_rules=2000,
  16. memory_par=0.01,
  17. tree_generator=None,
  18. lin_trim_quantile=0.025,
  19. lin_standardise=True,
  20. exp_rand_tree_size=True,
  21. include_linear=True,
  22. alpha=None,
  23. random_state=None):
  24. super().__init__(n_estimators,
  25. tree_size,
  26. sample_fract,
  27. max_rules,
  28. memory_par,
  29. tree_generator,
  30. lin_trim_quantile,
  31. lin_standardise,
  32. exp_rand_tree_size,
  33. include_linear,
  34. alpha,
  35. random_state)
  36. self.minsupport = minsupport
  37. self.maxcardinality = maxcardinality
  38. self.verbose = verbose
  39. def fit(self, X, y=None, feature_names=None, undiscretized_features=[]):
  40. self.undiscretized_features = undiscretized_features
  41. super().fit(X, y, feature_names=feature_names)
  42. return self
  43. def _extract_rules(self, X, y) -> List[str]:
  44. X = pd.DataFrame(X, columns=self.feature_placeholders)
  45. itemsets = extract_fpgrowth(X, minsupport=self.minsupport,
  46. maxcardinality=self.maxcardinality,
  47. verbose=self.verbose)
  48. return itemsets_to_rules(itemsets)
  49. class FPLassoRegressor(FPLasso, RegressorMixin):
  50. def _init_prediction_task(self):
  51. self.prediction_task = 'regression'
  52. class FPLassoClassifier(FPLasso, ClassifierMixin):
  53. def _init_prediction_task(self):
  54. self.prediction_task = 'classification'
Tip!

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

Comments

Loading...