Deep Learning¶

Practice Projects¶

P1: Neural Networks for Regression¶

In this project, we'll evaluate the performance and predictive power of neural networks in the sphere of regression tasks. Models will be trained and tested on data collected from homes in suburbs of Boston, Massachusetts.

Origin: This dataset was taken from the StatLib library which is maintained at Carnegie Mellon University.

Creators: Harrison, D. and Rubinfeld, D.L.

Data Set Information: Concerns housing values in suburbs of Boston.

Attribute Information:

  • CRIM: per capita crime rate by town
  • ZN: proportion of residential land zoned for lots over 25,000 sq.ft.
  • INDUS: proportion of non-retail business acres per town
  • CHAS: Charles River dummy variable (= 1 if tract bounds river; 0 otherwise)
  • NOX: nitric oxides concentration (parts per 10 million)
  • RM: average number of rooms per dwelling
  • AGE: proportion of owner-occupied units built prior to 1940
  • DIS: weighted distances to five Boston employment centres
  • RAD: index of accessibility to radial highways
  • TAX: full-value property-tax rate per 10,000 USD
  • PTRATIO: pupil-teacher ratio by town
  • B: 1000(Bk - 0.63)^2 where Bk is the proportion of blacks by town
  • LSTAT: % lower status of the population
  • MEDV: Median value of owner-occupied homes in 1000 USD

The Boston housing data was collected in 1978 and each of the 506 entries represents aggregated data about 14 features for homes from various suburbs.

Step 0. Style and Libraries¶

Let's choose a style of the Jupyter notebook and import the software libraries. The command hide_code will hide the code cells.

Using TensorFlow backend.

Step 1. Load and Explore the Data¶

This database is very popular for studying regression and can be downloaded in several ways. Let's display the easiest ones of them.

Out[5]:
CRIM ZN INDUS CHAS NOX RM AGE DIS RAD TAX PTRATIO B LSTAT MEDV
0 0.00632 18.0 2.31 0.0 0.538 6.575 65.2 4.0900 1.0 296.0 15.3 396.90 4.98 24.0
1 0.02731 0.0 7.07 0.0 0.469 6.421 78.9 4.9671 2.0 242.0 17.8 396.90 9.14 21.6
2 0.02729 0.0 7.07 0.0 0.469 7.185 61.1 4.9671 2.0 242.0 17.8 392.83 4.03 34.7
3 0.03237 0.0 2.18 0.0 0.458 6.998 45.8 6.0622 3.0 222.0 18.7 394.63 2.94 33.4
4 0.06905 0.0 2.18 0.0 0.458 7.147 54.2 6.0622 3.0 222.0 18.7 396.90 5.33 36.2
Out[16]:
MEDV
LSTAT -0.737663
RM 0.69536
PTRATIO -0.507787
INDUS -0.483725
TAX -0.468536
NOX -0.427321
CRIM -0.385832
RAD -0.381626
AGE -0.376955
ZN 0.360445
B 0.333461
DIS 0.249929
CHAS 0.17526
Training feature's shape: (404, 13)
Training target's shape (404,)
Validating feature's shape: (51, 13)
Validating target's shape (51,)
Testing feature's shape: (51, 13)
Testing target's shape (51,)

Step 2. Build the Neural Networks¶

For more information use the following links:

Multilayer Perceptron (MLP)¶

Define a model architecture and compile the model.

Run cells below to fit the model and save the best results. Choose parameters for fitting.

Epoch 00086: ReduceLROnPlateau reducing learning rate to 0.0007000000332482159.

Epoch 00118: ReduceLROnPlateau reducing learning rate to 0.0004900000232737511.

Epoch 00142: ReduceLROnPlateau reducing learning rate to 0.00034300000406801696.

Epoch 00174: ReduceLROnPlateau reducing learning rate to 0.00024009999469853935.

Epoch 00193: ReduceLROnPlateau reducing learning rate to 0.00016806999628897755.

Epoch 00225: ReduceLROnPlateau reducing learning rate to 0.00011764899536501615.

Epoch 00238: ReduceLROnPlateau reducing learning rate to 8.235429777414538e-05.

Epoch 00248: ReduceLROnPlateau reducing learning rate to 5.76480058953166e-05.

Epoch 00258: ReduceLROnPlateau reducing learning rate to 4.0353603617404586e-05.

Epoch 00268: ReduceLROnPlateau reducing learning rate to 2.8247522277524694e-05.

Epoch 00278: ReduceLROnPlateau reducing learning rate to 1.977326610358432e-05.

Display the fitting history and evaluate the model.

Train R2 score: 0.8569403511523863
Valid R2 score: 0.7271727149599336
Test R2 score: 0.6564382417374299

Convolutional Neural Network (CNN)¶

Run cells below to fit the model and save the best results. Choose parameters for fitting.

Epoch 00099: ReduceLROnPlateau reducing learning rate to 0.0007000000332482159.

Epoch 00115: ReduceLROnPlateau reducing learning rate to 0.0004900000232737511.

Epoch 00172: ReduceLROnPlateau reducing learning rate to 0.00034300000406801696.

Epoch 00182: ReduceLROnPlateau reducing learning rate to 0.00024009999469853935.

Epoch 00192: ReduceLROnPlateau reducing learning rate to 0.00016806999628897755.

Epoch 00202: ReduceLROnPlateau reducing learning rate to 0.00011764899536501615.

Epoch 00221: ReduceLROnPlateau reducing learning rate to 8.235429777414538e-05.

Epoch 00235: ReduceLROnPlateau reducing learning rate to 5.76480058953166e-05.

Epoch 00245: ReduceLROnPlateau reducing learning rate to 4.0353603617404586e-05.

Epoch 00255: ReduceLROnPlateau reducing learning rate to 2.8247522277524694e-05.

Epoch 00265: ReduceLROnPlateau reducing learning rate to 1.977326610358432e-05.

Epoch 00283: ReduceLROnPlateau reducing learning rate to 1.3841286272509023e-05.

Epoch 00293: ReduceLROnPlateau reducing learning rate to 9.688900263427058e-06.

Display the fitting history and evaluate the model.

Train R2 score: 0.7028864458163019
Valid R2 score: 0.743870712552267
Test R2 score: 0.6792672490744978

Recurrent Neural Network (RNN)¶

Define a model architecture and compile the model.

Run cells below to fit the model and save the best results. Choose parameters for fitting.

Epoch 00094: ReduceLROnPlateau reducing learning rate to 0.0007000000332482159.

Epoch 00129: ReduceLROnPlateau reducing learning rate to 0.0004900000232737511.

Epoch 00139: ReduceLROnPlateau reducing learning rate to 0.00034300000406801696.

Epoch 00149: ReduceLROnPlateau reducing learning rate to 0.00024009999469853935.

Epoch 00159: ReduceLROnPlateau reducing learning rate to 0.00016806999628897755.

Epoch 00169: ReduceLROnPlateau reducing learning rate to 0.00011764899536501615.

Epoch 00179: ReduceLROnPlateau reducing learning rate to 8.235429777414538e-05.

Epoch 00189: ReduceLROnPlateau reducing learning rate to 5.76480058953166e-05.

Epoch 00199: ReduceLROnPlateau reducing learning rate to 4.0353603617404586e-05.

Display the fitting history and evaluate the model.

Train R2 score: 0.8220617315946245
Valid R2 score: 0.7244811790821222
Test R2 score: 0.618432932958535

Step 3. Compare Predictions¶

Run the cells below to visualize the quality of predictions.