[英] TensorFlow Overview

Key concept of Machine Learning and TensorFlow

TensorFlow

www.tensorflow.org
is an open source machine learning framework. Support language Python, C++, JavaScript, Java, Go, Swift.

Keras

is a high-level API to build and train models in TensorFlow

Colaboratory

colab.research.google.com/notebooks/w…
is a Google research project created to help disseminate machine learning education and research. It's a Jupyter notebook environment that requires no setup to use and runs entirely in the cloud.

Feature and lable

Briefly, feature is input; label is output. A feature is one column of the data in your input set. For instance, if you're trying to predict the type of pet someone will choose, your input features might include age, home region, family income, etc. The label is the final choice, such as dog, fish, iguana, rock, etc.
Once you've trained your model, you will give it sets of new input containing those features; it will return the predicted "label" (pet type) for that person. The features of the data, such as a house's size, age, etc.

Classification

Classify things such as classify images of clothing.

Regression

Predict the output of a continuous value according to the input, such as pridict house price according to the features of the house.

Key params for Karas to create a model

  • Layer
  • Loss function —This measures how accurate the model is during training.
  • Optimizer —This is how the model is updated based on the data it sees and its loss - - function.
  • Metrics —Used to monitor the training and testing steps.

Machine Learning Steps

  1. Import dataset.
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
复制代码
  1. Build model(choose layers, loss function, optimizer, metrics).
model = keras.Sequential([
    keras.layers.Flatten(input_shape=(28, 28)),
    keras.layers.Dense(128, activation=tf.nn.relu),
    keras.layers.Dense(10, activation=tf.nn.softmax)
])
model.compile(optimizer=tf.train.AdamOptimizer(), 
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])
复制代码
  1. Train the model with train dataset, evaluate the trained model with the validate dataset.If not good enough, return to step2.
model.fit(train_images, train_labels, epochs=5)
test_loss, test_acc = model.evaluate(test_images, test_labels)
复制代码
  1. Use the trained model to classify or predict new input data.
predictions = model.predict(test_images)
复制代码

Overfitting and underfitting

A better understanding of Neural Network

playground.tensorflow.org/

TensorFlow demos

Classification: clissify clothing

import package

# TensorFlow and tf.keras
import tensorflow as tf
from tensorflow import keras

# Helper libraries
import numpy as np
import matplotlib.pyplot as plt
复制代码

import dateset

fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
复制代码

create model

model = keras.Sequential([
    keras.layers.Flatten(input_shape=(28, 28)),
    keras.layers.Dense(128, activation=tf.nn.relu),
    keras.layers.Dense(10, activation=tf.nn.softmax)
])
model.compile(optimizer=tf.train.AdamOptimizer(), 
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])
复制代码

train model

model.fit(train_images, train_labels, epochs=5)
复制代码

evaluate accuracy

test_loss, test_acc = model.evaluate(test_images, test_labels)
复制代码

make predict

predictions = model.predict(test_images)
复制代码

Regression: Predict house price

...
create model

model = keras.Sequential([
keras.layers.Dense(64, activation=tf.nn.relu,
                   input_shape=(train_data.shape[1],)),
keras.layers.Dense(64, activation=tf.nn.relu),
keras.layers.Dense(1)
])
optimizer = tf.train.RMSPropOptimizer(0.001)
model.compile(loss='mse',
            optimizer=optimizer,
            metrics=['mae'])
复制代码

train model

history = model.fit(train_data, train_labels, epochs=EPOCHS,
                    validation_split=0.2, verbose=0,
                    callbacks=[PrintDot()])
复制代码
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值