在使用梯度下降的线性回归后对 thetas 进行非归一化

Denormalizing thetas after a linear regression with gradient descent

我有以下一组数据:

km,price
240000,3650
139800,3800
150500,4400
185530,4450
176000,5250
114800,5350
166800,5800
89000,5990
144500,5999
84000,6200
82029,6390
63060,6390
74000,6600
97500,6800
67000,6800
76025,6900
48235,6900
93000,6990
60949,7490
65674,7555
54000,7990
68500,7990
22899,7990
61789,8290

对它们进行归一化后,我正在执行梯度下降,得到以下 thetas:

θ0 = 0.9362124793084768
θ1 = -0.9953762249792935

如果我输入归一化的里程数,然后将预测的价格去归一化,我就可以正确预测价格,即:

Asked price for a mileage of 50000km:
normalized mileage: 0.12483129971764294
normalized price: (mx + c) = 0.8119583714362707
real price: 7417.486843464296

我正在寻找的是将我的 thetas 恢复到它们的非标准化值,但我一直无法做到,无论我尝试了哪个方程式。有办法吗?

像往常一样,我在 Whosebug 上问了一个问题,过了一会儿才设法自己解决了....

这只是一个需要求解的二元方程,正如您在此处看到的(请原谅笔迹):https://ibb.co/178qWcQ.

这是执行计算的 python 代码:

x0, x1 = self.training_set[0][0], self.training_set[1][0]
x0n, x1n = self.normalized_training_set[0][0], self.normalized_training_set[1][0]
y0n, y1n = self.hypothesis(x0n), self.hypothesis(x1n)
p_diff = self.max_price - self.min_price
theta0 = (x1 / (x1 - x0)) * (y0n * p_diff + self.min_price - (x0 / x1 * (y1n * p_diff + self.min_price)))
y0 = self.training_set[0][1]
theta1 = (y0 - theta0) / x0
print(theta0, theta1) //RESULT: 8481.172796984529 -0.020129886654102203