#NEWLINE# def __init__( self , clf_method = 'ERF' , classifier = None , param_grid = None ) : #NEWLINE# #INDENT# ' Initialize a new classifier instance ' #NEWLINE# self . features_selected = None #NEWLINE# self . predictions = None #NEWLINE# if ( classifier is not None ) : #NEWLINE# #INDENT# self . clf = classifier #NEWLINE# from sklearn.svm import LinearSVC #NEWLINE# import random #NEWLINE# if isinstance ( self . clf , LinearSVC ) : #NEWLINE# #INDENT# self . clf . set_params ( ) . random_state = random . randint ( 0 , 200 ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( clf_method == 'SVM' ) : #NEWLINE# #INDENT# from sklearn import svm #NEWLINE# self . clf = svm . SVC ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( clf_method == 'ERF' ) : #NEWLINE# #INDENT# from sklearn.ensemble import ExtraTreesClassifier #NEWLINE# self . clf = ExtraTreesClassifier ( n_estimators = 100 , max_depth = None , min_samples_split = 1 , random_state = 0 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( self == 'GBC' ) : #NEWLINE# #INDENT# from sklearn.ensemble import GradientBoostingClassifier #NEWLINE# self . clf = GradientBoostingClassifier ( n_estimators = 100 , max_depth = 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( clf_method == 'Dummy' ) : #NEWLINE# #INDENT# from sklearn.dummy import DummyClassifier #NEWLINE# self . clf = DummyClassifier ( strategy = 'stratified' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise Exception ( 'Unrecognized classification method' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if isinstance ( param_grid , dict ) : #NEWLINE# #INDENT# from sklearn.grid_search import GridSearchCV #NEWLINE# self . clf = GridSearchCV ( estimator = self . clf , param_grid = param_grid )