selective 1.1.2__tar.gz → 1.2.0__tar.gz

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 (43) hide show
  1. selective-1.2.0/LICENSE.md +173 -0
  2. selective-1.2.0/MANIFEST.in +1 -0
  3. selective-1.2.0/NOTICES +16 -0
  4. selective-1.2.0/PKG-INFO +250 -0
  5. {selective-1.1.2 → selective-1.2.0}/README.md +23 -6
  6. {selective-1.1.2 → selective-1.2.0}/feature/_version.py +2 -2
  7. {selective-1.1.2 → selective-1.2.0}/feature/base.py +1 -1
  8. {selective-1.1.2 → selective-1.2.0}/feature/correlation.py +1 -1
  9. selective-1.2.0/feature/kl_divergence.py +66 -0
  10. {selective-1.1.2 → selective-1.2.0}/feature/linear.py +1 -1
  11. {selective-1.1.2 → selective-1.2.0}/feature/selector.py +10 -3
  12. {selective-1.1.2 → selective-1.2.0}/feature/statistical.py +17 -8
  13. {selective-1.1.2 → selective-1.2.0}/feature/text_based.py +1 -1
  14. {selective-1.1.2 → selective-1.2.0}/feature/tree_based.py +1 -1
  15. {selective-1.1.2 → selective-1.2.0}/feature/utils.py +1 -1
  16. {selective-1.1.2 → selective-1.2.0}/feature/variance.py +1 -1
  17. selective-1.2.0/requirements.txt +11 -0
  18. selective-1.2.0/selective.egg-info/PKG-INFO +250 -0
  19. selective-1.2.0/selective.egg-info/SOURCES.txt +38 -0
  20. {selective-1.1.2 → selective-1.2.0}/setup.py +4 -4
  21. selective-1.2.0/tests/test_base.py +23 -0
  22. selective-1.2.0/tests/test_benchmark.py +214 -0
  23. selective-1.2.0/tests/test_correlation.py +77 -0
  24. selective-1.2.0/tests/test_linear.py +160 -0
  25. selective-1.2.0/tests/test_parallel.py +162 -0
  26. selective-1.2.0/tests/test_stat_anova.py +113 -0
  27. selective-1.2.0/tests/test_stat_chi.py +79 -0
  28. selective-1.2.0/tests/test_stat_kl.py +95 -0
  29. selective-1.2.0/tests/test_stat_maximal.py +116 -0
  30. selective-1.2.0/tests/test_stat_mutual.py +113 -0
  31. selective-1.2.0/tests/test_stat_vif.py +87 -0
  32. selective-1.2.0/tests/test_text.py +699 -0
  33. selective-1.2.0/tests/test_tree.py +329 -0
  34. selective-1.2.0/tests/test_utils.py +29 -0
  35. selective-1.2.0/tests/test_variance.py +86 -0
  36. selective-1.1.2/PKG-INFO +0 -212
  37. selective-1.1.2/selective.egg-info/PKG-INFO +0 -212
  38. selective-1.1.2/selective.egg-info/SOURCES.txt +0 -18
  39. {selective-1.1.2 → selective-1.2.0}/feature/__init__.py +0 -0
  40. {selective-1.1.2 → selective-1.2.0}/selective.egg-info/dependency_links.txt +0 -0
  41. {selective-1.1.2 → selective-1.2.0}/selective.egg-info/requires.txt +0 -0
  42. {selective-1.1.2 → selective-1.2.0}/selective.egg-info/top_level.txt +0 -0
  43. {selective-1.1.2 → selective-1.2.0}/setup.cfg +0 -0
