Kaggle competition: DL for exploration geophysics
<SOS> metric: rmse Kaggle data source: dl-for-exploration-geophysics<choose_model_class>
import numpy as np
import pandas as pd
submit_confirmed=[]
submit_fatal=[]
for i in df1:
data = i.ConfirmedCases.astype('int32' ).tolist()
try:
model = SARIMAX(data, order=(1,1,0), seasonal_order=(1,1,0,12),measurement_error=True)
 model_fit = model.fit(disp=False)
 predicted = model_fit.predict(len(data), len(data)+34)
 new=np.concatenate(( np.array(data),np.array([int(num)for num in predicted])) ,axis=0)
 submit_confirmed.extend(list(new[-43:]))
except:
submit_confirmed.extend(list(data[-10:-1]))
for j in range(34):
submit_confirmed.append(data[-1]*2)
 data = i.Fatalities.astype('int32' ).tolist()
try:
model = SARIMAX(data, order=(1,1,0), seasonal_order=(1,1,0,12),measurement_error=True)
 model_fit = model.fit(disp=False)
 predicted = model_fit.predict(len(data), len(data)+34)
 new=np.concatenate(( np.array(data),np.array([int(num)for num in predicted])) ,axis=0)
 submit_fatal.extend(list(new[-43:]))
except:
submit_fatal.extend(list(data[-10:-1]))
for j in range(34):
submit_fatal.append(data[-1]*2 )<data_type_conversions>
test = pd.read_csv("/kaggle/input/mldl-competition-1/test.csv")
 train = pd.read_csv("/kaggle/input/mldl-competition-1/train.csv")
 sampleSabmission = pd.read_csv("/kaggle/input/mldl-competition-1/sampleSubmission.csv" )
df_submit=pd.concat([pd.Series(np.arange(1,1+len(submit_confirmed))),pd.Series(submit_confirmed),pd.Series(submit_fatal)],axis=1)
 df_submit=df_submit.fillna(method='pad' ).astype(int)
 df_submit.head()<merge>
print(tf.__version__)
df_submit.rename(columns={0: 'ForecastId', 1: 'ConfirmedCases',2: 'Fatalities',}, inplace=True)
 complete_test= pd.merge(test, df_submit, how="left", on="ForecastId")
 complete_test.head()<save_to_csv>
column_names = ['Id' 'X','Y','Z','Time']
X_train_orig = train[["X", "Y", "Z"]]
X_test_orig = test[["X", "Y", "Z"]]
Y_train_orig = train["Time"]
print(X_train_orig.shape)
 print(X_test_orig.shape)
 print(Y_train_orig.shape)
df_submit.to_csv('submission.csv',header=['ForecastId','ConfirmedCases','Fatalities'],index=False)
 complete_test.to_csv('complete_test.csv',index=False )<set_options>
scaler = MinMaxScaler(feature_range=(-1, 1), copy=True)
 scaler.fit(X_train_orig)
 print("Maximum values of X_train(X, Y, Z): " + str(scaler.data_max_))
print("Minimum values of X_train(X, Y, Z): " + str(scaler.data_min_))
X_train_norm = scaler.transform(X_train_orig)
 X_test_norm = scaler.transform(X_test_orig)
pd.set_option("display.max_columns", 200)
 pd.set_option("display.max_rows", 200 )<load_from_csv>
X_train, X_val, y_train, y_val = train_test_split(X_train_norm, Y_train_orig, test_size=0.2)
 print(X_train.shape)
 print(y_train.shape)
 print(X_val.shape)
 print(y_val.shape )
country_info = pd.read_csv("/kaggle/input/countryinfo/covid19countryinfo.csv")
 country_info = country_info.rename({"region": "state"}, axis=1)
 country_info.loc[country_info["state"].isna() , "state"] = "Unknown"
country_info = country_info.drop([col for col in country_info.columns if "Unnamed" in col], axis=1)
 country_info["pop"] = country_info["pop"].str.replace(',', '' ).astype(float)
 pollution = pd.read_csv("/kaggle/input/pollution-by-country-for-covid19-analysis/region_pollution.csv")
 pollution = pollution.rename({"Region": "country",
"Outdoor Pollution(deaths per 100000)": "outdoor_pol",
"Indoor Pollution(deaths per 100000)": "indoor_pol"}, axis=1)
 economy = pd.read_csv("/kaggle/input/the-economic-freedom-index/economic_freedom_index2019_data.csv", engine='python')
 economy_cols = [col for col in economy.columns if economy[col].dtype == "float64"] + ["Country"]
economy = economy[economy_cols]
economy = economy.rename({"Country": "country"}, axis=1)
 def append_external_data(df):
df = pd.merge(df, country_info, on=["country", "state"], how="left")
 df = pd.merge(df, pollution, on="country", how="left")
 df = pd.merge(df, economy, on="country", how="left")
 return df<feature_engineering>
model = keras.Sequential([
keras.layers.Dense(128, input_dim=3, activation='relu'),
keras.layers.Dense(6, activation='relu'),
keras.layers.Dense(1, activation="linear")
 ])
 print(model.summary())
country_info["publicplace"] = np.where(country_info["publicplace"].str.contains("/"), country_info["publicplace"], np.nan )<count_values>
model.compile(optimizer='adam',
loss='MSE',
metrics=['accuracy'] )
country_info["publicplace"].value_counts()<define_variables>
history = model.fit(X_train, y_train, validation_data=(X_val, y_val), epochs=5 )
list_rel_columns = ['state', 'country', 'pop', 'tests',
'testpop', 'density', 'medianage', 'urbanpop', 'quarantine', 'schools',
'publicplace', 'gatheringlimit', 'gathering', 'nonessential',
'hospibed', 'smokers', 'sex0', 'sex14', 'sex25', 'sex54', 'sex64',
'sex65plus', 'sexratio', 'lung', 'femalelung', 'malelung', 'gdp2019',
'healthexp', 'healthperpop', 'fertility']<drop_column>
test_loss, test_acc = model.evaluate(X_val, y_val, verbose=0)
 print('
Test loss:', test_loss)
 print('
Test accuracy:', test_acc )
country_info = country_info[list_rel_columns]<filter>
predictions = model.predict(X_test_norm )
<merge><EOS> 
mySubmission = sampleSabmission
mySubmission["Predicted"] = predictions
mySubmission.head()
filename = 'IvanPredictions_1.csv'
mySubmission.to_csv(filename,index=False)
 print('Saved file: ' + filename )