Keras 笔记

To take notes about the essential Keras elements to build basic neural networks. The explainations of each section haven’t finished yet.

1. Single Layer Neural Network (Linear Regression)

单层神经网络相当于(非)线性回归模型,第一个例子是构建一个最简单一元线性回归模型。

  1. 创建数据
    单层神经网络模型需要数据进行训练,因此我们使用 numpy 创建一些人造数据,且我们的 $y$ 为 $y = ax+b$ 。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    import numpy as np
    import tensorflow as tf
    from tensorflow.keras import layers
    import matplotlib.pyplot as plt
    plt.style.use('seaborn')

    # create data
    X = np.linspace(-1, 1, 200)
    np.random.shuffle(X) #randomize the data
    Y = 2*X + 10 + np.random.normal(0, 0.05, (200,))

    # plot data
    plt.scatter(X, Y)
    plt.show()

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×