@@ -0,0 +1,173 @@
1
+ # Apache License
2
+
3
+ Version 2.0, January 2004
4
+
5
+ <http://www.apache.org/licenses/>
6
+
7
+ ## TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ ### 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction, and
12
+ distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
15
+ owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all other entities
18
+ that control, are controlled by, or are under common control with that entity.
19
+ For the purposes of this definition, "control" means (i) the power, direct or
20
+ indirect, to cause the direction or management of such entity, whether by
21
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
25
+ permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications, including
28
+ but not limited to software source code, documentation source, and
29
+ configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical transformation or
32
+ translation of a Source form, including but not limited to compiled object
33
+ code, generated documentation, and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or Object form,
36
+ made available under the License, as indicated by a copyright notice that is
37
+ included in or attached to the work (an example is provided in the Appendix
38
+ below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
41
+ is based on (or derived from) the Work and for which the editorial revisions,
42
+ annotations, elaborations, or other modifications represent, as a whole, an
43
+ original work of authorship. For the purposes of this License, Derivative Works
44
+ shall not include works that remain separable from, or merely link (or bind by
45
+ name) to the interfaces of, the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean any work of authorship, including the original
48
+ version of the Work and any modifications or additions to that Work or
49
+ Derivative Works thereof, that is intentionally submitted to Licensor for
50
+ inclusion in the Work by the copyright owner or by an individual or Legal
51
+ Entity authorized to submit on behalf of the copyright owner. For the purposes
52
+ of this definition, "submitted" means any form of electronic, verbal, or
53
+ written communication sent to the Licensor or its representatives, including
54
+ but not limited to communication on electronic mailing lists, source code
55
+ control systems, and issue tracking systems that are managed by, or on behalf
56
+ of, the Licensor for the purpose of discussing and improving the Work, but
57
+ excluding communication that is conspicuously marked or otherwise designated in
58
+ writing by the copyright owner as "Not a Contribution."
59
+
60
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
61
+ of whom a Contribution has been received by Licensor and subsequently
62
+ incorporated within the Work.
63
+
64
+ ### 2. Grant of Copyright License.
65
+
66
+ Subject to the terms and conditions of this License, each Contributor hereby
67
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
68
+ irrevocable copyright license to reproduce, prepare Derivative Works of,
69
+ publicly display, publicly perform, sublicense, and distribute the Work and
70
+ such Derivative Works in Source or Object form.
71
+
72
+ ### 3. Grant of Patent License.
73
+
74
+ Subject to the terms and conditions of this License, each Contributor hereby
75
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
76
+ irrevocable (except as stated in this section) patent license to make, have
77
+ made, use, offer to sell, sell, import, and otherwise transfer the Work, where
78
+ such license applies only to those patent claims licensable by such Contributor
79
+ that are necessarily infringed by their Contribution(s) alone or by combination
80
+ of their Contribution(s) with the Work to which such Contribution(s) was
81
+ submitted. If You institute patent litigation against any entity (including a
82
+ cross-claim or counterclaim in a lawsuit) alleging that the Work or a
83
+ Contribution incorporated within the Work constitutes direct or contributory
84
+ patent infringement, then any patent licenses granted to You under this License
85
+ for that Work shall terminate as of the date such litigation is filed.
86
+
87
+ ### 4. Redistribution.
88
+
89
+ You may reproduce and distribute copies of the Work or Derivative Works thereof
90
+ in any medium, with or without modifications, and in Source or Object form,
91
+ provided that You meet the following conditions:
92
+
93
+ a. You must give any other recipients of the Work or Derivative Works a copy of
94
+ this License; and
95
+
96
+ b. You must cause any modified files to carry prominent
97
+ notices stating that You changed the files; and
98
+
99
+ c. You must retain, in the
100
+ Source form of any Derivative Works that You distribute, all copyright, patent,
101
+ trademark, and attribution notices from the Source form of the Work, excluding
102
+ those notices that do not pertain to any part of the Derivative Works; and
103
+
104
+ d. If the Work includes a "NOTICE" text file as part of its distribution, then
105
+ any Derivative Works that You distribute must include a readable copy of the
106
+ attribution notices contained within such NOTICE file, excluding those notices
107
+ that do not pertain to any part of the Derivative Works, in at least one of the
108
+ following places: within a NOTICE text file distributed as part of the
109
+ Derivative Works; within the Source form or documentation, if provided along
110
+ with the Derivative Works; or, within a display generated by the Derivative
111
+ Works, if and wherever such third-party notices normally appear. The contents
112
+ of the NOTICE file are for informational purposes only and do not modify the
113
+ License. You may add Your own attribution notices within Derivative Works that
114
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
115
+ provided that such additional attribution notices cannot be construed as
116
+ modifying the License. You may add Your own copyright statement to Your
117
+ modifications and may provide additional or different license terms and
118
+ conditions for use, reproduction, or distribution of Your modifications, or for
119
+ any such Derivative Works as a whole, provided Your use, reproduction, and
120
+ distribution of the Work otherwise complies with the conditions stated in this
121
+ License.
122
+
123
+ ### 5. Submission of Contributions.
124
+
125
+ Unless You explicitly state otherwise, any Contribution intentionally submitted
126
+ for inclusion in the Work by You to the Licensor shall be under the terms and
127
+ conditions of this License, without any additional terms or conditions.
128
+ Notwithstanding the above, nothing herein shall supersede or modify the terms
129
+ of any separate license agreement you may have executed with Licensor regarding
130
+ such Contributions.
131
+
132
+ ### 6. Trademarks.
133
+
134
+ This License does not grant permission to use the trade names, trademarks,
135
+ service marks, or product names of the Licensor, except as required for
136
+ reasonable and customary use in describing the origin of the Work and
137
+ reproducing the content of the NOTICE file.
138
+
139
+ ### 7. Disclaimer of Warranty.
140
+
141
+ Unless required by applicable law or agreed to in writing, Licensor provides
142
+ the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
143
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
144
+ including, without limitation, any warranties or conditions of TITLE,
145
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
146
+ solely responsible for determining the appropriateness of using or
147
+ redistributing the Work and assume any risks associated with Your exercise of
148
+ permissions under this License.
149
+
150
+ ### 8. Limitation of Liability.
151
+
152
+ In no event and under no legal theory, whether in tort (including negligence),
153
+ contract, or otherwise, unless required by applicable law (such as deliberate
154
+ and grossly negligent acts) or agreed to in writing, shall any Contributor be
155
+ liable to You for damages, including any direct, indirect, special, incidental,
156
+ or consequential damages of any character arising as a result of this License
157
+ or out of the use or inability to use the Work (including but not limited to
158
+ damages for loss of goodwill, work stoppage, computer failure or malfunction,
159
+ or any and all other commercial damages or losses), even if such Contributor
160
+ has been advised of the possibility of such damages.
161
+
162
+ ### 9. Accepting Warranty or Additional Liability.
163
+
164
+ While redistributing the Work or Derivative Works thereof, You may choose to
165
+ offer, and charge a fee for, acceptance of support, warranty, indemnity, or
166
+ other liability obligations and/or rights consistent with this License.
167
+ However, in accepting such obligations, You may act only on Your own behalf and
168
+ on Your sole responsibility, not on behalf of any other Contributor, and only
169
+ if You agree to indemnify, defend, and hold each Contributor harmless for any
170
+ liability incurred by, or claims asserted against, such Contributor by reason
171
+ of your accepting any such warranty or additional liability.
172
+
173
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1 @@
1
+ include requirements.txt
@@ -0,0 +1,16 @@
1
+ Selective
2
+ Copyright 2020 and onwards FMR LLC.
3
+
4
+ This product includes software developed at
5
+ FMR LLC (https://www.fidelity.com/).
6
+
7
+ This product relies on the following works (and the dependencies thereof), installed separately:
8
+ - catboost | apache 2 | https://github.com/catboost/catboost
9
+ - lightgbm | mit | https://github.com/microsoft/LightGBM
10
+ - minepy | gpl-3.0-only | https://github.com/minepy/minepy
11
+ - numpy | bsd-3 | https://github.com/numpy/numpy
12
+ - pandas | bsd-3 | https://github.com/pandas-dev/pandas
13
+ - scikit-learn | bsd-3 |https://github.com/scikit-learn/scikit-learn
14
+ - seaborn | bsd-3 | https://github.com/mwaskom/seaborn
15
+ - statsmodels | bsd-3 | https://github.com/statsmodels/statsmodels
16
+ - xgboost | apache-2.0 | https://github.com/dmlc/xgboost
@@ -0,0 +1,250 @@
1
+ Metadata-Version: 2.4
2
+ Name: selective
3
+ Version: 1.2.0
4
+ Summary: feature selection library
5
+ Home-page: https://github.com/fidelity/selective
6
+ Author: FMR LLC
7
+ Project-URL: Source, https://github.com/fidelity/selective
8
+ Classifier: License :: OSI Approved :: Apache Software License
9
+ Classifier: Programming Language :: Python :: 3.8
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE.md
14
+ License-File: NOTICES
15
+ Requires-Dist: catboost
16
+ Requires-Dist: joblib
17
+ Requires-Dist: lightgbm
18
+ Requires-Dist: numpy
19
+ Requires-Dist: mip
20
+ Requires-Dist: pandas
21
+ Requires-Dist: scikit-learn
22
+ Requires-Dist: seaborn
23
+ Requires-Dist: statsmodels
24
+ Requires-Dist: textwiser
25
+ Requires-Dist: xgboost
26
+ Dynamic: author
27
+ Dynamic: classifier
28
+ Dynamic: description
29
+ Dynamic: description-content-type
30
+ Dynamic: home-page
31
+ Dynamic: license-file
32
+ Dynamic: project-url
33
+ Dynamic: requires-dist
34
+ Dynamic: requires-python
35
+ Dynamic: summary
36
+
37
+ [![ci](https://github.com/fidelity/selective/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fidelity/selective/actions/workflows/ci.yml) [![PyPI version fury.io](https://badge.fury.io/py/selective.svg)](https://pypi.python.org/pypi/selective/) [![PyPI license](https://img.shields.io/pypi/l/selective.svg)](https://pypi.python.org/pypi/selective/) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) [![Downloads](https://static.pepy.tech/personalized-badge/selective?period=total&units=international_system&left_color=grey&right_color=orange&left_text=Downloads)](https://pepy.tech/project/selective)
38
+
39
+
40
+ # Selective: Feature Selection Library
41
+ **Selective** is a white-box feature selection library that supports supervised and unsupervised selection methods for classification and regression tasks.
42
+
43
+ The library provides:
44
+
45
+ * Simple to complex selection methods: Variance, Correlation, Statistical, Linear, Tree-based, or Customized.
46
+ * [Text-based selection](#text-based-selection) to maximize diversity in text embeddings and metadata coverage.
47
+ * Interoperable with data frames as the input.
48
+ * Automated task detection. No need to know what feature selection method works with what machine learning task.
49
+ * Benchmarking multiple selectors using cross-validation with built-in parallelization.
50
+ * Inspection of the results and feature importance.
51
+
52
+ Selective also provides optimized item selection based on diversity of text embeddings via [TextWiser](https://github.com/fidelity/textwiser) and
53
+ coverage of binary labels via multi-objective optimization ([AMAI'24](https://trebuchet.public.springernature.app/get_content/2c9eb6df-5c2b-42bc-89d6-4e3eb8bc8799?utm_source=rct_congratemailt&utm_medium=email&utm_campaign=nonoa_20240405&utm_content=10.1007/s10472-024-09941-x), [CPAIOR'21](https://link.springer.com/chapter/10.1007/978-3-030-78230-6_27), [DSO@IJCAI'22](https://arxiv.org/abs/2112.03105)). This approach speeds-up online experimentation and boosts recommender systems significantly as presented at [NVIDIA GTC'22](https://www.youtube.com/watch?v=_v-B2nRy79w).
54
+
55
+ Selective is developed by the Artificial Intelligence Center of Excellence at Fidelity Investments.
56
+
57
+ ## Quick Start
58
+ ```python
59
+ # Import Selective and SelectionMethod
60
+ from sklearn.datasets import fetch_california_housing
61
+ from feature.utils import get_data_label
62
+ from feature.selector import Selective, SelectionMethod
63
+
64
+ # Data
65
+ data, label = get_data_label(fetch_california_housing())
66
+
67
+ # Feature selectors from simple to more complex
68
+ selector = Selective(SelectionMethod.Variance(threshold=0.0))
69
+ selector = Selective(SelectionMethod.Correlation(threshold=0.5, method="pearson"))
70
+ selector = Selective(SelectionMethod.Statistical(num_features=3, method="anova"))
71
+ selector = Selective(SelectionMethod.Linear(num_features=3, regularization="none"))
72
+ selector = Selective(SelectionMethod.TreeBased(num_features=3))
73
+
74
+ # Feature reduction
75
+ subset = selector.fit_transform(data, label)
76
+ print("Reduction:", list(subset.columns))
77
+ print("Scores:", list(selector.get_absolute_scores()))
78
+ ```
79
+
80
+
81
+ ## Available Methods
82
+
83
+ | Method | Options |
84
+ |:--------------------------------------------------------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
85
+ | [Variance per Feature](https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.VarianceThreshold.html) | `threshold` |
86
+ | [Correlation pairwise Features](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.corr.html) | [Pearson Correlation Coefficient](https://en.wikipedia.org/wiki/Pearson_correlation_coefficient) <br> [Kendall Rank Correlation Coefficient](https://en.wikipedia.org/wiki/Kendall_rank_correlation_coefficient) <br> [Spearman's Rank Correlation Coefficient](https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient) <br> |
87
+ | [Statistical Analysis](https://scikit-learn.org/stable/modules/feature_selection.html#univariate-feature-selection) | [ANOVA F-test Classification](https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.f_classif.html) <br> [F-value Regression](https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.f_regression.html) <br> [Chi-Square](https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.chi2.html) <br> [KL Divergence](https://en.wikipedia.org/wiki/Kullback–Leibler_divergence) <br> [Mutual Information Classification](https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.mutual_info_classif.html) <br> [Variance Inflation Factor](https://www.statsmodels.org/stable/generated/statsmodels.stats.outliers_influence.variance_inflation_factor.html) |
88
+ | [Linear Methods](https://en.wikipedia.org/wiki/Linear_regression) | [Linear Regression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html?highlight=linear%20regression#sklearn.linear_model.LinearRegression) <br> [Logistic Regression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html?highlight=logistic%20regression#sklearn.linear_model.LogisticRegression) <br> [Lasso Regularization](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Lasso.html#sklearn.linear_model.Lasso) <br> [Ridge Regularization](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Ridge.html#sklearn.linear_model.Ridge) <br> |
89
+ | [Tree-based Methods](https://scikit-learn.org/stable/modules/tree.html) | [Decision Tree](https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html#sklearn.tree.DecisionTreeClassifier) <br> [Random Forest](https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html?highlight=random%20forest#sklearn.ensemble.RandomForestClassifier) <br> [Extra Trees Classifier](https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.ExtraTreesClassifier.html) <br> [XGBoost](https://xgboost.readthedocs.io/en/latest/) <br> [LightGBM](https://lightgbm.readthedocs.io/en/latest/) <br> [AdaBoost](https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.AdaBoostClassifier.html) <br> [CatBoost](https://github.com/catboost)<br> [Gradient Boosting Tree](http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.GradientBoostingClassifier.html) <br> |
90
+ | [Text-based Methods](https://link.springer.com/chapter/10.1007/978-3-030-78230-6_27) | `featurization_method` = [TextWiser](https://github.com/fidelity/textwiser) <br> `optimization_method = ["exact", "greedy", "kmeans", "random"]` <br> `cost_metric = ["unicost", "diverse"]` |
91
+
92
+
93
+
94
+ ## Benchmarking
95
+
96
+ ```python
97
+ # Imports
98
+ from sklearn.datasets import fetch_california_housing
99
+ from feature.utils import get_data_label
100
+ from xgboost import XGBClassifier, XGBRegressor
101
+ from feature.selector import SelectionMethod, benchmark, calculate_statistics
102
+
103
+ # Data
104
+ data, label = get_data_label(fetch_california_housing())
105
+
106
+ # Selectors
107
+ corr_threshold = 0.5
108
+ num_features = 3
109
+ tree_params = {"n_estimators": 50, "max_depth": 5, "random_state": 111, "n_jobs": 4}
110
+ selectors = {
111
+
112
+ # Correlation methods
113
+ "corr_pearson": SelectionMethod.Correlation(corr_threshold, method="pearson"),
114
+ "corr_kendall": SelectionMethod.Correlation(corr_threshold, method="kendall"),
115
+ "corr_spearman": SelectionMethod.Correlation(corr_threshold, method="spearman"),
116
+
117
+ # Statistical methods
118
+ "stat_anova": SelectionMethod.Statistical(num_features, method="anova"),
119
+ "stat_chi_square": SelectionMethod.Statistical(num_features, method="chi_square"),
120
+ "stat_kl_divergence": SelectionMethod.Statistical(num_features, method="kl_divergence"),
121
+ "stat_mutual_info": SelectionMethod.Statistical(num_features, method="mutual_info"),
122
+
123
+ # Linear methods
124
+ "linear": SelectionMethod.Linear(num_features, regularization="none"),
125
+ "lasso": SelectionMethod.Linear(num_features, regularization="lasso", alpha=1000),
126
+ "ridge": SelectionMethod.Linear(num_features, regularization="ridge", alpha=1000),
127
+
128
+ # Non-linear tree-based methods
129
+ "random_forest": SelectionMethod.TreeBased(num_features),
130
+ "xgboost_classif": SelectionMethod.TreeBased(num_features, estimator=XGBClassifier(**tree_params)),
131
+ "xgboost_regress": SelectionMethod.TreeBased(num_features, estimator=XGBRegressor(**tree_params))
132
+ }
133
+
134
+ # Benchmark (sequential)
135
+ score_df, selected_df, runtime_df = benchmark(selectors, data, label, cv=5)
136
+ print(score_df, "\n\n", selected_df, "\n\n", runtime_df)
137
+
138
+ # Benchmark (in parallel)
139
+ score_df, selected_df, runtime_df = benchmark(selectors, data, label, cv=5, n_jobs=4)
140
+ print(score_df, "\n\n", selected_df, "\n\n", runtime_df)
141
+
142
+ # Get benchmark statistics by feature
143
+ stats_df = calculate_statistics(score_df, selected_df)
144
+ print(stats_df)
145
+ ```
146
+
147
+ ## Text-based Selection
148
+ This example shows how to use text-based selection. In this scenario, we would like to select a subset of articles that is most diverse in the text embedding space and covers a range of topics.
149
+
150
+ ```python
151
+ # Import Selective and TextWiser
152
+ import pandas as pd
153
+ from feature.selector import Selective, SelectionMethod
154
+ from textwiser import TextWiser, Embedding, Transformation
155
+
156
+ # Data with the text content of each article
157
+ data = pd.DataFrame({"article_1": ["article text here"],
158
+ "article_2": ["article text here"],
159
+ "article_3": ["article text here"],
160
+ "article_4": ["article text here"],
161
+ "article_5": ["article text here"]})
162
+
163
+ # Labels to denote 0/1 coverage metadata for each article
164
+ # across four labels, e.g., sports, international, entertainment, science
165
+ labels = pd.DataFrame({"article_1": [1, 1, 0, 1],
166
+ "article_2": [0, 1, 0, 0],
167
+ "article_3": [0, 0, 1, 0],
168
+ "article_4": [0, 0, 1, 1],
169
+ "article_5": [1, 1, 1, 0]},
170
+ index=["label_1", "label_2", "label_3", "label_4"])
171
+
172
+ # TextWiser featurization method to create text embeddings
173
+ textwiser = TextWiser(Embedding.TfIdf(), Transformation.NMF(n_components=20))
174
+
175
+ # Text-based selection
176
+ # The goal is to select a subset of articles
177
+ # that is most diverse in the text embedding space of articles
178
+ # and covers the most labels in each topic
179
+ selector = Selective(SelectionMethod.TextBased(num_features=2, featurization_method=textwiser))
180
+
181
+ # Feature reduction
182
+ subset = selector.fit_transform(data, labels)
183
+ print("Reduction:", list(subset.columns))
184
+ ```
185
+
186
+ ## Visualization
187
+
188
+ ```python
189
+ import pandas as pd
190
+ from sklearn.datasets import fetch_california_housing
191
+ from feature.utils import get_data_label
192
+ from feature.selector import SelectionMethod, Selective, plot_importance
193
+
194
+ # Data
195
+ data, label = get_data_label(fetch_california_housing())
196
+
197
+ # Feature Selector
198
+ selector = Selective(SelectionMethod.Linear(num_features=8, regularization="none"))
199
+ subset = selector.fit_transform(data, label)
200
+
201
+ # Plot Feature Importance
202
+ df = pd.DataFrame(selector.get_absolute_scores(), index=data.columns)
203
+ plot_importance(df)
204
+ ```
205
+
206
+ ## Installation
207
+
208
+ Selective requires **Python 3.8+** and can be installed from PyPI using ``pip install selective``.
209
+
210
+ ## Source
211
+
212
+ Alternatively, you can build a wheel package on your platform from scratch using the source code:
213
+
214
+ ```bash
215
+ git clone https://github.com/fidelity/selective.git
216
+ cd selective
217
+ pip install setuptools wheel # if wheel is not installed
218
+ python setup.py sdist bdist_wheel
219
+ pip install dist/selective-X.X.X-py3-none-any.whl
220
+ ```
221
+
222
+ ## Test your setup
223
+
224
+ ```
225
+ cd selective
226
+ python -m unittest discover tests
227
+ ```
228
+
229
+ ## Citation
230
+
231
+ If you use Selective in a publication, please cite it as:
232
+
233
+ ```bibtex
234
+ @article{DBLP:journals/amai/HaDVH98,
235
+ author = {Kad\i{}o\u{g}lu, Serdar and Kleynhans, Bernard and Wang, Xin},
236
+ title = {Integrating optimized item selection with active learning for continuous exploration in recommender systems},
237
+ journal = {Ann. Math. Artif. Intell.},
238
+ year = {2024},
239
+ url = {https://doi.org/10.1007/s10472-024-09941-x},
240
+ doi = {10.1007/s10472-024-09941-x},
241
+ }
242
+ }
243
+ ```
244
+
245
+ ## Support
246
+
247
+ Please submit bug reports and feature requests as [Issues](https://github.com/fidelity/selective/issues).
248
+
249
+ ## License
250
+ Selective is licensed under [Apache 2.0](https://github.com/fidelity/selective/blob/master/LICENSE.md)
@@ -4,9 +4,6 @@
4
4
  # Selective: Feature Selection Library
5
5
  **Selective** is a white-box feature selection library that supports supervised and unsupervised selection methods for classification and regression tasks.
6
6
 
7
- Selective also provides optimized item selection based on diversity of text embeddings (via [TextWiser](https://github.com/fidelity/textwiser)) and
8
- the coverage of binary labels by solving a multi-objective optimization problem ([CPAIOR'21](https://link.springer.com/chapter/10.1007/978-3-030-78230-6_27), [DSO@IJCAI'22](https://arxiv.org/abs/2112.03105)). The approach showed to speed-up online experimentation significantly and boost recommender systems [NVIDIA GTC'22](https://www.youtube.com/watch?v=_v-B2nRy79w).
9
-
10
7
  The library provides:
11
8
 
12
9
  * Simple to complex selection methods: Variance, Correlation, Statistical, Linear, Tree-based, or Customized.
@@ -16,6 +13,9 @@ The library provides:
16
13
  * Benchmarking multiple selectors using cross-validation with built-in parallelization.
17
14
  * Inspection of the results and feature importance.
18
15
 
16
+ Selective also provides optimized item selection based on diversity of text embeddings via [TextWiser](https://github.com/fidelity/textwiser) and
17
+ coverage of binary labels via multi-objective optimization ([AMAI'24](https://trebuchet.public.springernature.app/get_content/2c9eb6df-5c2b-42bc-89d6-4e3eb8bc8799?utm_source=rct_congratemailt&utm_medium=email&utm_campaign=nonoa_20240405&utm_content=10.1007/s10472-024-09941-x), [CPAIOR'21](https://link.springer.com/chapter/10.1007/978-3-030-78230-6_27), [DSO@IJCAI'22](https://arxiv.org/abs/2112.03105)). This approach speeds-up online experimentation and boosts recommender systems significantly as presented at [NVIDIA GTC'22](https://www.youtube.com/watch?v=_v-B2nRy79w).
18
+
19
19
  Selective is developed by the Artificial Intelligence Center of Excellence at Fidelity Investments.
20
20
 
21
21
  ## Quick Start
@@ -48,7 +48,7 @@ print("Scores:", list(selector.get_absolute_scores()))
48
48
  |:--------------------------------------------------------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
49
49
  | [Variance per Feature](https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.VarianceThreshold.html) | `threshold` |
50
50
  | [Correlation pairwise Features](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.corr.html) | [Pearson Correlation Coefficient](https://en.wikipedia.org/wiki/Pearson_correlation_coefficient) <br> [Kendall Rank Correlation Coefficient](https://en.wikipedia.org/wiki/Kendall_rank_correlation_coefficient) <br> [Spearman's Rank Correlation Coefficient](https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient) <br> |
51
- | [Statistical Analysis](https://scikit-learn.org/stable/modules/feature_selection.html#univariate-feature-selection) | [ANOVA F-test Classification](https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.f_classif.html) <br> [F-value Regression](https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.f_regression.html) <br> [Chi-Square](https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.chi2.html) <br> [Mutual Information Classification](https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.mutual_info_classif.html) <br> [Variance Inflation Factor](https://www.statsmodels.org/stable/generated/statsmodels.stats.outliers_influence.variance_inflation_factor.html) |
51
+ | [Statistical Analysis](https://scikit-learn.org/stable/modules/feature_selection.html#univariate-feature-selection) | [ANOVA F-test Classification](https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.f_classif.html) <br> [F-value Regression](https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.f_regression.html) <br> [Chi-Square](https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.chi2.html) <br> [KL Divergence](https://en.wikipedia.org/wiki/Kullback–Leibler_divergence) <br> [Mutual Information Classification](https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.mutual_info_classif.html) <br> [Variance Inflation Factor](https://www.statsmodels.org/stable/generated/statsmodels.stats.outliers_influence.variance_inflation_factor.html) |
52
52
  | [Linear Methods](https://en.wikipedia.org/wiki/Linear_regression) | [Linear Regression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html?highlight=linear%20regression#sklearn.linear_model.LinearRegression) <br> [Logistic Regression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html?highlight=logistic%20regression#sklearn.linear_model.LogisticRegression) <br> [Lasso Regularization](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Lasso.html#sklearn.linear_model.Lasso) <br> [Ridge Regularization](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Ridge.html#sklearn.linear_model.Ridge) <br> |
53
53
  | [Tree-based Methods](https://scikit-learn.org/stable/modules/tree.html) | [Decision Tree](https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html#sklearn.tree.DecisionTreeClassifier) <br> [Random Forest](https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html?highlight=random%20forest#sklearn.ensemble.RandomForestClassifier) <br> [Extra Trees Classifier](https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.ExtraTreesClassifier.html) <br> [XGBoost](https://xgboost.readthedocs.io/en/latest/) <br> [LightGBM](https://lightgbm.readthedocs.io/en/latest/) <br> [AdaBoost](https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.AdaBoostClassifier.html) <br> [CatBoost](https://github.com/catboost)<br> [Gradient Boosting Tree](http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.GradientBoostingClassifier.html) <br> |
54
54
  | [Text-based Methods](https://link.springer.com/chapter/10.1007/978-3-030-78230-6_27) | `featurization_method` = [TextWiser](https://github.com/fidelity/textwiser) <br> `optimization_method = ["exact", "greedy", "kmeans", "random"]` <br> `cost_metric = ["unicost", "diverse"]` |
@@ -81,6 +81,7 @@ selectors = {
81
81
  # Statistical methods
82
82
  "stat_anova": SelectionMethod.Statistical(num_features, method="anova"),
83
83
  "stat_chi_square": SelectionMethod.Statistical(num_features, method="chi_square"),
84
+ "stat_kl_divergence": SelectionMethod.Statistical(num_features, method="kl_divergence"),
84
85
  "stat_mutual_info": SelectionMethod.Statistical(num_features, method="mutual_info"),
85
86
 
86
87
  # Linear methods
@@ -168,7 +169,7 @@ plot_importance(df)
168
169
 
169
170
  ## Installation
170
171
 
171
- Selective requires **Python 3.7+** and can be installed from PyPI using ``pip install selective``.
172
+ Selective requires **Python 3.8+** and can be installed from PyPI using ``pip install selective``.
172
173
 
173
174
  ## Source
174
175
 
@@ -189,9 +190,25 @@ cd selective
189
190
  python -m unittest discover tests
190
191
  ```
191
192
 
193
+ ## Citation
194
+
195
+ If you use Selective in a publication, please cite it as:
196
+
197
+ ```bibtex
198
+ @article{DBLP:journals/amai/HaDVH98,
199
+ author = {Kad\i{}o\u{g}lu, Serdar and Kleynhans, Bernard and Wang, Xin},
200
+ title = {Integrating optimized item selection with active learning for continuous exploration in recommender systems},
201
+ journal = {Ann. Math. Artif. Intell.},
202
+ year = {2024},
203
+ url = {https://doi.org/10.1007/s10472-024-09941-x},
204
+ doi = {10.1007/s10472-024-09941-x},
205
+ }
206
+ }
207
+ ```
208
+
192
209
  ## Support
193
210
 
194
211
  Please submit bug reports and feature requests as [Issues](https://github.com/fidelity/selective/issues).
195
212
 
196
213
  ## License
197
- Selective is licensed under the [GNU GPL 3.0.](https://github.com/fidelity/selective/blob/master/LICENSE)
214
+ Selective is licensed under [Apache 2.0](https://github.com/fidelity/selective/blob/master/LICENSE.md)
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Copyright FMR LLC <opensource@fidelity.com>
3
- # SPDX-License-Identifier: GNU GPLv3
3
+ # SPDX-License-Identifier: Apache-2.0
4
4
 
5
- __version__ = "1.1.2"
5
+ __version__ = "1.2.0"
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Copyright FMR LLC <opensource@fidelity.com>
3
- # SPDX-License-Identifier: GNU GPLv3
3
+ # SPDX-License-Identifier: Apache-2.0
4
4
 
5
5
  """
6
6
  :Author: FMR LLC
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Copyright FMR LLC <opensource@fidelity.com>
3
- # SPDX-License-Identifier: GNU GPLv3
3
+ # SPDX-License-Identifier: Apache-2.0
4
4
 
5
5
  import numpy as np
6
6
  import pandas as pd
@@ -0,0 +1,66 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright FMR LLC <opensource@fidelity.com>
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ from typing import NoReturn, Tuple
6
+
7
+ import pandas as pd
8
+ import numpy as np
9
+
10
+ from scipy.special import rel_entr
11
+ from feature.base import _BaseSupervisedSelector
12
+ from feature.utils import Num, check_true
13
+
14
+
15
+ class _KL_Divergence(_BaseSupervisedSelector):
16
+
17
+ def __init__(self, seed: int, num_features: Num, num_bins: Num = 100):
18
+ super().__init__(seed)
19
+
20
+ self.num_features = num_features # this could be int or float
21
+ self.num_bins = num_bins
22
+
23
+ def fit(self, X: pd.DataFrame, y: pd.Series) -> NoReturn:
24
+
25
+ label_categories = np.unique(y)
26
+ check_true(len(label_categories) == 2, TypeError("Only binary labels are supported for KL Divergence"))
27
+ input_dimension = X.shape[1]
28
+
29
+ kl_mat = np.zeros((input_dimension, 1))
30
+ X = X.values
31
+
32
+ class_one_idx = np.where(y == label_categories[0])[0]
33
+ class_two_idx = np.where(y == label_categories[1])[0]
34
+
35
+ for i in range(input_dimension):
36
+
37
+ # Create two distributions, one for the positive label and one for the negative label
38
+ f1 = np.histogram(X[class_one_idx, i], bins = self.num_bins)[0]
39
+ f2 = np.histogram(X[class_two_idx, i], bins = self.num_bins)[0]
40
+
41
+ # Normalize the distributions to be between 0 and 1
42
+ f1 = f1 / np.sum(f1)
43
+ f2 = f2 / np.sum(f2)
44
+
45
+ # KL Divergence is not symmetric, so we calculate divergence in both directions
46
+ kl = rel_entr(f1, f2)
47
+ kl_reversed = rel_entr(f2, f1)
48
+
49
+ # The relative entropy function returns KL(P || Q) = np.inf when P == 0 and Q != 0.
50
+ kl[kl == np.inf] = 9999
51
+ kl_reversed[kl_reversed == np.inf] = 9999
52
+
53
+ # The final score is the combination of KL divergence in both directions.
54
+ # This could possibly be a flag in a future version to determine which direction to apply KL Divergence
55
+ # in if bidirectional is not desired.
56
+ kl_mat[i] = np.sum(kl) + np.sum(kl_reversed)
57
+
58
+ scores_ = kl_mat.flatten()
59
+
60
+ self.scores_ = scores_ # This is used by the statistical.py fit function.
61
+ self.abs_scores = scores_
62
+
63
+ def transform(self, data: pd.DataFrame) -> pd.DataFrame:
64
+
65
+ # Select top-k from data based on abs_scores and num_features
66
+ return self.get_top_k(data, self.abs_scores)
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # Copyright FMR LLC <opensource@fidelity.com>
3
- # SPDX-License-Identifier: GNU GPLv3
3
+ # SPDX-License-Identifier: Apache-2.0
4
4
 
5
5
  from typing import NoReturn, Tuple
6
6