Skip to content

Commit 114b0dc

Browse files
Merge pull request #12 from MatthewSZhang/docs
DOC fix wrong pick in plot_redundancy
2 parents 839b4e0 + 14defe6 commit 114b0dc

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ FastCan is a feature selection method, which has following advantages:
3939

4040
#. Skip redundant features.
4141

42-
#. Evalaute relative usefulness of features.
42+
#. Evaluate relative usefulness of features.
4343

4444
Check `Home Page <https://fastcan.readthedocs.io/en/latest/?badge=latest>`_ for more information.
4545

examples/plot_redundancy.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
2-
===================================================
3-
Feature selection performance on redundant features
4-
===================================================
2+
=================================
3+
Performance on redundant features
4+
=================================
55
66
.. currentmodule:: fastcan
77
@@ -109,8 +109,7 @@ def get_n_missed(
109109
n_missed_dep = len(
110110
np.setdiff1d(dep_info_ids+redundant_ids, selected_ids)
111111
)-n_redundant
112-
if n_missed_dep < 0:
113-
n_missed_dep = 0
112+
n_missed_dep = max(n_missed_dep, 0)
114113
return n_missed_indep+n_missed_dep
115114

116115
# %%
@@ -160,7 +159,7 @@ def get_n_missed(
160159
N_REPEATED = 10
161160

162161
selector_dict = {
163-
"fastcan": FastCan(N_SELECTED, verbose=0),
162+
"fastcan": FastCan(N_SELECTED, tol=1e-7, verbose=0),
164163
"skb_reg": SelectKBest(f_regression, k=N_SELECTED),
165164
"skb_mir": SelectKBest(mutual_info_regression, k=N_SELECTED),
166165
"sfm_lsvr": SelectFromModel(lsvr, max_features=N_SELECTED, threshold=-np.inf),
@@ -179,7 +178,7 @@ def get_n_missed(
179178
n_missed = np.zeros((N_REPEATED, N_SELECTORS), dtype=int)
180179

181180
for i in range(N_REPEATED):
182-
X, y = make_redundant(
181+
data, target = make_redundant(
183182
n_samples=N_SAMPLES,
184183
n_features=N_FEATURES,
185184
dep_info_ids=DEP_INFO_IDS,
@@ -188,7 +187,7 @@ def get_n_missed(
188187
random_seed=i,
189188
)
190189
for j, selector in enumerate(selector_dict.values()):
191-
result_ids = selector.fit(X, y).get_support(indices=True)
190+
result_ids = selector.fit(data, target).get_support(indices=True)
192191
n_missed[i, j] = get_n_missed(
193192
dep_info_ids=DEP_INFO_IDS,
194193
indep_info_ids=INDEP_INFO_IDS,

fastcan/_utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ def ols(X, y, t=1):
8080
scores : ndarray of shape (n_features_to_select,), dtype=float
8181
The scores of selected features. The order of
8282
the scores is corresponding to the feature selection process.
83+
84+
Examples
85+
--------
86+
>>> from fastcan import ols
87+
>>> X = [[1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 0, 0]]
88+
>>> y = [1, 0, 1, 0]
89+
>>> indices, scores = ols(X, y, 2)
90+
>>> indices
91+
array([0, 2])
92+
>>> scores
93+
array([0.5, 0.5])
8394
"""
8495
X, y = check_X_y(X, y, dtype=float, ensure_2d=True)
8596
n_features = X.shape[1]

pixi.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)