Kaggle competition: INGV - Volcanic Eruption Prediction
<SOS> metric: MAE Kaggle data source: ingv-volcanic-eruption-prediction<concatenate>
import numpy as np
import pandas as pd
import lightgbm as lgb
import os
df = pd.concat([train, test],sort=False)
 df = df.reset_index(drop=True )<count_missing_values>
print(h2o.__version__)
 h2o.init(max_mem_size='16G' )
def print_missing(df):
for col in df.columns.tolist() :
if df[col].isnull().sum() :
print('{}: {}'.format(col, df[col].isnull().sum()))<feature_engineering>
train = pd.read_csv('/kaggle/input/predict-volcanic-eruptions-ingv-oe/train.csv')
 test = pd.read_csv('/kaggle/input/predict-volcanic-eruptions-ingv-oe/sample_submission.csv' )
df.loc[df['Alley'].isnull() ,'Alley'] = 'None'
df.loc[df['Fence'].isnull() ,'Fence'] = 'None'
df.loc[df['MiscFeature'].isnull() ,'MiscFeature'] = 'None'<filter>
scaled_feature_df = pd.read_csv('.. /input/ingv-tsfresh-7730/train.csv', sep = ';', index_col=0)
 scaled_feature_df = scaled_feature_df.loc[train['segment_id']]
scaled_test_df = pd.read_csv('.. /input/ingv-tsfresh-7730/test.csv', sep = ';', index_col=0)
 scaled_test_df = scaled_test_df.loc[test['segment_id']]
df.loc[np.logical_and(df['PoolArea'] != 0, df['PoolQC'].isnull()),
['PoolArea', 'PoolQC', 'OverallQual']]<feature_engineering>
from sklearn.feature_selection import SelectFromModel
df.loc[2420,['PoolQC']] = 2
df.loc[2599,['PoolQC']] = 2
df.loc[2503,['PoolQC']] = 3
df['PoolQC'].fillna('None', inplace=True )<count_values>
sfm = SelectFromModel(estimator=lgb.LGBMRegressor())
 X = scaled_feature_df.drop('time_to_eruption',axis=1 ).copy()
X.columns = list(np.arange(len(X.columns)))
 y = scaled_feature_df['time_to_eruption']
sfm.fit(X, y )
df['MasVnrType'].value_counts()<filter>
selected_features = list(scaled_feature_df.drop('time_to_eruption',axis=1 ).columns[sfm.get_support() ])
 selected_features
df.loc[df['MasVnrArea'].isnull() | df['MasVnrType'].isnull() ][['MasVnrArea','MasVnrType']]<feature_engineering>
print('Number of selected features: ' + str(len(selected_features)) )
df.loc[df['MasVnrArea'].isnull() ,['MasVnrArea','MasVnrType']] = [0, 'None']
df.loc[df['MasVnrType'].isnull() ,['MasVnrType']] = 'None'<count_missing_values>
scaled_feature_df = scaled_feature_df[selected_features]
scaled_test_df = scaled_test_df[selected_features]
print(len(df.loc[df['BsmtQual'].isnull() & df['BsmtCond'].isnull() & df['BsmtExposure'].isnull() &
df['BsmtFinType1'].isnull() & df['BsmtFinType2'].isnull() ]))<filter>
train_h2o = h2o.H2OFrame(scaled_feature_df)
 train_label_h2o = h2o.H2OFrame(train[['time_to_eruption']])
 train_h2o['time_to_eruption'] = train_label_h2o['time_to_eruption']
test_feature_h2o = h2o.H2OFrame(scaled_test_df )
df.loc[(df['BsmtFinType1'].notnull())&(df['BsmtQual'].isnull() | df['BsmtCond'].isnull() | df['BsmtExposure'].isnull() | df['BsmtFinType2'].isnull())][['BsmtQual','BsmtCond','BsmtExposure','BsmtFinType1','BsmtFinSF1','BsmtFinType2',\
'BsmtFinSF2','BsmtUnfSF','TotalBsmtSF','BsmtFullBath','BsmtHalfBath']]<feature_engineering>
x = test_feature_h2o.columns
y = 'time_to_eruption'
df.BsmtQual.loc[[2217, 2218]] = df.BsmtQual.mode() [0]
df.BsmtCond.loc[[2040, 2185, 2524]]= df.BsmtCond.mode() [0]
df.BsmtFinType2.loc[[332]] = df.BsmtFinType2.mode() [0]
df.BsmtExposure.loc[[948, 1487, 2348]] = df.BsmtExposure.mode() [0]
df.BsmtQual.fillna('None', inplace=True)
 df.BsmtCond.fillna('None', inplace=True)
 df.BsmtExposure.fillna('None', inplace=True)
 df.BsmtFinType1.fillna('None', inplace=True)
 df.BsmtFinType2.fillna('None', inplace=True)
 df.BsmtFinSF1.fillna(0, inplace=True)
 df.BsmtFinSF2.fillna(0, inplace=True)
 df.BsmtUnfSF.fillna(0, inplace=True)
 df.TotalBsmtSF.fillna(0, inplace=True)
 df.BsmtFullBath.fillna(0, inplace=True)
 df.BsmtHalfBath.fillna(0, inplace=True )<filter>
aml = H2OAutoML(max_models=1000, seed=121, stopping_metric='MAE',
max_runtime_secs=360*60)
 aml.train(x=x, y=y, training_frame=train_h2o )
len(df.loc[df.GarageType.isnull() & df.GarageFinish.isnull() & df.GarageQual.isnull() & df.GarageCond.isnull() ,
['GarageType','GarageYrBlt','GarageFinish','GarageCars','GarageArea','GarageQual','GarageCond']] )<filter>
aml.leader
df.loc[df.GarageType.notnull() &(df.GarageFinish.isnull() | df.GarageQual.isnull() | df.GarageCond.isnull()),
['GarageType','GarageFinish','GarageCars','GarageArea','GarageQual','GarageCond']]<feature_engineering>
preds = aml.predict(test_feature_h2o )
<feature_engineering><EOS> 
submission = pd.DataFrame()
submission['segment_id'] = test['segment_id']
submission['time_to_eruption'] = preds.as_data_frame().values.flatten()
submission.loc[submission['time_to_eruption']<0, 'time_to_eruption'] = 0
submission.to_csv('submission_recent.csv', header=True, index=False )