CTO练习营 | 12月3-5日,深圳,是时刻成为优良的技巧治理者了
在这篇文┞仿中,我们将会介绍若何应用 TF.Learn API 同时练习一个广度线性模型和一个深度前馈神经收集。这种办法结合了记忆和泛化的优势。它在一般的大年夜范围回归和具有稀少输入特点的分类问题(例如,分类特点存在一个很大年夜的可能值域)上很有效。如不雅你有兴趣进修更多关于广度和深度进修若何工作的问题,请参考 研究论文 Wide & Deep Spectrum of Models如今,我们来看一个简单的例子。
选择广度部分的特点:选摘要应用的稀少根本列和交叉列。
选择深度部分的特点:选择持续列,每个分类列的嵌入维度和隐蔽层大年夜小。
将它们一路放入广度和深度模型(DNNLinearCombinedClassifier)。
如不雅想要测验测验本教程中的代码:
1.安装 TensorFlow ,请前去此处。
2.下载 教程代码。
3.安装 pandas 数据分析库。因为本教程中须要应用 pandas 数据。固然 tf.learn 不请求 pandas,然则它支撑 pandas。安装 pandas:
a. 获取 pip:
- # Ubuntu/Linux 64-bit
- $ sudo apt-get install python-pip python-dev
- # Mac OS X
- $ sudo easy_install pip
- $ sudo easy_install --upgrade six
b. 应用 pip 安装 pandas
- $ sudo pip install pandas
4.履行以下敕令来练习教程中描述的线性模型:
- $ python wide_n_deep_tutorial.py --model_type=wide_n_deep
如不雅你在安装过程中碰到问题,请前去 pandas 网站上的 解释 。
请持续浏览,懂得此代码若何构建其线性模型。
定义根本特点列
起首,定义我们应用的基本分类和持续特点的列。这些列将被作为模型的广度部分和深度部分的构件块。
- import tensorflow as tf
- gender = tf.feature_column.categorical_column_with_vocabulary_list(
- "gender", ["Female", "Male"])
- education = tf.feature_column.categorical_column_with_vocabulary_list(
- "education", [
- "Bachelors", "HS-grad", "11th", "Masters", "9th",
- "Some-college", "Assoc-acdm", "Assoc-voc", "7th-8th",
- "Doctorate", "Prof-school", "5th-6th", "10th", "1st-4th",
- "Preschool", "12th"
- ])
- marital_status = tf.feature_column.categorical_column_with_vocabulary_list(
- "marital_status", [
- "Married-civ-spouse", "Divorced", "Married-spouse-absent"
推荐阅读
CTO练习营 | 12月3-5日,深圳,是时刻成为优良的技巧治理者了 今日头条开创人兼CEO张一鸣我们要实现本身的愿景,必须在全球范围内去解决三个问题:第一个是应用处景的问题,这本质上是一个>>>详细阅读
本文标题:TensorFlow广度和深度学习的教程
地址:http://www.17bianji.com/lsqh/39382.html
1/2 1