Reputation: 2302
I am reading data from a file using pandas
which looks like this:
data.head()
ldr1 ldr2 servo
0 971 956 -2
1 691 825 -105
2 841 963 -26
3 970 731 44
4 755 939 -69
I proceed to normalize this data to perform gradient descent:
my_data = (my_data - my_data.mean())/my_data.std()
my_data.head()
ldr1 ldr2 servo
0 1.419949 1.289668 0.366482
1 -0.242834 0.591311 -1.580420
2 0.647943 1.326984 -0.087165
3 1.414011 0.090200 1.235972
4 0.137231 1.199041 -0.899949
I perform multivariate regression and end up with fitted parameters on the normalized data:
Thetas: [[ 0.31973117 0.45401309 -0.12941108]]
I would like to plot the plane of best fit on the original data and not the normalized data using the normalized thetas.
I used scipy.optimize.curve_fit
to perform multivariate linear regression and come up with the optimal fitted parameters. I know that the original thetas should be close to the following:
[ 0.26654135 -0.15218007 -107.79915373]
How can I get the 'original' thetas for the original data-set in order to plot, without using Scikit-Learn?
Any suggestions will be appreciated.
As per the answer below:
m
ldr1 731.891429
ldr2 714.080000
servo -21.388571
dtype: float64
s
ldr1 168.392347
ldr2 187.583221
servo 52.904576
dtype: float64
I then proceed with:
original_thetas = np.dot(theta, s) + m
which yields:
original_thetas
ldr1 862.420572
ldr2 844.609144
servo 109.140572
dtype: float64
I am not sure if I am performing the calculation incorrectly or if the method presented does not work for the coefficients themselves.
Upvotes: 4
Views: 1435
Reputation: 3632
I believe you just need to store the mean and standard deviations
m = data.mean()
s = data.std()
And then inverse the transformation
theta * s + m
Upvotes: 6