Kaggle competition: Don't Overfit! II
y = data['TARGET']
del data['TARGET']<categorify>
train = pd.read_csv('.. /input/train.csv' )
categorical_feature = [col for col in data.columns if data[col].dtype == 'object']<count_missing_values>
x_train = train.drop(['id' ,'target'] ,axis = 1 )
def missing_values_table(df):
mis_val = df.isnull().sum()
mis_val_percent = 100 * df.isnull().sum() / len(df)
 mis_val_table = pd.concat([mis_val, mis_val_percent], axis=1)
 mis_val_table_ren_columns = mis_val_table.rename(
 columns = {0 : 'Missing Values', 1 : '% of Total Values'})
 mis_val_table_ren_columns = mis_val_table_ren_columns[
mis_val_table_ren_columns.iloc[:,1] != 0].sort_values(
 '% of Total Values', ascending=False ).round(1)
 print("Your selected dataframe has " + str(df.shape[1])+ " columns.
 "
"There are " + str(mis_val_table_ren_columns.shape[0])+
" columns that have missing values.")
 return mis_val_table_ren_columns<count_missing_values>
test = pd.read_csv('.. /input/test.csv' )
missing_values = missing_values_table(data)
 missing_values.head(20 )<count_values>
test = test.drop('id',axis = 1 )
data.dtypes.value_counts()<count_unique_values>
scaler = StandardScaler()
x_train = scaler.fit_transform(x_train)
 test = scaler.fit_transform(test )
data.select_dtypes('object' ).nunique()<concatenate>
model_lasso = LassoCV(alphas = [0.05, 0.1, 0.3, 1, 3, 5, 10, 15, 30, 50, 75] ).fit(x_train, y_train )
one_hot_df = pd.concat([data, test] )<categorify>
lasso_preds = model_lasso.predict(test )
one_hot_df = pd.get_dummies(one_hot_df, columns=categorical_feature )<split>
lasso_preds=lasso_preds.T
data = one_hot_df.iloc[:data.shape[0],:]
test = one_hot_df.iloc[data.shape[0]:,]<groupby>
lasso_preds
test = pd.read_csv('.. /input/test.csv')
<groupby><EOS> 
solution = pd.DataFrame({"id":test.id, "target":lasso_preds})
 solution.to_csv("lasso_sol.csv", index = False )