<s> from sklearn import cross_validation <EOL> from sklearn . metrics import * <EOL> from sklearn . svm import SVC <EOL> from sklearn . neighbors import KNeighborsClassifier <EOL> from sklearn . tree import DecisionTreeClassifier <EOL> from sklearn . ensemble import RandomForestClassifier <EOL> from sklearn . naive_bayes import GaussianNB <EOL> class Classifier : <EOL> def __init__ ( self , input_data , classifier_type , train_data_percentage , input_features , target_feature ) : <EOL> self . input_data = input_data <EOL> self . train_data_percentage = train_data_percentage <EOL> self . target_feature = target_feature <EOL> self . input_features = input_features <EOL> self . parallel_jobs = <NUM_LIT:1> <EOL> if classifier_type == '<STR_LIT>' : <EOL> self . clf = SVC ( kernel = '<STR_LIT>' , C = <NUM_LIT> ) <EOL> elif classifier_type == '<STR_LIT>' : <EOL> self . clf = KNeighborsClassifier ( <NUM_LIT:3> ) <EOL> elif classifier_type == '<STR_LIT>' : <EOL> self . clf = DecisionTreeClassifier ( max_depth = <NUM_LIT:5> ) <EOL> elif classifier_type == '<STR_LIT>' : <EOL> self . clf = RandomForestClassifier ( max_depth = <NUM_LIT:5> , n_estimators = <NUM_LIT:10> , max_features = <NUM_LIT:1> , n_jobs = self . parallel_jobs ) <EOL> elif classifier_type == '<STR_LIT>' : <EOL> self . clf = GaussianNB ( ) <EOL> def learn ( self ) : <EOL> print "<STR_LIT>" , list ( self . input_features ) <EOL> print "<STR_LIT>" , self . target_feature <EOL> features = self . input_data [ self . input_features ] . values <EOL> labels = self . input_data [ self . target_feature ] . values <EOL> test_data_percentage = <NUM_LIT:1> - self . train_data_percentage <EOL> x_train , x_test , y_train , y_actual = cross_validation . train_test_split ( <EOL> features , labels , test_size = test_data_percentage , random_state = <NUM_LIT:0> ) <EOL> self . clf . fit ( x_train , y_train ) <EOL> y_pred = self . clf . predict ( x_test ) <EOL> accuracy = round ( accuracy_score ( y_actual , y_pred ) , <NUM_LIT:2> ) <EOL> recall = round ( recall_score ( y_actual , y_pred ) , <NUM_LIT:2> ) <EOL> precision = round ( precision_score ( y_actual , y_pred ) , <NUM_LIT:2> ) <EOL> f1 = round ( f1_score ( y_actual , y_pred ) , <NUM_LIT:2> ) <EOL> mat = confusion_matrix ( y_actual , y_pred ) <EOL> true_positives = mat [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> false_positives = mat [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> true_negatives = mat [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> false_negatives = mat [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> result = { <EOL> '<STR_LIT>' : accuracy , '<STR_LIT>' : recall , <EOL> '<STR_LIT>' : precision , '<STR_LIT>' : f1 , <EOL> '<STR_LIT>' : true_positives , <EOL> '<STR_LIT>' : false_positives , <EOL> '<STR_LIT>' : true_negatives , <EOL> '<STR_LIT>' : false_negatives <EOL> } <EOL> print result <EOL> return result </s>
