How to feed data into a polynomial basis function regression (unregularized) for degree n?

370 Views Asked by At

We know that polynomial base function Models is:

$$t = \sum_{i=0}^n w^T\phi_j(x) = w_0*\phi_0(x) + w_1*\phi_1(x) + w_2*\phi_2(x)+ ....$$ $$\phi_j(x) = x^j$$

Problem: I am not sure how to pass the data to the model. For example, degree 2 polynomial base function regression is: $$t = w_0 + w_1*x + w_2 * x^2 $$

Now I want to feed a table of data into Degree 2 model:

Employee    Target_income    factor_1  factor_2  factor_3  factor_4
A                 100           10        12        9          8
B                 150           19        17        15         10
C                 200           25        15        16         12

To find optimal $w^T$, we find the minimum of square error: $$E(w) = \frac{1}{2} \sum_{i=0}^n \{ t_i - w^T\phi(x_i) \}^2$$ Okay, I know that $t_i =[100, 150,200]^T$. What is $w^T\phi(x_i)$ for each employee i here?

To be more precise, when i=1 how can I put the data into this model: $$t_1 - w^T\phi(x_1) = $$ $$t_1 - (w_0 + w_1*x_1 + w_2 * x_1^2)$$ Employee A salary is defined by 4 factors (data points), but we only have 1 x.

2

There are 2 best solutions below

3
On BEST ANSWER

After the discussion in comments, what it seems is that you want tht, for each employee $i$, his/her salary $t_i$ be represented as $$t_i=a+(b_1 f_{1i}+b_2f_{1i}^2)+(c_1 f_{2i}+c_2f_{2i}^2)+(d_1 f_{3i}+d_2f_{3i}^2)+(e_1 f_{4i}+e_2f_{4i}^2)$$ which makes a linear regression for eight variables $(f_{ki},f_{ki}^2)$ for $k=1,2,3,4$ and $i=1,2,\cdots,n$

So,nine parameters. Now, use matrix calculations to get the answer.

2
On

Attached a MATHEMATICA script showing a possible formulation

data = {{ 100, 10, 12, 9, 8}, {150, 19, 17, 15, 10}, {200, 25, 15, 16, 12}}; n = 3; m = 4; W = {w1, w2, w3}; phi[k_, x_] := x^(k - 1) Phi[x_] := {phi[1, x], phi[2, x], phi[3, x]} EE[j_] := Sum[(data[[k, j + 1]] - W.Phi[data[[k, 1]]])^2, {k, n}] EE0 = Sum[EE[j], {j, m}]

and the generated output

$$ {\small{ \text{EE0}=\left(12-w_1-200 w_2-200{}^{\wedge}2 w_3\right){}^2+\left(15-w_1-200 w_2-200{}^{\wedge}2 w_3\right){}^2+\left(16-w_1-200 w_2-200{}^{\wedge}2w_3\right){}^2+\left(25-w_1-200 w_2-200{}^{\wedge}2 w_3\right){}^2+\\ \left(10-w_1-150 w_2-150{}^{\wedge}2 w_3\right){}^2+\left(15-w_1-150 w_2-150{}^{\wedge}2 w_3\right){}^2+\left(17-w_1-150 w_2-150{}^{\wedge}2 w_3\right){}^2+\left(19-w_1-150 w_2-150{}^{\wedge}2 w_3\right){}^2+\\ \left(8-w_1-100 w_2-100{}^{\wedge}2 w_3\right){}^2+\left(9-w_1-100 w_2-100{}^{\wedge}2 w_3\right){}^2+\left(10-w_1-100 w_2-100{}^{\wedge}2 w_3\right){}^2+\left(12-w_1-100 w_2-100{}^{\wedge}2 w_3\right){}^2}} $$

follows the minimization-resolution process

der = Grad[EE0, W]; equs = Thread[der == 0]; sol = Solve[equs, W]

giving

{{w1 -> -(25/2), w2 -> 119/400, w3 -> -(3/4000)}}

Follows the obtained adjust.

$$ $$

enter image description here

I hope this helps.