Kaggle competition: Don't Overfit! II
x = sample(space)
 subsample = x['boosting_type'].get('subsample', 1.0)
 x['boosting_type'] = x['boosting_type']['boosting_type']
x['subsample'] = subsample
x<feature_engineering>
train=pd.read_csv('.. /input/train.csv')
 test=pd.read_csv('.. /input/test.csv' )
x = sample(space)
 subsample = x['boosting_type'].get('subsample', 1.0)
 x['boosting_type'] = x['boosting_type']['boosting_type']
x['subsample'] = subsample
x<save_to_csv>
train = train.set_index('id' , drop = True)
OUT_FILE = 'bayes_test.csv'
of_connection = open(OUT_FILE, 'w')
 writer = csv.writer(of_connection)
 ITERATION = 0
headers = ['loss', 'hyperparameters', 'iteration', 'runtime', 'score']
writer.writerow(headers)
 of_connection.close()
results = objective(sample(space))
print('The cross validation loss = {:.5f}.'.format(results['loss']))
print('The optimal number of estimators was {}.'.format(results['hyperparameters']['n_estimators']))<find_best_params>
test=test.set_index('id',drop=True )
tpe_algorithm = tpe.suggest<choose_model_class>
y=train['target']
train=train.drop(['target'],axis=1)
 train.info()
trials = Trials()<save_to_csv>
scaler = StandardScaler()
train=scaler.fit_transform(train)
 test=scaler.transform(test )
OUT_FILE = 'bayes_test.csv'
of_connection = open(OUT_FILE, 'w')
 writer = csv.writer(of_connection)
 ITERATION = 0
headers = ['loss', 'hyperparameters', 'iteration', 'runtime', 'score']
writer.writerow(headers)
 of_connection.close()<import_modules>
clf = LogisticRegression(class_weight='balanced', solver='liblinear', penalty ='l1', C= 0.1, max_iter=10000 ).fit(train, y)
 scores = cross_val_score(clf, train, y, cv=5)
 scores
from hyperopt import fmin<find_best_params>
clf.fit(train,y)
 ans = clf.predict_proba(test)
 ans
global ITERATION
ITERATION = 0
best = fmin(fn = objective, space = space, algo = tpe.suggest, trials = trials,
max_evals = MAX_EVALS)
 best<sort_values>
submit = pd.read_csv('.. /input/sample_submission.csv')
 submit.columns
trials_dict = sorted(trials.results, key = lambda x: x['loss'])
 trials_dict[:1]<load_from_csv>
submit['target'] = ans[:,1]
<find_best_params><EOS> 
submit.to_csv('submit.csv', index = False )