NN-based Regression
1 Observe the data from statistical department
1 |
|
plot the trainset
1 |
|
2 Divide dataset and preprocess dataset
2.1 Divide dataset
First, you should divide the dataset into a trainset and a testset. As an example, we can define 80%80% of the raw dataset is trainset and the other 20%20% is testset.
1 |
|
observe the trainset and testset in different color
1 | plt.figure(figsize=(6,4))plotData(train_x, train_y) #plotData(x-axis,y-axis)plotData(test_x, test_y)plt.legend(["Trainset","Testset"])plt.show() |
2.2 Preprocess dataset
Before training, we need to preprocess our trainset.
Because the values in dataset are too big, computation of loss may be difficult. So, one method of preprocessing is normalization.
In this case, we can do normalization by
Normalized Value=RawValue/NormalizeFactor
1 |
|
3 Describe your neural network
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
describe the model
1 |
|
4 Training
We declare a variable to record the number of iteration.
1 |
|
5 Evaluation of the trained model
1 |
|
6 Post-processing and final prediction
Before predicting, we need to post-process the output of the trained model.
In above, we use normalization to preprocess. So, we use denormalization to post-process the output of the trained model and get the final predict results.
First, we define a function to denormalize.
Prediction=(Normalized Value)×(Normalize Factor)
1 |
|