@author: FF120 """ import numpy as np from time import time from sklearn.svm import SVC from sklearn.ensemble import ExtraTreesClassifier from sklearn.feature_selection import SelectFromModel from sklearn.cross_validation import StratifiedKFold import fmriUtils as fm n_folds = 10 f = fm.outTo() #输出重定向到文件 X,y = fm.loadData2() y = fm.defineClass(y) t0 = time() forest = ExtraTreesClassifier(n_estimators=1000, max_features=1000, n_jobs=2, random_state=0) forest.fit(X, y) model = SelectFromModel(forest, threshold='2*mean',prefit=True) XX = model.transform(X) yy = y cv = StratifiedKFold(yy,n_folds) cv_scores = [] for train, test in cv:
@author: FF120 """ import numpy as np from sklearn.linear_model import LogisticRegression from sklearn.feature_selection import SelectFromModel from sklearn.svm import SVC from sklearn.cross_validation import StratifiedKFold from sklearn.linear_model import RandomizedLogisticRegression import fmriUtils as fm #自定义函数 n_folds = 10 f = fm.outTo() #输出重定向到文件 X, y = fm.loadData2() X2, y2 = fm.loadData2() y = fm.defineClass(y) randomized_logistic = RandomizedLogisticRegression(C=0.1, n_jobs=2) randomized_logistic.fit(X, y) XX = randomized_logistic.transform(X) print "============选择后剩余的特征================" print XX.shape yy = y cv = StratifiedKFold(yy, n_folds) cv_scores = [] for train, test in cv: svc = SVC(kernel='linear')
# -*- coding: utf-8 -*- """ 使用递归特征消除选取特征 """ from sklearn.svm import SVC from sklearn.cross_validation import StratifiedKFold from sklearn.feature_selection import RFECV import numpy as np import fmriUtils as fm n_folds = 5 f = fm.outTo() #输出重定向到文件 X, y = fm.loadData2() y = fm.defineClass(y) svc = SVC(kernel="linear") rfecv = RFECV(estimator=svc, step=1, cv=StratifiedKFold(y, n_folds), scoring='accuracy') rfecv.fit(X, y) print("Optimal number of features : %d" % rfecv.n_features_)
@author: FF120 """ import numpy as np from sklearn.linear_model import LogisticRegression from sklearn.feature_selection import SelectFromModel from sklearn.svm import SVC from sklearn.cross_validation import StratifiedKFold from sklearn.linear_model import RandomizedLogisticRegression import fmriUtils as fm #自定义函数 n_folds = 10 f = fm.outTo() #输出重定向到文件 X,y = fm.loadData2() X2,y2 = fm.loadData2() y = fm.defineClass(y) randomized_logistic = RandomizedLogisticRegression(C=0.1,n_jobs=2) randomized_logistic.fit(X,y) XX = randomized_logistic.transform(X) print "============选择后剩余的特征================" print XX.shape yy = y cv = StratifiedKFold(yy,n_folds) cv_scores = [] for train, test in cv: svc = SVC(kernel='linear')