def test_compare_with_no_feature_selection():
'''
compare the result before the selection and after
:return: None
'''
iris=load_iris()
X,y=iris.data,iris.target
estimator=LinearSVC()
selector=RFE(estimator=estimator,n_features_to_select=2)
X_t=selector.fit_transform(X,y)
X_train,X_test,y_train,y_test=cross_validation.train_test_split(X, y,
test_size=0.25,random_state=0,stratify=y)
X_train_t,X_test_t,y_train_t,y_test_t=cross_validation.train_test_split(X_t, y,
test_size=0.25,random_state=0,stratify=y)
clf=LinearSVC()
clf_t=LinearSVC()
clf.fit(X_train,y_train)
clf_t.fit(X_train_t,y_train_t)
print("Original DataSet: test score=%s"%(clf.score(X_test,y_test)))
print("Selected DataSet: test score=%s"%(clf_t.score(X_test_t,y_test_t)))
11.6 feature_selection_bagging.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录