<jupyter_start><jupyter_text>Load data and split into training data and validation data<jupyter_code>feature = pd.read_csv('https://raw.githubusercontent.com/BolunDai0216/nyuMLSummerSchool/master/day05/fish_market_feature.csv')
label = pd.read_csv('https://raw.githubusercontent.com/BolunDai0216/nyuMLSummerSchool/master/day05/fish_market_label.csv')
X_train, X_val, y_train, y_val = train_test_split(feature.values, label.values, test_size=0.1, random_state=3)<jupyter_output><empty_output><jupyter_text>Build Model1) Define a model of three dense layers with ReLu activation functions. The output of the two first layers should have 300 neurons. 2) Train the model for 2000 epochs with a batch size of 64 and a mean squared error loss.<jupyter_code>model = Sequential([
    Dense(300, activation='relu', input_shape=(5,)),
    Dense(300, activation='relu'),
    Dense(1, activation='linear')
])

model.compile(
    optimizer='Adam',
    loss='mean_squared_error',
    metrics=['mae']
)

model.summary()
history = model.fit(X_train, y_train, epochs=1000, batch_size=64, validation_data=(X_val, y_val))<jupyter_output>Epoch 1/1000
2/2 [==============================] - 0s 89ms/step - loss: 273110.1875 - mae: 397.4537 - val_loss: 167608.2188 - val_mae: 306.2967
Epoch 2/1000
2/2 [==============================] - 0s 49ms/step - loss: 260672.5469 - mae: 385.0561 - val_loss: 159061.4531 - val_mae: 295.0354
Epoch 3/1000
2/2 [==============================] - 0s 40ms/step - loss: 249618.2344 - mae: 374.1753 - val_loss: 151106.2344 - val_mae: 284.2177
Epoch 4/1000
2/2 [==============================] - 0s 34ms/step - loss: 239109.0156 - mae: 363.7162 - val_loss: 143290.8594 - val_mae: 273.2159
Epoch 5/1000
2/2 [==============================] - 0s 34ms/step - loss: 228335.8906 - mae: 353.2311 - val_loss: 135578.3594 - val_mae: 261.9686
Epoch 6/1000
2/2 [==============================] - 0s 33ms/step - loss: 218098.4844 - mae: 342.8240 - val_loss: 127392.2109 - val_mae: 249.5609
Epoch 7/1000
2/2 [==============================] - 0s 44ms/step - loss: 206527.4219 - mae: 330.9941 - val_loss: 118635.6172 - val[...]<jupyter_text>Load the testing dataset<jupyter_code>X_test = pd.read_csv('https://raw.githubusercontent.com/BolunDai0216/nyuMLSummerSchool/master/day05/fish_market_test_feature.csv').values
y_test = pd.read_csv('https://raw.githubusercontent.com/BolunDai0216/nyuMLSummerSchool/master/day05/fish_market_test_label.csv').values


# Predict the corresponding y_hat value of the test dataset
y_hat = model.predict(X_test)
plt.figure()
plt.scatter(np.arange(y_hat.shape[0]), y_hat, label='Prediction')
plt.scatter(np.arange(y_test.shape[0]), y_test, label='Ground Truth')
plt.legend()
plt.xlabel('data no.')
plt.ylabel('predicted value')
plt.show()
loss = history.history['val_loss']
plt.figure()
plt.plot(loss)
plt.xlabel('epochs')
plt.ylabel('loss')
plt.show()
history.history.keys()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20354585748380497, 'fraction_numerical': 0.121036481418343, 'mean_word_length': 5.4483516483516485, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '255935', 'license': 'MIT', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1073, 'n_words': 211, 'path': 'day06/lab_mlp_fish_market_keras_solution.ipynb', 'repo_name': 'noamorris/nyuMLSummerSchool', 'size': '2933'}