Tensorflow 2.0 教程持续更新 :https://blog.csdn.net/qq_31456593/article/details/88606284
完整tensorflow2.0教程代码请看tensorflow2.0:中文教程tensorflow2_tutorials_chinese(欢迎star)
入门教程:
TensorFlow 2.0 教程- Keras 快速入门
TensorFlow 2.0 教程-keras 函数api
TensorFlow 2.0 教程-使用keras训练模型
TensorFlow 2.0 教程-用keras构建自己的网络层
[TensorFlow 2.0 教程-keras模型保存和序列化](
TensorFlow 2.0 教程-用Estimator构造Boosted trees
本教程是使用决策树和tf.estimator API训练Gradient Boosting模型的端到端演练。 Boosted Trees模型是回归和分类中最受欢迎和最有效的机器学习方法之一。 这是一种集合技术,它结合了几种树模型的预测。
Boosted Trees模型受到许多机器学习从业者的欢迎,因为它们可以通过最小的超参数调整实现令人印象深刻的性能。
1.加载泰坦尼克数据集
from __future__ import absolute_import, division, print_function
import numpy as np
import pandas as pd
from IPython.display import clear_output
# Load dataset.
dftrain = pd.read_csv('https://storage.googleapis.com/tf-datasets/titanic/train.csv')
dfeval = pd.read_csv('https://storage.googleapis.com/tf-datasets/titanic/eval.csv')
y_train = dftrain.pop('survived')
y_eval = dfeval.pop('survived')
import tensorflow as tf
tf.random.set_seed(123)
数据集由训练集和评估集组成:
dftrain
和y_train
是training set - 模型用来学习的数据。- 模型根据eval set,
dfeval
和y_eval
进行测试。
数据集设定的特征如下:
Feature Name | Description |
---|---|
sex | Gender of passenger |
age | Age of passenger |
n_siblings_spouses | # siblings and partners aboard |
parch | # of parents and children aboard |
fare | Fare passenger paid. |
class | Passenger's class on ship |
deck | Which deck passenger was on |
embark_town | Which town passenger embarked from |
alone | If passenger was alone |
2.探索数据
dftrain.head()
sex | age | n_siblings_spouses | parch | fare | class | deck | embark_town | alone | |
---|---|---|---|---|---|---|---|---|---|
0 | male | 22.0 | 1 | 0 | 7.2500 | Third | unknown | Southampton | n |
1 | female | 38.0 | 1 | 0 | 71.2833 | First | C | Cherbourg | n |
2 | female | 26.0 | 0 | 0 | 7.9250 | Third | unknown | Southampton | y |
3 | female | 35.0 | 1 | 0 | 53.1000 | First | C | Southampton | n |
4 | male | 28.0 | 0 | 0 | 8.4583 | Third | unknown | Queenstown | y |
dftrain.describe()
age | n_siblings_spouses | parch | fare | |
---|---|---|---|---|
count | 627.000000 | 627.000000 | 627.000000 | 627.000000 |
mean | 29.631308 | 0.545455 | 0.379585 | 34.385399 |
std | 12.511818 | 1.151090 | 0.792999 | 54.597730 |
min | 0.750000 | 0.000000 | 0.000000 | 0.000000 |
25% | 23.000000 | 0.000000 | 0.000000 | 7.895800 |
50% | 28.000000 | 0.000000 | 0.000000 | 15.045800 |
75% | 35.000000 | 1.000000 | 0.000000 | 31.387500 |
max | 80.000000 | 8.000000 | 5.000000 | 512.329200 |
dftrain.shape[