text_plain_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import tensorflow as tf

df = pd.read_csv('/kaggle/input/playground-series-s3e9/train.csv')
df.drop(columns='id', inplace=True)

df_add = pd.read_csv('/kaggle/input/predict-concrete-strength/ConcreteStrengthData.csv')
df_add.rename(columns={'CementComponent ': 'CementComponent'}, inplace=True)
df = pd.concat([df, df_add])

df_test = pd.read_csv('/kaggle/input/playground-series-s3e9/test.csv')
df_test.drop(columns='id', inplace=True)

y = df.pop('Strength')
df['tot_comp'] = df.iloc[:, :7].sum(axis=1)
df['ageinmonth'] = df.AgeInDays // 30 / 12
df['AgeInDays'] = df.AgeInDays / 365
df_test['tot_comp'] = df_test.iloc[:, :7].sum(axis=1)
df_test['ageinmonth'] = df_test.AgeInDays // 30 / 12
df_test['AgeInDays'] = df_test.AgeInDays / 365

df_transform = df.iloc[:, :7].transform(lambda x: x / df.tot_comp)
df_transform = pd.concat([df_transform, df.AgeInDays, df.ageinmonth], axis=1)
df_test_transform = df_test.iloc[:, :7].transform(lambda x: x / df_test.tot_comp)
df_test_transform = pd.concat([df_test_transform, df_test.AgeInDays, df_test.ageinmonth], axis=1)

model_nn = tf.keras.Sequential(name='neural_network')
model_nn.add(tf.keras.layers.Dense(9, activation='relu', input_shape=(df_transform.shape[1],)))
model_nn.add(tf.keras.layers.Dense(16, activation='relu'))
model_nn.add(tf.keras.layers.Dense(1, activation='relu'))
model_nn.summary()

tf.random.set_seed(9)
model_nn.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.0003), loss='mse', metrics=tf.keras.metrics.RootMeanSquaredError())
history = model_nn.fit(df_transform, y, batch_size=64, epochs=250, validation_split=0.3, verbose=2)

plt.plot(history.history['root_mean_squared_error'][10:], label='train RMSE')
plt.plot(history.history['val_root_mean_squared_error'][10:], label='valid RMSE')
plt.legend()