簡介

演算法導論和機器學習的異同
相同點:都是輸入,計算,得到結果。
差異:
演算法導論:
以f(x)=wx為例,其實就是人為的設定w的過程。但x是離散變數不是連續變數,不然就是高中數學題了。


神經網路

一般超過8層的神經網路模型就叫深度學習。
深度學習解決了淺層神經網路多層傳遞之後梯度消失和區域性最優解的問題。
主要的兩類深度學習
監督學習:
迴歸和分類,迴歸問題通常是用來預測一個值,如預測房價、未來的天氣情況等等。分類問題是用於將事物打上一個標籤,通常結果為離散值。例如判斷一幅圖片上的動物是一隻貓還是一隻狗。

無監督學習:
無監督學習裡典型的例子就是聚類了。聚類的目的在於把相似的東西聚在一起,而我們並不關心這一類是什麼。

神經網路基礎

輸入:整個訓練集表示為:





計算過程:比如第二層

啟用函式:比如啟用函式為sigmoid時,第二層

反向傳播:梯度下降法更新權重w。其中α為步長。
損失函式(Loss Function):是定義在單個樣本上的,算的是一個樣本的誤差。以均方誤差損失函式為例:

代價函式(Cost Function):是定義在整個訓練集上的,是所有樣本誤差的平均,也就是損失函式的平均。



附,矩陣操作
所有的計算過程如果都是這種形式,計算就會顯得很複雜。

所以神經網路中廣泛的使用了矩陣操作。


Tensorflow
安裝
python環境Anaconda整合安裝
ide Pycharm等
配置清華源
conda config --add channels mirrors.tuna.tsinghua.edu.cn/anaconda/pk…
conda config --set show_channel_urls yes
建立一個python環境
conda create -n tensorflow python=版本號
activate tensorflow(退出deactivate tensorflow)
pip清華源安裝tensorflow
pip install -i pypi.tuna.tsinghua.edu.cn/simple tensorflow
或者全域性設定pip源。C:\Users\使用者名稱\pip\pip.ini,預設情況下pip資料夾和pip.ini都未建立,自行建立,pip中新增以下內容。
[global]
index-url = pypi.tuna.tsinghua.edu.cn/simple
使用pip install tensorflow
案例
tensorflow mnist
from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf
# MNIST資料存放的路徑
file = "./MNIST"
# 匯入資料
mnist = input_data.read_data_sets(file, one_hot=True)
# 模型的輸入和輸出
x = tf.placeholder(tf.float32, shape=[None, 784])
y_ = tf.placeholder(tf.float32, shape=[None, 10])
# 模型的權重和偏移量
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
# 建立Session
sess = tf.InteractiveSession()
# 初始化權重變數
sess.run(tf.global_variables_initializer())
# SoftMax啟用函式
y = tf.nn.softmax(tf.matmul(x, W) + b)
# 交叉熵損失函式
cross_entropy = -tf.reduce_sum(y_*tf.log(y))
# 梯度下降法訓練
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)
for i in range(1000):
batch = mnist.train.next_batch(50)
train_step.run(feed_dict={x: batch[0], y_: batch[1]})
# 測試
correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_:mnist.test.labels}))
複製程式碼
參考連結: 吳恩達給你的人工智慧第一課
mooc.study.163.com/smartSpec/d…
機器學習的演算法和普通《演算法導論》裡的演算法有什麼本質上的異同?
人工智慧、機器學習和深度學習的區別?
如何簡單形象又有趣地講解神經網路是什麼?
深入淺出--梯度下降法及其實現
深入梯度下降(Gradient Descent)演算法
梯度下降(Gradient Descent)小結(寫了梯度下降和梯度上升)
一文弄懂神經網路中的反向傳播法——BackPropagation
基於字元的卷積神經網路實現文字分類(char-level CNN)-論文詳解及tensorflow實現
資料探勘系列(10)——卷積神經網路演算法的一個實現