Kaggle competition: Don't Overfit! II
<SOS> metric: AUC Kaggle data source: dont-overfit!-ii<define_variables>
py.init_notebook_mode(connected=True)
 warnings.filterwarnings('ignore' )
important_features = ['X314','X315','X119','X118','X263','X136','X29','X279','X5','X232','X76','X54','X189','X47','X104','X8','1_count_percent','1_count','X2',
'X3','X275','X65','X26','X6','X127','X1','X267','X311','X283','X0','X77','X341','X287','X13','X241','X46','X162','X117','X82','X105']<save_to_csv>
target_col = ["target"]
id_dataset = ["id"]
num_cols = [x for x in data.columns if x not in target_col + id_dataset]
std = StandardScaler()
scaled = std.fit_transform(data[num_cols])
 scaled = pd.DataFrame(scaled,columns=num_cols)
 df_data_og = data.copy()
data = data.drop(columns = num_cols,axis = 1)
 data = data.merge(scaled,left_index=True,right_index=True,how = "left")
 data = data.drop(columns = ['id'],axis = 1 )
sub['y'] = reg.predict(test[important_features])
 sub.to_csv('quick_and_dirty_Random_forest.csv', index=False);<set_options>
test = pd.read_csv('.. /input/test.csv')
 target_col = ["target"]
id_dataset = ["id"]
num_cols = [x for x in test.columns if x not in target_col + id_dataset]
std = StandardScaler()
scaled = std.fit_transform(test[num_cols])
 scaled = pd.DataFrame(scaled,columns=num_cols)
 df_test_og = test.copy()
test = test.drop(columns = num_cols,axis = 1)
 test = test.merge(scaled,left_index=True,right_index=True,how = "left")
 test = test.drop(columns = ['id'],axis = 1 )
%matplotlib inline
def ignore_warn(*args, **kwargs):
pass
warnings.warn = ignore_warn
print(os.listdir(".. /input"))
color = sns.color_palette() 
<load_from_csv>
X = data.drop('target', 1)
 y = data['target']
data = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv')
 sub_df = pd.read_csv('.. /input/sample_submission.csv' )<filter>
random_state = 42
log_clf = LogisticRegression(random_state = random_state)
 param_grid = {'class_weight' : ['balanced', None],
'penalty' : ['l2','l1'],
'C' : [0.001, 0.01, 0.1, 1, 10, 100, 1000]}
grid = GridSearchCV(estimator = log_clf, param_grid = param_grid , scoring = 'roc_auc', verbose = 1, n_jobs = -1)
 grid.fit(X,y)
 print("Best Score:" + str(grid.best_score_))
print("Best Parameters: " + str(grid.best_params_))
best_parameters = grid.best_params_
data = data[data.y < 250]<categorify>
log_clf = LogisticRegression(**best_parameters)
 log_clf.fit(X,y)
 selector = RFE(log_clf, 25, step=1)
 selector.fit(X,y)
 scores_table(selector, 'selector_clf' )
train_objs_num = len(data)
 dataset = pd.concat(objs=[data, test], axis=0)
 dataset = pd.get_dummies(dataset)
 data = copy.copy(dataset[:train_objs_num])
 test = copy.copy(dataset[train_objs_num:] )<prepare_x_and_y>
submission = pd.read_csv('.. /input/sample_submission.csv')
 X_test = test
submission['target'] = selector.predict_proba(X_test)
 submission.to_csv('submission.csv', index=False )