<s> import time <EOL> import pandas as pd <EOL> import numpy as np <EOL> import gc <EOL> from sklearn import cross_validation , naive_bayes , metrics , linear_model <EOL> from sklearn . pipeline import Pipeline <EOL> import matplotlib . pyplot as plt <EOL> import category_encoders <EOL> from source_data . loaders import get_cars_data , get_mushroom_data , get_splice_data <EOL> plt . style . use ( '<STR_LIT>' ) <EOL> __author__ = '<STR_LIT>' <EOL> def score_models ( clf , X , y , encoder , runs = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> scores = [ ] <EOL> X_test = None <EOL> for _ in range ( runs ) : <EOL> X_test = encoder ( ) . fit_transform ( X ) <EOL> scores . append ( cross_validation . cross_val_score ( clf , X_test , y , n_jobs = <NUM_LIT:1> , cv = <NUM_LIT:5> ) ) <EOL> gc . collect ( ) <EOL> scores = [ y for z in [ x for x in scores ] for y in z ] <EOL> return float ( np . mean ( scores ) ) , float ( np . std ( scores ) ) , scores , X_test . shape [ <NUM_LIT:1> ] <EOL> def main ( loader , name ) : <EOL> """<STR_LIT>""" <EOL> scores = [ ] <EOL> raw_scores_ds = { } <EOL> X , y , mapping = loader ( ) <EOL> X = category_encoders . ordinal_encoding ( X ) <EOL> clf = linear_model . LogisticRegression ( ) <EOL> encoders = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> for encoder_name in encoders : <EOL> encoder = category_encoders . __dict__ [ encoder_name ] <EOL> start_time = time . time ( ) <EOL> score , stds , raw_scores , dim = score_models ( clf , X , y , encoder ) <EOL> scores . append ( [ encoder_name , name , dim , score , stds , time . time ( ) - start_time ] ) <EOL> raw_scores_ds [ encoder_name ] = raw_scores <EOL> gc . collect ( ) <EOL> results = pd . DataFrame ( scores , columns = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> raw = pd . DataFrame . from_dict ( raw_scores_ds ) <EOL> ax = raw . plot ( kind = '<STR_LIT>' , return_type = '<STR_LIT>' ) <EOL> plt . title ( '<STR_LIT>' % ( name , ) ) <EOL> plt . ylabel ( '<STR_LIT>' ) <EOL> for tick in ax . get_xticklabels ( ) : <EOL> tick . set_rotation ( <NUM_LIT> ) <EOL> plt . grid ( ) <EOL> plt . tight_layout ( ) <EOL> plt . show ( ) <EOL> return results , raw <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> out , raw = main ( get_mushroom_data , '<STR_LIT>' ) <EOL> print ( out . sort_values ( by = [ '<STR_LIT>' , '<STR_LIT>' ] ) ) </s>
