Here, we desire to model the relationship between the dependent variable and the independent variable. In the linear regression with one variable, *we only have **one** independent variable*.
* Independent variable: 'RM'
* Dependent variable: 'MEDV'
In a simple word, we want to **predict** the Median value of owner-occupied homes in $1000’s [target attribute] based on the average number of rooms per dwelling (RM).
### Plot dependecy to one variable (linear regression with one variable)
Here we want to plot the MEDV against RM, i.e, visualize how MEDV is changed by changing RM. Basically we have $MEDV=f(RM)$ and we desire to estimate the function $f(.)$ using a linear regression.
"""
# Visual representation of training data
importmatplotlib.pyplotasplt
fig,ax=plt.subplots()
...
...
@@ -108,16 +51,6 @@ ax.set_xlabel('RM')
ax.set_ylabel('MEDV')
plt.show()
"""### Split train/test data and labels for linear regression for one variable experiments
We can use two approaches to access the columns:
1. **Pop command:** It returns an item and drops it from the frame. After using trainDataset.pop('RM'), the 'RM' column does not exist in the trainDataset frame anymore!
2. Using the **indexing with labels**. Example trainDataset['RM']
We use approach **(2)**.
"""
# Pop command return item and drop it from frame.
# After using trainDataset.pop('RM'), the 'RM' column
# does not exist in the trainDataset frame anymore!
*It is not needed for simple linear regression (linear regression with one variable).*
1. **Standardization**: Standardizing the features around the center and 0 with a standard deviation of 1. Assume we have features that have different units. So just becasue of the scaling do not contribute equally to the analysis and create misleading result. Formula: $\hat{X}=\frac{X-\mu}{\sigma}$
2. **Normalization**: Normalization aims to put the values of different features to a common scale (usually [0,1] or [-1,1]). This is used when features have different ranges but the same units. **Example**: Assume we have an RGB image. *Each channel has a different range but all channels have the same units: image pixel*! Formula: $\hat{X}=\frac{X-X_{min}}{X_{max}-X_{min}}$
### Create Model
1. The architecture of the model
2. Defining the optimizer
3. Compile the model and return the graph
Assume we desire to find the parameters (**W**) that predict the
output y from x in a linear fashion:
$y = w_1 x + w_0$
The above can be defined with the following dense layer: