Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
[MRG + 2] fix selectFdr bug #7490
What does this implement/fix? Explain your changes.
selectFdr in scikit-learn/sklearn/feature_selection/univariate_selection.py:
def _get_support_mask(self): check_is_fitted(self, 'scores_') n_features = len(self.pvalues_) sv = np.sort(self.pvalues_) **selected = sv[sv <= float(self.alpha) / n_features * np.arange(n_features)]** if selected.size == 0: return np.zeros_like(self.pvalues_, dtype=bool) return self.pvalues_ <= selected.max()
selected = sv[sv <= float(self.alpha) / n_features * (np.arange(n_features) + 1)]
Because np.arange is start from 0, here it should be start from 1
Any other comments?
Such a test could be that provided with only one p-value, that the function returns the approriate answer (ie, in this case that if the p-value is small enough but not 0, it should be selected - in master, it would only be selected if the p-value is equal to 0, but now it would be selected if the p-value is smaller than
hi @jnothman , sorry for late reply because of national holiday.
I propose the following method to show our change works,
def test_select_fdr_regression2(): X, y = make_regression(n_samples=150, n_features=20, n_informative=5, shuffle=False, random_state=0, noise=10) with warnings.catch_warnings(record=True): # Warnings can be raised when no features are selected # (low alpha or very noisy data) univariate_filter = SelectFdr(f_regression, alpha=0.01) univariate_filter.fit(X, y) support = univariate_filter.get_support() num_false_positives = np.sum(support[n_informative:] == 1) num_true_positives = np.sum(support[:n_informative] == 1) assert_equal(num_false_positives, 5) assert_equal(num_true_positives, 7)
How do you think about it?
referenced this pull request
Oct 17, 2016
It should be okay to include the test here.
On 18 October 2016 at 12:29, Meng, Peng firstname.lastname@example.org wrote:
Looks good to me apart from adding the link.