在Keras中训练多元回归模型时的损耗值非常大 [英] Very large loss values when training multiple regression model in Keras

查看:1031
本文介绍了在Keras中训练多元回归模型时的损耗值非常大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下功能构建多元回归模型来预测房价:

I was trying to build a multiple regression model to predict housing prices using the following features:

  [bedrooms  bathrooms  sqft_living  view  grade]
= [0.09375   0.266667     0.149582   0.0    0.6]

我已经使用sklearn.preprocessing.MinMaxScaler对功能进行了标准化和缩放.

I have standardized and scaled the features using sklearn.preprocessing.MinMaxScaler.

我用Keras建立了模型:

I used Keras to build the model:

def build_model(X_train):
    model = Sequential()
    model.add(Dense(5, activation = 'relu', input_shape = X_train.shape[1:]))
        model.add(Dense(1))

    optimizer = Adam(lr = 0.001)

    model.compile(loss = 'mean_squared_error', optimizer = optimizer)

    return model

当我去训练模型时,我的损失值非常高,大约是4或40万亿美元,并且每次下降只会减少大约一百万,这使得训练变得太慢了.最初,我尝试提高学习率,但是并没有太大帮助.然后,我进行了一些搜索,发现其他人使用了log-MSE损失函数,因此我尝试了一下,并且我的模型似乎运行良好. (从140损失开始,到400个时期后下降到0.2)

When I go to train the model, my loss values are insanely high, something like 4 or 40 trillion and it will only go down about a million per epoch making training infeasibly slow. At first I tried increasing the learning rate, but it didn't help much. Then I did some searching and found that others have used a log-MSE loss function so I tried it and my model seemed to work fine. (Started at 140 loss, went down to 0.2 after 400 epochs)

我的问题是,当看到线性/多重回归问题的MSE值非常大时,我是否总是只使用log-MSE?还是我可以采取其他措施来解决此问题?

关于此问题发生原因的一个猜测是,我的预测变量和响应变量之间的比例差异很大. X介于0-1之间,而最高的Y则高达800万. (我想缩小我的Y吗?然后再放大以进行预测?)

A guess as to why this issue occurred is the scale between my predictor and response variables were vastly different. X's are between 0-1 while the highest Y went up to 8 million. (Am I suppose to scale down my Y's? And then scale back up for predicting?)

推荐答案

很多人都相信扩展一切.如果您的y达到800万,我会按比例缩放它,是的,然后等到您得到预测后再逆向缩放.

A lot of people believe in scaling everything. If your y goes up to 8 million, I'd scale it, yes, and reverse the scaling when you get predictions out, later.

不必太担心您看到的loss数字.当然,40万亿美元有点荒谬,表明可能需要对网络体系结构或参数进行更改.主要关注的是验证损失是否实际上正在减少,以及网络是否正在实际学习中.如您所说,如果经过400个纪元后降为0.2",那么听起来您就在正确的轨道上.

Don't worry too much about specifically what loss number you see. Sure, 40 trillion is a bit ridiculously high, indicating changes may need to be made to the network architecture or parameters. The main concern is whether the validation loss is actually decreasing, and the network actually learning therewith. If, as you say, it 'went down to 0.2 after 400 epochs', then it sounds like you're on the right track.

除了log-mse,mse和mae,还有许多其他损失函数可用于回归问题.看看这些.希望有帮助!

There are many other loss functions besides log-mse, mse, and mae, for regression problems. Have a look at these. Hope that helps!

这篇关于在Keras中训练多元回归模型时的损耗值非常大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