内容简介:1. What is Neural Network在課程開始,講者(Laurence Moroney)以x和y的關係來解釋 Neural network假設 y = 2x-1 , 則傳統程式如下方顯示
Week 1:
課程連結1. What is Neural Network
在課程開始,講者(Laurence Moroney)以x和y的關係來解釋 Neural network
假設 y = 2x-1 , 則傳統程式如下方顯示
float hw_function(float x) { float y = (2 * x) - 1; return y; }
那機器學習的程式將會如何表示?
2. Machine Learning 訓練過程
Imports
import tensorflow as tf import numpy as np from tensorflow import keras
Define and Compile the Neural Network
建立一個簡單的神經網路
其內容只有一層, 一個神經元, 輸入為1維
model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
接下來,要怎麼讓電腦知道 y & x的關係是y=2x-1 ?
當電腦要進行猜測時,它可能一開始會猜y=10x+10..
因此,我們會先定義兩個函式
The LOSS function : 從data來測量答案與正確答案的差距(趨近越小越好)
The OPTIMIZER function : 根據how the loss function went,來做下一次的猜測,並盡量減少loss. 例如可能猜測 y=5x+5… , 再慢慢猜測降低loss,並重複EPOCHS 的number次數
在這裡,我們使用
Loss = ‘MEAN SQUARED ERROR’
Optimizer = ‘STOCHASTIC GRADIENT DESCENT’
Over time you will learn the different and appropriate loss and optimizer functions for different scenarios.
model.compile(optimizer='sgd', loss='mean_squared_error')
Providing the Data
xs = np.array([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0], dtype=float) ys = np.array([-3.0, -1.0, 1.0, 3.0, 5.0, 7.0], dtype=float)
Training the Neural Network
在訓練神經元網路的過程,電腦會從呼叫model.fit來學習 Xs & Ys的關係
這就是上面內容所講述的過程:
1. 猜測
2. 測量猜測的好壞
3. 透過optimizer來進行下一次猜測
model.fit(xs, ys, epochs=500)
在透過 model.fit 訓練完模型之後,我們可以輸入 X 到模型裡得到相對應的 Y
若X=10, Y會是多少?
print(model.predict([10.0]))
你可能會以為答案是19 但事實上會得到一個~19但接近的數字
因為神經網路是算答案的機率性
我們只能透過data得到模型是接近Y=2X-1 但無法確定100%一定是
因此在神經網路的世界裡一直都是得到機率性而非確定性
最後再透過程式和機率來做分群或是分類的行為
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Sovereign Individual
James Dale Davidson、William Rees-Mogg / Free Press / 1999-08-26 / USD 16.00
Two renowned investment advisors and authors of the bestseller The Great Reckoning bring to light both currents of disaster and the potential for prosperity and renewal in the face of radical changes ......一起来看看 《The Sovereign Individual》 这本书的介绍吧!