# <!-- TITLE --> [BHPD1] - Regression with a Dense Network (DNN)
# <!-- TITLE --> [BHPD1] - Regression with a Dense Network (DNN)
<!-- DESC --> Simple example of a regression with the dataset Boston Housing Prices Dataset (BHPD)
<!-- DESC --> Simple example of a regression with the dataset Boston Housing Prices Dataset (BHPD)
<!-- AUTHOR : Jean-Luc Parouty (CNRS/SIMaP) -->
<!-- AUTHOR : Jean-Luc Parouty (CNRS/SIMaP) -->
## Objectives :
## Objectives :
- Predicts **housing prices** from a set of house features.
- Predicts **housing prices** from a set of house features.
- Understanding the **principle** and the **architecture** of a regression with a **dense neural network**
- Understanding the **principle** and the **architecture** of a regression with a **dense neural network**
The **[Boston Housing Prices Dataset](https://www.cs.toronto.edu/~delve/data/boston/bostonDetail.html)** consists of price of houses in various places in Boston.
The **[Boston Housing Prices Dataset](https://www.cs.toronto.edu/~delve/data/boston/bostonDetail.html)** consists of price of houses in various places in Boston.
Alongside with price, the dataset also provide theses informations :
Alongside with price, the dataset also provide theses informations :
- CRIM: This is the per capita crime rate by town
- CRIM: This is the per capita crime rate by town
- ZN: This is the proportion of residential land zoned for lots larger than 25,000 sq.ft
- ZN: This is the proportion of residential land zoned for lots larger than 25,000 sq.ft
- INDUS: This is the proportion of non-retail business acres per town
- INDUS: This is the proportion of non-retail business acres per town
- CHAS: This is the Charles River dummy variable (this is equal to 1 if tract bounds river; 0 otherwise)
- CHAS: This is the Charles River dummy variable (this is equal to 1 if tract bounds river; 0 otherwise)
- NOX: This is the nitric oxides concentration (parts per 10 million)
- NOX: This is the nitric oxides concentration (parts per 10 million)
- RM: This is the average number of rooms per dwelling
- RM: This is the average number of rooms per dwelling
- AGE: This is the proportion of owner-occupied units built prior to 1940
- AGE: This is the proportion of owner-occupied units built prior to 1940
- DIS: This is the weighted distances to five Boston employment centers
- DIS: This is the weighted distances to five Boston employment centers
- RAD: This is the index of accessibility to radial highways
- RAD: This is the index of accessibility to radial highways
- TAX: This is the full-value property-tax rate per 10,000 dollars
- TAX: This is the full-value property-tax rate per 10,000 dollars
- PTRATIO: This is the pupil-teacher ratio by town
- PTRATIO: This is the pupil-teacher ratio by town
- B: This is calculated as 1000(Bk — 0.63)^2, where Bk is the proportion of people of African American descent by town
- B: This is calculated as 1000(Bk — 0.63)^2, where Bk is the proportion of people of African American descent by town
- LSTAT: This is the percentage lower status of the population
- LSTAT: This is the percentage lower status of the population
- MEDV: This is the median value of owner-occupied homes in 1000 dollars
- MEDV: This is the median value of owner-occupied homes in 1000 dollars
## What we're going to do :
## What we're going to do :
- Retrieve data
- Retrieve data
- Preparing the data
- Preparing the data
- Build a model
- Build a model
- Train the model
- Train the model
- Evaluate the result
- Evaluate the result
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Step 1 - Import and init
## Step 1 - Import and init
You can also adjust the verbosity by changing the value of TF_CPP_MIN_LOG_LEVEL :
You can also adjust the verbosity by changing the value of TF_CPP_MIN_LOG_LEVEL :
- 0 = all messages are logged (default)
- 0 = all messages are logged (default)
- 1 = INFO messages are not printed.
- 1 = INFO messages are not printed.
- 2 = INFO and WARNING messages are not printed.
- 2 = INFO and WARNING messages are not printed.
- 3 = INFO , WARNING and ERROR messages are not printed.
- 3 = INFO , WARNING and ERROR messages are not printed.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
# import os
# import os
# os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
# os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
importtensorflowastf
importtensorflowastf
fromtensorflowimportkeras
fromtensorflowimportkeras
importnumpyasnp
importnumpyasnp
importmatplotlib.pyplotasplt
importmatplotlib.pyplotasplt
importpandasaspd
importpandasaspd
importos,sys
importos,sys
sys.path.append('..')
sys.path.append('..')
importfidle.pwkaspwk
importfidle.pwkaspwk
datasets_dir=pwk.init('BHPD1')
datasets_dir=pwk.init('BHPD1')
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Verbosity during training :
Verbosity during training :
- 0 = silent
- 0 = silent
- 1 = progress bar
- 1 = progress bar
- 2 = one line per epoch
- 2 = one line per epoch
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
fit_verbosity=1
fit_verbosity=1
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Override parameters (batch mode) - Just forget this cell
Override parameters (batch mode) - Just forget this cell
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
pwk.override('fit_verbosity')
pwk.override('fit_verbosity')
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Step 2 - Retrieve data
## Step 2 - Retrieve data
### 2.1 - Option 1 : From Keras
### 2.1 - Option 1 : From Keras
Boston housing is a famous historic dataset, so we can get it directly from [Keras datasets](https://www.tensorflow.org/api_docs/python/tf/keras/datasets)
Boston housing is a famous historic dataset, so we can get it directly from [Keras datasets](https://www.tensorflow.org/api_docs/python/tf/keras/datasets)