Kaggle competition: Home Credit Default Risk
modelo = linear_model.LinearRegression(normalize = False, fit_intercept = True )<compute_test_metric>
M1 = pd.read_csv('.. /input/home123/11111.csv')
 M2 = pd.read_csv('.. /input/home123/22222.csv')
 M3 = pd.read_csv('.. /input/home123/33333.csv')
 M4 = pd.read_csv('.. /input/home123/44444.csv')
 M5 = pd.read_csv('.. /input/home123/55555.csv')
 M6 = pd.read_csv('.. /input/home123/Think1.csv')
 M7 = pd.read_csv('.. /input/home123/new1submit8aug.csv')
 M8 = pd.read_csv('.. /input/home123/newthinking.csv')
 M9 = pd.read_csv('.. /input/home123/Think123.csv' )
def r2_est(X,y):
return r2_score(y, modelo.fit(X,y ).predict(X ).clip(1,100))<compute_test_metric>
def merge_dataframes(dfs, merge_keys):
dfs_merged = reduce(lambda left,right: pd.merge(left, right, on=merge_keys), dfs)
 return dfs_merged
def mean_absolute_error(y, y_pred):
return(1 / len(y)) * np.sum(np.abs(y - y_pred))<compute_test_metric>
dfs = [M1,M2,M3,M4,M5,M6,M7,M8,M9]
merge_keys=['SK_ID_CURR']
df = merge_dataframes(dfs, merge_keys=merge_keys )
print('Baseline R2: %0.3f' % r2_est(X,y))<predict_on_test>
df.columns = ['SK_ID_CURR','T1','T2','T3','T4','T5','T6','T7','T8','T9']
df.head()
predictions = modelo.fit(X,y ).predict(X ).clip(1,100)
 predictions<compute_test_metric>
pred_prob = 0.6 * df['T9'] + 0.4 * df['T6']
pred_prob.head()
<compute_test_metric>
sub = pd.DataFrame()
sub['SK_ID_CURR'] = df['SK_ID_CURR']
sub['target']= pred_prob
print('MAE test score: %0.3f' % mean_absolute_error(y, predictions))<define_variables>
sub.to_csv('ldit.csv', index=False )
num_folds = 10
num_instances = len(X)
 seed = 998
modelos = []
modelos.append(( 'LINEAR', LinearRegression()))
modelos.append(( 'RIDGE', Ridge()))
modelos.append(( 'LASSO', Lasso()))
modelos.append(( 'ELASTIC', ElasticNet()))
modelos.append(( 'KNN', KNeighborsRegressor()))
modelos.append(( 'CART', DecisionTreeRegressor()))
resultados = []
nomes = []
for nome, modelo in modelos:
kfold = model_selection.KFold(n_splits = num_folds, random_state = seed)
 cv_results = model_selection.cross_val_score(modelo, X, y, cv = kfold, scoring = 'neg_mean_absolute_error')
 resultados.append(cv_results)
 nomes.append(nome)
 msg = "%s: %.3f(%.3f)" %(nome, cv_results.mean() , cv_results.std())
 print(msg )<define_variables>
B_prob = 0.4 * df['T9'] + 0.15 * df['T4'] + 0.15 * df['T6'] + 0.15 *df['T1'] + 0.15*df['T5']
num_folds = 10
num_instances = len(X)
 seed = 998
modelos = []
modelos.append(( 'AD', AdaBoostRegressor()))
modelos.append(( 'BG', BaggingRegressor()))
modelos.append(( 'ET', ExtraTreesRegressor()))
modelos.append(( 'GB', GradientBoostingRegressor()))
modelos.append(( 'RF', RandomForestRegressor()))
modelos.append(( 'XGB', XGBRegressor()))
resultados = []
nomes = []
for nome, modelo in modelos:
kfold = model_selection.KFold(n_splits = num_folds, random_state = seed)
 cv_results = model_selection.cross_val_score(modelo, X, y, cv = kfold, scoring = 'neg_mean_absolute_error')
 resultados.append(cv_results)
 nomes.append(nome)
 msg = "%s: %.3f(%.3f)" %(nome, cv_results.mean() , cv_results.std())
 print(msg )<drop_column>
SUB = pd.DataFrame()
SUB['SK_ID_CURR'] = df['SK_ID_CURR']
SUB['TARGET'] = B_prob
SUB.to_csv('Blendss.csv', index=False )
<drop_column><EOS> 
SuB = pd.DataFrame()
SuB['SK_ID_CURR'] = df['SK_ID_CURR']
SuB['TARGET'] = corr_pred
SuB.to_csv('corr_blend.csv', index=False )