使用TensorFlow训练神经网络进行价格预测

Using Deep Neural Networks for regression problems might seem like overkill (and quite often is), but for some cases where you have a significant amount of high dimensional data they can outperform any other ML models.

使用深度神经网络解决回归问题似乎过大(并且经常是),但是在某些情况下,如果您拥有大量的高维数据,它们可能会胜过其他任何ML模型。

When you learn about Neural Networks you usually start with some image classification problem like the MNIST dataset — this is an obvious choice as advanced tasks with high dimensional data is where DNNs really thrive.

当您了解神经网络时,通常会遇到一些图像分类问题,例如MNIST数据集-这是一个显而易见的选择,因为具有高维数据的高级任务是DNN真正蓬勃发展的地方。

Surprisingly, when you try to apply what you learned on MNIST on a regression tasks you might struggle for a while before your super-advanced DNN model is any better than a basic Random Forest Regressor. Sometimes you might never reach that moment…

令人惊讶的是,当您尝试将在MNIST上学到的知识应用到回归任务上时,您可能需要花一阵子才能使超高级DNN模型比基本的Random Forest Regressor更好。 有时您可能永远都无法到达那一刻……

In this guide, I listed some key tips and tricks learned while using DNN for regression problems. The data is a set of nearly 50 features describing 25k properties in Warsaw. I described the feature selection process in my previous article: feature-selection-and-error-analysis-while-working-with-spatial-data so now we will focus on creating the best possible model predicting property price per m2 using the selected features.

在本指南中,我列出了使用DNN解决回归问题时学到的一些关键技巧。 该数据是一组近50个要素的集合,描述了华沙的25k属性。 我在上一篇文章中介绍了特征选择过程:在处理空间数据时进行特征选择和错误分析,因此现在我们将着重于使用选定的特征创建最佳的模型来预测每平方米的房地产价格。

The code and data source used for this article can be found on GitHub.

本文使用的代码和数据源可在 GitHub 找到

1.入门 (1. Getting started)

When training a Deep Neural Network I usually follow these key steps:

在训练深度神经网络时,我通常遵循以下关键步骤:

  • A) Choose a default architecture — no. of layers, no. of neurons, activation

    A)选择默认架构-不。 层数 的神经元,激活

  • B) Regularize model

    B)正则化模型

  • C) Adjust network architecture

    C)调整网络架构

  • D) Adjust the learning rate and no. of epochs

    D)调整学习率和否。 时代

  • E) Extract optimal model using CallBacks

    E)使用回调提取最佳模型

Usually creating the final model takes a few runs through all of these steps but an important thing to remember is: DO ONE THING AT A TIME. Don’t try to change architecture, regularization, and learning rate at the same time as you will not know what really worked and probably spend hours going in circles.

通常,创建最终模型需要完成所有这些步骤,但是要记住的重要一件事是: 一次做一件事。 不要试图同时更改体系结构,正则化和学习率,因为您将不知道真正有效的方法,并且可能会花费数小时来讨论。

Before you start building any DNNs for regression tasks there are 3 key things you must remember:

在开始为回归任务构建任何DNN之前,您必须记住3个关键事项:

  • Standarize your data to make training more efficient

    标准化您的数据以提高培训效率

  • Use RELU activation function for all hidden layers — you will be going nowhere with default sigmoid activation

    对所有隐藏层使用RELU激活功能-默认Sigmoid激活将无处可走

  • Use Linear activation function for the single-neuron output layer

    对单神经元输出层使用线性激活函数

Another important task is selecting the loss function. Mean Squared Error or Mean Absolute Error are the two most common choices. As my goal to minimize the average percentage error and maximize the share of all buildings within 5% error I choose MAE, as it penalizes outliers less and is easier to interpret — it pretty much tells you how many $$/m2 on average each offer is off the actual value.

另一个重要任务是选择损失函数。 均方误差均绝对误差是两个最常见的选择。 我的目标是最大程度地减少平均百分比误差并在5%误差内最大化所有建筑物的份额,因此我选择MAE,因为它减少了异常值,并且更易于解释-它几乎可以告诉您每个报价平均要多少美元/平方米偏离实际值。

There is also a function directly linked to my goal — Mean Absolute Percentage Error, but after testing it against MAE I found the training to be less efficient.

还有一个与我的目标直接相关的功能- 平均绝对百分比误差 ,但是在针对MAE进行测试后,我发现训练的效率较低。

2.基本的DNN模型 (2. Base DNN model)

We start with a basic network with 5 hidden layers and a decreasing number of neurons in every second layer.

我们从一个具有5个隐藏层的基本网络开始,并且每隔第二层神经元的数量就会减少。

tf.keras.backend.clear_session()
tf.random.set_seed(60)model=keras.models.Sequential([

keras.layers.Dense(512, input_dim = X_train.shape[1], activation='relu'),
keras.layers.Dense(512, input_dim = X_train.shape[1], activation='relu'),
keras.layers.Dense(units=256,activation='relu'),
keras.layers.Dense(units=256,activation='relu'),
keras.layers.Dense(units=128,activation='relu'),
keras.layers.Dense(units=1, activation="linear"),],name
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值