The values in ols_estimation
are the scalar matrix \textbf{a} such that
\begin{eqnarray}
\textbf{a} &=& \left[\begin{matrix} a_o & a_1 & ... & a_n \end{matrix}\right] \\
&=& \left[\begin{matrix} w_o & w_1 & ... & w_n \end{matrix}\right]
&=& \textbf{w}
\end{eqnarray}
The scalar matrix \textbf{a} is also a weight matrix \textbf{w}.
The definition of a Linear Regression
\begin{eqnarray}
y &=& b + mx &, Line\ slope\ equation \\
&=& a_0 + a_1x_1 + ... + a_nx_n &, Mathematical\ defintion \\
&=& b + w_1x_1 + ... + w_nx_n &, Machine\ Learning\ definition \\
&=& y\prime
& &\\
y\prime &=& b + w_1x_1 + ... + w_nx_n
\end{eqnarray}
For the Line Slope Equation, where
-
y is the value we are trying to predict
-
m is the slope of the line
-
x_1, x_2, ..., x_n is the input feature
-
b is the y-intercept
For the Machine Learning and Mathematical definition of Linear Regression, where
-
y\prime is the predicted label (a desired output)
-
w_0 or a_0 is the bias (y-intercept)
-
x_1, x_2, ..., x_n is the features (or known input)
-
w_1, w_2, ..., w_n (or a_1, a_2, ..., a_n) is the weights of n features
From the mission, given the following,
features = ['Wood Deck SF', 'Fireplaces', 'Full Bath', '1st Flr SF', 'Garage Area',
'Gr Liv Area', 'Overall Qual']
target = "SalePrice"
The Linear Regression of our model is given as
\begin{eqnarray}
y\prime &=& a_0 + a_1x_1 + a_2x_2 + a_3x_3 + a_4x_4 + a_5x_5 + a_6x_6 + a_7x_7 \\
&=& w_0 + w_1x_1 + w_2x_2 + w_3x_3 + w_4x_4 + w_5x_5 + w_6x_6 + w_7x_7 \\
\end{eqnarray}
There are 7 features. n = 7 but there are 8 (to include 1 bias - a_0 or w_0) values in matrix \textbf{a} or ols_estimation
.
\begin{eqnarray}
\textbf{a} &=& \left[\begin{matrix} a_0 & a_1 & a_2 & a_3 & a_4 & a_5 & a_6 & a_7 \end{matrix}\right] \\
&=& \left[\begin{matrix} w_0 & w_1 & w_2 & w_3 & w_4 & w_5 & w_6 & w_7 \end{matrix}\right]
&=& \textbf{w}
\end{eqnarray}
From the values of ols_estimation
,
ols_estimation ndarray (<class 'numpy.ndarray'>)
array([-1.12764871e+05, 3.78815268e+01, 7.08698430e+03, -2.22197281e+03,
4.31853639e+01, 6.48808564e+01, 3.87112549e+01, 2.45531837e+04])
The weight of each feature is given as
\begin{eqnarray}
w_0 &=& -1.12764871e+05 &,& Bias \\
w_1 &=& 3.78815268e+01 &,& feature &=& Wood\ Deck\ SF \\
w_2 &=& 7.08698430e+03 &,& feature &=& Fireplaces\\
w_3 &=& -2.22197281e+03 &,& feature &=& Full\ Bath\\
w_4 &=& 4.31853639e+01 &,& feature &=& 1st\ Flr\ SF\\
w_5 &=& 6.48808564e+01 &,& feature &=& Garage\ Area\\
w_6 &=& 3.87112549e+01 &,& feature &=& Gr\ Liv\ Area\\
w_7 &=& 2.45531837e+04 &,& feature &=& Overall\ Qual \\
\end{eqnarray}
Ordinary Least Square Estimator goal is to minimizing the square differences between the observed observed dependent variable (values of the variable being observed) in the given dataset and those predicted by the linear function of the independent variable.
As a result of minimizing the error, Ordinary Least Square Estimator gives the optimal Linear Regression weights for n features. In other words, in mission example, matrix \textbf{a} or ols_estimation
gives us the optimal weights for 7 features.