Kaggle Digit Recognizer

這是進入 Kaggle 的第一個試題:Kaggle digit recognizer。 這是一個用 CSV 儲存的 MNIST 問題,因此選用 CNN 來解決。資料格式如下: If we omit the “pixel” prefix, the pixels make up the image like this: 000 001 002 003 ... 026 027 028 029 030 031 ... 054 055 056 057 058 059 ... 082 083 | | | | ... | | 728 729 730 731 ... 754 755 756 757 758 759 ... 782 783 The test data set, (test.csv), is the same as the training set, except that it does not contain the “label” column. Your submission file should be in the following format: ...

2017-06-05 · 1 min read · 148 words · KbWen · ZH

TENSORFLOW 練習4: word2vec

把字詞轉成 word embedding 要在字詞中找到他們之間的某種關聯,而不只是分散無意義的符號代表。 做這個問題的核心概念是: 「假設兩個不同句子中的詞上下文相同,則代表兩個詞的語意相近。」 今天要來使用 skip-gram 模型,一個類似二元分類的方式 (判斷像或是不像)。一開始也同之前的問題,先做數據處理。 計算出現數量:[(most count word1, n1), (second word2, n2)] 文字轉成向量: 例如:The actual code for this tutorial is very short 生成的 skip-gram pairs 示意: ([the, code], actual), ([actual, for], code), … (actual, the), (actual, code), (code, actual), … 在這之間都會給他編號,轉化為 (10, 20), (10, 30), (30, 10), (30, 40) ... 的形式。 用到 nce_loss,目前我還不是非常熟練,概念上是讓目標詞的機率越高越好,並讓其餘 K 個負面樣本 (negative samples) 的機率降低。 經典案例: king - queen = man - woman ==> king - queen + woman = man ...

2017-05-12 · 1 min read · 95 words · KbWen · ZH

Tensorflow 練習3: 'FizzBuzz'

Joel Grus — FizzBuzz in TensorFlow 從網路上看到的幽默問題,算是一個很有趣的使用,適合在做完 Classification 後練習。 輸入資料處理和原版程式碼一樣,因為還蠻直觀的: 1 – 000000001 – [0 0 0 0 0 0 0 0 1] 2 – 000000010 – [0 0 0 0 0 0 0 1 0] ……… 輸出則是用 [1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1] 來代表四個分類。 輸入輸出都是一個矩陣的形式。利用兩層 hidden layer 分別是 512 和 256,激勵函數選擇 relu,剩下的就交給 tensorflow 分類。 結果 一開始一直分不出來,都會卡在把每個資料都判定成同一類 (0.533)。後來減低每次訓練丟進去的量就 OK 了 (忘記一開始做分類時也只丟一點點進去)。 ...

2017-05-08 · 1 min read · 89 words · KbWen · ZH

Tensorflow 練習2: CNN

利用 CNN 來預測數字 (MNIST) 輸入圖形是一個 2828 灰階 0~9 的數字。輸出是一個 110 的矩陣,代表預測 0~9 的機率分布。 流程如下: 輸入 – convolution – pooling – convolution – pooling – hidden layer – output 在代碼中用到 [None, xx, xx] 和 [-1, XX, xx],代表我們忽略輸入的大小(batch size),它會跟隨著輸入自動改變。 max pooling 表示我們選擇的是那個 kernel size 裡的最大值。結構中也加入了 dropout 來避免 overfitting。 結果 上圖是沒有 dropout,下圖是有 dropout。就這個例子而言差別不大,但還是看得出來上面的訓練會比測試好。 準確率落在 97%~99% 之間 (1000 次訓練)。 (目前使用 GradientDescent,更換優化器應該會更好)。 My GitHub

2017-05-07 · 1 min read · 59 words · KbWen · ZH

PYTHON 機器學習基石 LS-PLA

