Kaggle competition: Temperature Forecasting
df_scaled = pd.read_feather('/kaggle/input/scaling/df_scaled.feather')
 df_scaled = downcast_dtypes(df_scaled)
 X_train = df_scaled.iloc[:X_train_iloc]
X_valid = df_scaled.iloc[X_train_iloc:X_valid_iloc]
X_test = df_scaled.iloc[X_valid_iloc:]
del df_scaled
gc.collect()
print('The scaled variables are', X_train.columns )<compute_train_metric>
def create_data(x, len_seq):
X = []
y = []
for i in range(len(x)- len_seq):
X.append(x[i:i+len_seq])
 y.append(x[i+len_seq])
 return np.array(X), np.array(y)
 df = pd.read_csv('.. /input/train.csv', index_col=0)
 x = df['Min temp.'].values
len_seq = 121
X, y = create_data(x, len_seq)
 X = np.reshape(X,(X.shape[0], X.shape[1], 1))
print(X.shape)
 print(y.shape )
ensembler = XGBRegressor(
 max_depth=2,
n_estimators=150,
min_child_weight=100,
colsample_bytree=0.75,
subsample=0.75,
eta=0.1,
seed=42)
 kfold = KFold(n_splits=5, random_state=42)
 y_pred = cross_val_predict(ensembler, df_reg_valid, y_valid, cv=kfold)
 print('The cross validation RMSE is', np.sqrt(mean_squared_error(y_valid, y_pred)) )<create_dataframe>
model = Sequential()
model.add(LSTM(units=64, return_sequences=False, input_shape=(len_seq, 1)))
 model.add(Dropout(0.2))
model.add(Dense(units=1, activation='linear'))
model.compile(loss='mean_squared_error', optimizer='adam')
 model.summary()
df_mean_analysis = pd.DataFrame()
df_mean_analysis['group'] = df_reg_valid['group']
df_mean_analysis['lightgbm'] = df_reg_valid['lightgbm']
df_mean_analysis['ridge'] = df_reg_valid['ridge']
df_mean_analysis['ensemble'] = y_pred
df_mean_analysis['target'] = y_valid.values
df_mean_analysis.groupby('group' ).agg(np.mean )<prepare_output>
model.fit(X, y, batch_size=365, epochs=100, validation_split=0.1 )
df_mean_analysis = pd.DataFrame()
df_mean_analysis['group'] = df_reg_test['group']
df_mean_analysis['lightgbm'] = df_reg_test['lightgbm']
df_mean_analysis['ridge'] = df_reg_test['ridge']
df_mean_analysis['pred'] = ensembler.predict(df_reg_test)
 df_mean_analysis.groupby('group' ).agg(np.mean )<set_options>
x = df['Min temp.'].values[len(x)-len_seq:]
predict = np.array([])
 for i in range(365):
X = np.reshape(x,(1, len_seq, 1))
p = model.predict(X)[0]
predict = np.append(predict, p)
 x = np.append(np.delete(x, 0), p)
 %matplotlib inline
plt.plot(predict)
 plt.show()
<save_to_csv><EOS> 
submit = pd.read_csv('.. /input/sampleSubmission.csv')
 submit['Min temp.'] = predict
submit.to_csv('submission.csv', index=False )