本文整理汇总了Python中sklearn.feature_selection.SelectFdr.get_support方法的典型用法代码示例。如果您正苦于以下问题:Python SelectFdr.get_support方法的具体用法?Python SelectFdr.get_support怎么用?Python SelectFdr.get_support使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.feature_selection.SelectFdr
的用法示例。
在下文中一共展示了SelectFdr.get_support方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: single_fdr
# 需要导入模块: from sklearn.feature_selection import SelectFdr [as 别名]
# 或者: from sklearn.feature_selection.SelectFdr import get_support [as 别名]
def single_fdr(alpha, n_informative, random_state):
X, y = make_regression(
n_samples=150,
n_features=20,
n_informative=n_informative,
shuffle=False,
random_state=random_state,
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=alpha)
X_r = univariate_filter.fit(X, y).transform(X)
X_r2 = GenericUnivariateSelect(f_regression, mode="fdr", param=alpha).fit(X, y).transform(X)
assert_array_equal(X_r, X_r2)
support = univariate_filter.get_support()
num_false_positives = np.sum(support[n_informative:] == 1)
num_true_positives = np.sum(support[:n_informative] == 1)
if num_false_positives == 0:
return 0.0
false_discovery_rate = num_false_positives / (num_true_positives + num_false_positives)
return false_discovery_rate
示例2: test_boundary_case_ch2
# 需要导入模块: from sklearn.feature_selection import SelectFdr [as 别名]
# 或者: from sklearn.feature_selection.SelectFdr import get_support [as 别名]
def test_boundary_case_ch2():
# Test boundary case, and always aim to select 1 feature.
X = np.array([[10, 20], [20, 20], [20, 30]])
y = np.array([[1], [0], [0]])
scores, pvalues = chi2(X, y)
assert_array_almost_equal(scores, np.array([4.0, 0.71428571]))
assert_array_almost_equal(pvalues, np.array([0.04550026, 0.39802472]))
filter_fdr = SelectFdr(chi2, alpha=0.1)
filter_fdr.fit(X, y)
support_fdr = filter_fdr.get_support()
assert_array_equal(support_fdr, np.array([True, False]))
filter_kbest = SelectKBest(chi2, k=1)
filter_kbest.fit(X, y)
support_kbest = filter_kbest.get_support()
assert_array_equal(support_kbest, np.array([True, False]))
filter_percentile = SelectPercentile(chi2, percentile=50)
filter_percentile.fit(X, y)
support_percentile = filter_percentile.get_support()
assert_array_equal(support_percentile, np.array([True, False]))
filter_fpr = SelectFpr(chi2, alpha=0.1)
filter_fpr.fit(X, y)
support_fpr = filter_fpr.get_support()
assert_array_equal(support_fpr, np.array([True, False]))
filter_fwe = SelectFwe(chi2, alpha=0.1)
filter_fwe.fit(X, y)
support_fwe = filter_fwe.get_support()
assert_array_equal(support_fwe, np.array([True, False]))
示例3: test_select_fdr_classif
# 需要导入模块: from sklearn.feature_selection import SelectFdr [as 别名]
# 或者: from sklearn.feature_selection.SelectFdr import get_support [as 别名]
def test_select_fdr_classif():
"""
Test whether the relative univariate feature selection
gets the correct items in a simple classification problem
with the fpr heuristic
"""
X, Y = make_classification(
n_samples=200,
n_features=20,
n_informative=3,
n_redundant=2,
n_repeated=0,
n_classes=8,
n_clusters_per_class=1,
flip_y=0.0,
class_sep=10,
shuffle=False,
random_state=0,
)
univariate_filter = SelectFdr(f_classif, alpha=0.0001)
X_r = univariate_filter.fit(X, Y).transform(X)
X_r2 = GenericUnivariateSelect(f_classif, mode="fdr", param=0.0001).fit(X, Y).transform(X)
assert_array_equal(X_r, X_r2)
support = univariate_filter.get_support()
gtruth = np.zeros(20)
gtruth[:5] = 1
assert_array_equal(support, gtruth)
示例4: test_select_fdr_regression
# 需要导入模块: from sklearn.feature_selection import SelectFdr [as 别名]
# 或者: from sklearn.feature_selection.SelectFdr import get_support [as 别名]
def test_select_fdr_regression():
"""
Test whether the relative univariate feature selection
gets the correct items in a simple regression problem
with the fdr heuristic
"""
X, Y = make_regression(n_samples=200, n_features=20, n_informative=5, shuffle=False, random_state=0)
univariate_filter = SelectFdr(f_regression, alpha=0.01)
X_r = univariate_filter.fit(X, Y).transform(X)
X_r2 = GenericUnivariateSelect(f_regression, mode="fdr", param=0.01).fit(X, Y).transform(X)
assert_array_equal(X_r, X_r2)
support = univariate_filter.get_support()
gtruth = np.zeros(20)
gtruth[:5] = 1
assert_array_equal(support, gtruth)
示例5: svm_cv
# 需要导入模块: from sklearn.feature_selection import SelectFdr [as 别名]
# 或者: from sklearn.feature_selection.SelectFdr import get_support [as 别名]
def svm_cv(data, data_target):
X_train, X_test, y_train, y_test = cross_validation.train_test_split(data, data_target)
print "*" * 79
print "Training..."
# selector = SelectFdr(chi2)
selector = SelectFdr(f_classif)
selector.fit(X_train, y_train)
clf = svm.SVC(kernel='linear', probability=True)
clf.fit(selector.transform(X_train), y_train)
print "Testing..."
pred = clf.predict(selector.transform(X_test))
probs = pred.predict_proba(selector.transfrom(X_test))
accuracy_score = metrics.accuracy_score(y_test, pred)
classification_report = metrics.classification_report(y_test, pred)
support = selector.get_support()
print support
print accuracy_score
print classification_report
precision, recall, thresholds = precision_recall_curve(y_test, probs[:, 1])