Perceptron Learning Algorithm (PLA) 根據林軒田教授的機器學習基石課程,實作一下這個基礎的機器學習演算法。 我們探討的是監督式學習 (Supervised learning) 大架構下的二元分類 (YES/NO) 問題。 Perceptron ⇔ linear (Binary) Classifiers 我們有一組訓練資料 D,包含數據 Xn 和對應的 Yn (在這裡就是 1, -1);Hypothesis set H 代表全部可能的解 (無限多條線),經過演算法 A,從 H 找到一個可能的 g 與我們的目標函數 f 相近。 這個演算法的主要兩大步驟:找到錯誤的點,進行向量修正。 詳細課程可以參考教授的講解!!其中 naive cycle 是常用的作法。 這方法只適用於 linear separable PLA。 除此以外,當資料中有雜訊也無法使用這個方式,目前在線性問題上較好的解是用 Pocket PLA。 Linear separable PLA 首先整理一下資料。把原始格式如 ['x0\ty0\tz0\nx1\ty1\tz1\nx2\ty2\tz2\n....'] 轉換為 array([[(x0, y0), z0], [(x1, y1), z1], [(x2, y2), z2].....]) 的格式。 NAIVE PLA 實作,畫線則是用 ax + by = 0。 ...

2017-04-18 · 1 min read · 79 words · KbWen · ZH

Python reminder

變數 不用宣告變數的型態 可以直接用 x, y = y, x 對調 同時宣告多個變數的方法: 上下兩類方法會得到兩種結果 (前者數字,後者字串);注意變數數量和迭代的數量要相同。 String 表示 Escape \ Python 中 \ 代表著脫離字串,常見如下: 要讓「脫離字串」回到字串型式,前面要再加 \;例如倒數第二個用 Raw string 也是相同意思:r'****'。 字串可以迭代。 字串也有像基本 list 的取值、讀值方式;代表可以使用非物件專屬的函式,例如:len()。 範例,可以注意 find 指令的回傳值: ‘’.format() 與 %s 這兩種輸出方式會得到類似的結果: 目前看到在 tuple 下,% 會有問題,我想我會多習慣用 ''.format() 格式。

2017-04-14 · 1 min read · 42 words · KbWen · ZH

Tensorflow 使用GPUs

Tensorflow 支援使用 CPU 和 GPU 做運算: "/cpu:0": The CPU of your machine. "/gpu:0": The GPU of your machine, if you have one. "/gpu:1": The second GPU of your machine, etc. 用 with tf.device() 來分配這個語句下使用的設備。 可以用以下設定來優化運算: log_device_placement = True: 紀錄我們使用 device 的情況。 allow_soft_placement = True: 避免指定的 device 不存在,讓他能自行分配到存在且可運行的地方。 我沒有多顆 CPU,其他的語法先不試。

2017-04-14 · 1 min read · 49 words · KbWen · ZH

Tensorflow 練習1 : Polynomial Regression

使用 Tensorflow 分析 Regression 的基礎練習 Nerual network 分析二維四次多項式 先定義輸入輸出格式,None表示我們不限制它的Row 在 Tensorflow 中,要定義它是常數、變數,或是從外部輸入,必須要分別指定成: tf.constant() tf.Variable() tf.placeholder() 他才會是那個形式;而想使用 Tensorflow 的任何內容,必須要用 sess.run() 去啟動它,不然會是 Tensor 的格式。 其中 sess = tf.Session() 定義一個 Y = W*x + b 的線性方程,在隱藏層中利用 activation function 去改變它。 評估模型好壞常用有 square error 和 cross_entropy,這裡利用 square error 計算 loss。 選擇基本的梯度下降並最小化 loss;optimizer 是個小於 1 的值。 設定要訓練的數值和函數 (記得要有一定的雜訊) W shape = (in_dim, hidden_units) = (10,1) predictions shape = (200,1)*(1,10)*(10,1) = (200,1) 訓練 1000 次每 50 次看結果:視覺化和數據化 ...

2017-04-13 · 1 min read · 79 words · KbWen · ZH

Contact / 聯絡

Contact If you’d like to get in touch, feel free to email me: [email protected] Common topics: article corrections, technical collaboration, tool feedback, or anything related to the site. 聯絡 如果你想聯絡我,歡迎直接來信: [email protected] 常見主題包含文章勘誤、技術合作、工具回饋,或任何和本站內容相關的問題。

2017-04-12 · 1 min read · 32 words · KbWen · ZH

Search

0 min read · 0 words · KbWen · EN