前部爲英文原文,原文連接:http://machinelearningmastery.com/understand-machine-learning-algorithms-by-implementing-them-from-scratch/程序員
後部爲中文翻譯,本文中文部分轉自:http://www.csdn.net/article/2015-09-08/2825646web
Understand Machine Learning Algorithms By Implementing Them From Scratch (and tactics to get around算法
Implementing machine learning algorithms from scratch seems like a great way for a programmer to understand machine learning.編程
And maybe it is.app
But there some downsides to this approach too.框架
In this post you will discover some great resources that you can use to implement machine learning algorithms from scratch.機器學習
You will also discover some of the limitations of this seemingly perfect approach.編程語言
Have you implemented a machine learning algorithm from scratch in an effort to learn about it Leave a comment, I’d love to hear about your experience.ide
Implement machine learning algorithms from scratch!
Photo by Tambako The Jaguar, some rights reserved.函數
I promote the idea of implementing machine learning algorithms from scratch.
I think you can learn a lot about how algorithms work. I also think that as a developer, it provides a bridge into learning the mathematical notations, descriptions and intuitions used in machine learning.
I’ve discussed the benefits of implementing algorithms from scratch before in the post 「Benefits of Implementing Machine Learning Algorithms From Scratch「.
In the post I listed the benefits as:
Also in that post I comment how you can short-cut the process by leveraging existing tutorials and books. There is a wealth of good resources for getting started, but there are also stumbling blocks to watch out for.
In the next section I point out three books that you can follow to implement machine learning algorithms from scratch.
I’ve helped a lot of programmers get started in machine learning over the last few years. From my experience, I list 5 of the most common stumbling blocks that I see tripping up programmers and the tactics that you can use to over come them.
Finally, you will discover 3 quick tips to getting the most from code tutorials and going from a copy-paste programmer (if you happen to be one) to truly diving down the rabbit hole of machine learning algorithms.
I have implemented a lot of algorithms from scratch, directly from research papers. It can be very difficult.
It is a much gentler start to follow someone else’s tutorial.
There are many excellent resources that you can use to get started implementing machine learning algorithms from scratch.
Perhaps the most authoritative are books that guide you through tutorials.
There are many benefits to starting with a book. For example:
Some great books that guide you through implementing machine learning algorithms step-by-step are:
This truly is from scratch, working through visualization, stats, probability, working with data and then 12 or so different machine learning algorithms.
This is one of my favorite beginner machine learning books from this year.
This is the long awaited second edition to this popular book. This covers a large number of diverse machine learning algorithms with implementations.
I like that it gives a mix of mathematical description, pseudo code as well as working source code.
This book works through the 10 most popular machine learning algorithms providing case study problems and worked code examples in Python.
I like that there is a good effort to tie the code to the descriptions using numbering and arrows.
Did I miss a good book that provides programming tutorials for implementing machine learning algorithms from scratch?
Let me know in the comments.
Implementing machine learning algorithms from scratch using tutorials is a lot of fun.
But there can be stumbling blocks, and if you’re not careful, they may trip you up and kill your motivation.
In this section I want to point out the 5 most common stumbling blocks that I see and how to roll with them and not let them hold you up. I want you to get unstuck and plow on (or move on to another tutorial).
Some good general advice for avoiding the stumbling blocks below is to carefully check the reviews of books (or the comments on blog posts) before diving into a tutorial. You want to be sure that the code works and that you’re not wasting your time.
Another general tactic is to dive-in no matter what and figure out the parts that are not working and re-implement them yourself. This is a great hack to force understanding, but it’s probably not for the beginner and you may require a good technical reference close at hand.
Anyway, let’s dive into the 5 common stumbling blocks with machine learning from scratch tutorials:
The worst and perhaps most common stumbling block is that the code in the example does not work.
In fact, if you spend some time in the book reviews on Amazon for some texts or in the comments of big blog posts, it’s clear that this problem is more prevalent than you think.
How does this happen? A few reasons come to mind that might give you clues to applying your own fixes and carrying on:
A good general tactic if the code does not work is to look for the associated errata if it is a book, GitHub repository, code downloads or similar. Sometimes the problems have been fixed and are available on the book or author’s website. Some simple Googling should turn it up.
Code machine learning algorithms completely from scratch. Photo by Tambako The Jaguar, some rights reserved
I think the second worst stumbling block when implementing algorithms from scratch is when the descriptions provided with the code are bad.
These types of problems are particularly not good for a beginner, because you are trying your best to stay motivated and actually learn something from the exercise. All of that goes down in smoke if the code and text do not align.
I (perhaps kindly) call them 「bad descriptions」 because there may be many symptoms and causes. For example:
A good general tactic is to look up description for the algorithm in other resources and try to map them onto the code you are working with. Essentially, try to build your own descriptions for the code.
This just might not be an option for a beginner and you may need to move on to another resource.
We programmers can be pedantic about the 「correct」 use of our languages (e.g. Python code is not Pythonic). This is a good thing, it shows good attention to detail and best practices.
When sample code is not idiomatic to the language in which it is written it can be off putting. Sometimes it can be so distracting that the code can be unreadable.
There are many reasons that this may be the case, for example:
If idiomatic code is deeply important to you, these stumbling blocks could be an opportunity. You could port the code from the 「Java-Python」 hybrid (or whatever) to a pure Pythonic implementation.
In so doing, you would gain a deeper understanding for the algorithm and more ownership over the code.
A good code example or tutorial will provide a bridge from the mathematical description to the code.
This is important because it allows you to travel across and start to build an intuition for the notation and the concise mathematical descriptions.
There problem is, sometimes this bridge may be broken or missing completely.
A beginner might want to stick with code and ignore the math, to build confidence and momentum. Later, it will pay to invest in a high-quality reference text and start relating the code to the math.
You want to get good at relating the algebra to standard code constructs and build an intuition for the process involved. It’s an applied skill. You need to put in the work and practice.
We saw in 2) that you can have no descriptions and long listings of code. This problem can be inverted where you don’t have enough code. This is the case when the code listing is incomplete.
I am a big believer in complete code listings. I think the code listing should give you everything you need to give a 「complete」 and working implementation, even if it is the simplest possible case.
You can build on a simple case, you can’t run an incomplete example. You have to put in work and tie it all together.
Some reasons that this stumbling block may be the case, are:
【編者按】並不是全部的開發者都有機器學習算法的基礎知識,那麼開發者如何從零入門來學習好機器學習算法呢?本文總結推薦了一些從零開始學習機器學習算法的辦法,包括推薦了一些合適的書籍,如何克服所面臨的各類障礙,以及快速得到更多知識的竅門。
從零開始實現機器學習算法彷佛是開發者理解機器學習的一個出色方式。或許真的是這樣,但這種作法也有一些缺點。
在這篇文章中,你會發現一些很好的資源,能夠用來從零開始實現機器學習算法。你也會發現一些看似完美的方法的侷限性。你已經從零開始實現機器學習算法並努力學習留下的每一條評論了麼?我很樂意聽到關於你的經驗。
從零開始實現機器學習算法!圖片來自Tambako The Jaguar
我推廣了從零開始實現機器學習算法的觀念。
我認爲你能夠學到不少關於算法是如何工做的。我也認爲,做爲一名開發者,它提供了一個學習用於機器學習的數學符號、描述以及直覺的橋樑。
在「從零開始實現機器學習算法的好處」這篇文章裏,我已經討論了從零實現機器學習算法的好處。
在那篇文章,我列出的好處以下:
在這篇文章中,我對如何利用現有的教程和書籍來縮短這個學習過程表達了一些我的見解。有一些用於初學的豐富資源,但也要堤防一些絆腳石。
下一節,我指出了三本書,你能夠照着書籍從零開始實現機器學習算法。
在過去的幾年裏,我已經在機器學習入門中幫助了許多程序員。根據個人經驗,我列出了五項曾困擾過程序員的最多見的障礙,以及你能夠用來克服它們的技巧。
最後,你會發現3個快速技巧,用以從代碼教程中得到更豐富的知識,並從一個複製粘貼的程序員(若是你碰巧是其中一個)到一個真正深刻機器學習算法的學者。
我從零實現過許多算法,這些算法直接來自研究論文。這個過程可能很是困難。
跟着別人的教程來作是一個很是溫和的開始。有不少優秀的資源,可讓你用來從零開始實現機器學習算法。也許最具權威性的是能指導你完成整個教程的書籍。
從啃書本開始學習有不少好處。例如:
那麼,一步一步引導你完成機器學習算法實現的出色書籍有:
這本書的確是從零開始,貫穿可視化操做、統計、機率、數據處理,而後是大約12個不一樣的機器學習算法。
這本書是我今年最喜歡的機器學習初學者書籍之一。
我喜歡它既給出了數學描述和僞代碼,又包含了能執行的源代碼。
我喜歡它用符號和箭頭把代碼和描述緊密聯繫在一塊兒的形式。
我是否有漏掉一本從零開始實現機器學習算法的編程教程書籍呢?
若是有,請在評論中指出!
根據教程從零開始實現機器學習算法是頗有趣的。但也有可能會成爲絆腳石,並且若是你不當心,他們可能會絆倒你並抹殺你的學習動機。
在這一節中,我想指出我所看到的五個常見的絆腳石,以及如何與它們共存,而不是讓它們阻礙你。個人目的是讓你徹底擺脫它而且破浪前行(或是轉移到另外一個教程)。
用來避免下面障礙的一些好的常規建議是在你深刻一個教程以前,仔細檢查書籍的評論(或博客帖子的評論)。你要確保代碼是可以工做的而且保證你不是在浪費時間。
另外一個常規策略是,不管深刻的是什麼,找出不工做的那部分,並本身去從新實現他們。這是一個強行理解的出色解決方法,但它可能不適合初學者,而且你可能須要一個很好的技術參考資料放在手邊。
不管如何,讓咱們從零開始機器學習教程,深刻研究這5個常見的障礙:
最糟糕而且最多見的障礙就是實例當中的代碼不能正常工做。
事實上,若是你花一些時間瀏覽亞馬遜網站的一些書籍評論或博文評論,很顯然,這個問題比你想象的更爲廣泛。
這是怎麼發生的呢?有幾個緣由可能會給你提供一些線索,能夠應用到你本身的修改中並繼續使用:
若是它是一本書、GitHub庫、代碼下載或者相似的,若是代碼不工做,一個好的常規策略是尋找相關的勘誤表。有時這些問題已經在書上或做者的網站上修正了。一些簡單的谷歌搜索就能找到它們。
當從零開始實現算法時,我認爲第二個糟糕的絆腳石是提供的代碼描述很糟糕。
對於初學者來講,這類問題特別很差,由於你正在努力維持積極性,而實際上你是從練習中學習一些東西。若是代碼和文本不一致,全部的這些都會在煙霧中漸漸消失。
我(或許比較溫和)把他們稱爲「糟糕的描述」,由於可能有不少的症狀和緣由。例如:
一個好的常規方法是在其它的資源裏尋找算法的描述,並嘗試將它們映射到你所使用的代碼中。從本質上講,是嘗試創建你本身的代碼描述。
這對初學者來講可能不是一個好的選擇,你可能須要轉到另外一個資源上。
咱們程序員能夠對咱們語言的 「正確」使用咬文嚼字(如Python代碼不是Pythonic)。這實際上是一件好事,它顯示了對細節和最佳實踐的充分關注。
當實例代碼不符合語言編寫習慣時,它可能會讓人排斥。有時它會使代碼零散以致於難以理解。
這種狀況有許多緣由,例如:
若是你慣用的代碼對你很是重要,這些障礙可能會是一個機會。你能夠把接口代碼從「Java-Python」混合體(或別的什麼)化爲一個純Python的實現。
這麼作以後,你將獲得一個更深層次的算法理解以及更多的代碼所屬權。
一個很好的代碼示例或教程將提供一個從數學描述到代碼的橋樑。
這很重要,由於它容許你跨越代碼和數學,並開始爲符號和簡明的數學描述造成一個直覺。
問題是,有時候這個橋樑可能會被完全破壞或是丟失。
一個初學者可能會堅持代碼而忽略數學,創建信心和動力。以後,它將爲一個高質量的參考文本以及關聯代碼和數學付出代價。
你想要擅長於關聯代數和標準代碼,併爲有關過程創建一個直覺。這是一個應用技巧。須要你投入工做與實踐。
咱們在2)中看到,你能夠有不帶任何描述和長列表的代碼。然而,當你沒有大量代碼的時候,這個問題會逆轉。這也就是代碼列表不完整時的狀況。
事實上,我是一個完整代碼列表的忠實信徒。我認爲代碼列表應該給你所須要的,給你一個「完整」的代碼和工做實現,即便它是最簡單的狀況。
你能夠創建一個簡單的實例,但你不能運行一個不完整的例子。你必須把它放在工做中並把全部的都聯繫在一塊兒。
這個障礙可能成爲事實的一些緣由是:
在某些狀況下,把代碼聚在一塊兒,這對你可能會是一個有趣的挑戰。這一樣不適合初學者,可是一旦你有一些算法以後,這也許會是一個有趣的鍛鍊。
你能夠實現一個合理的算法。一旦你這樣作過,那麼你能夠作得更多,並在你知道它以前,你已經創建了你本身很是理解的小算法庫。
在這一節中,我想給你3個你可使用的快速技巧,可讓你從實現機器學習算法過程當中得到最多的經驗。
我認爲這些技巧與教程和代碼實例相比,會讓你走的更遠。
特別是最後一點,會給你在算法行爲上更深層次的看法,不多有從業人員花時間去學習它。
這是一篇很長的文章,如今,你已經學會了如何從零開始實現機器學習算法。
重要的是,你已經瞭解了最多見的障礙、一些框架是如何造成的以及一些你能夠運用的戰術,你能夠把它們轉化爲機遇。
你的下一步很明顯:從零開始實現算法。