Last active
August 6, 2020 15:47
-
-
Save netsatsawat/d07dd195bdb956c294a7ce48eccf4a4b to your computer and use it in GitHub Desktop.
Snippet code for feed forward neural network
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import random | |
from sklearn.datasets import make_regression | |
import tensorflow as tf | |
from tensorflow import keras | |
from tensorflow.keras import layers | |
# require for installation: !pip install -q git+https://github.com/tensorflow/docs | |
import tensorflow_docs as tfdocs | |
import tensorflow_docs.plots | |
import tensorflow_docs.modeling | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
np.set_printoptions(suppress=True) | |
SEED = 515 | |
X, y, coef = make_regression(n_samples=10000, n_features=5, noise=12.3, | |
bias=100, random_state=121, coef_ind=True) | |
model = keras.Sequential([ | |
layers.Dense(16, activation='relu', input_shape=[X.shape[1]]), | |
layers.Dense(1) | |
]) | |
optimizer = tf.keras.optimizers.RMSprop(0.001) | |
model.compile(loss='mse', | |
optimizer=optimizer, | |
metrics=['mae', 'mse']) | |
history = model.fit( | |
X, y, epochs=500, validation_split=0.2, verbose=0, | |
callbacks=[tfdocs.modeling.EpochDots()] | |
) | |
plotter = tfdocs.plots.HistoryPlotter(smoothing_std=2) | |
plt.figure(figsize=(6, 4)) | |
plotter.plot({'Basic': history}, metric="mae") | |
plt.ylabel('MAE [y]') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment