标签:
前部为英文原文,原文链接:http://machinelearningmastery.com/understand-machine-learning-algorithms-by-implementing-them-from-scratch/
后部为中文翻译,本文中文部分转自:http://www.csdn.net/article/2015-09-08/2825646
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.
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.
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.
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个你可以使用的快速技巧,可以让你从实现机器学习算法过程中获得最多的经验。
我认为这些技巧与教程和代码实例相比,会让你走的更远。
特别是最后一点,会给你在算法行为上更深层次的见解,很少有从业人员花时间去学习它。
这是一篇很长的文章,现在,你已经学会了如何从零开始实现机器学习算法。
重要的是,你已经了解了最常见的障碍、一些框架是如何形成的以及一些你可以运用的战术,你可以把它们转化为机遇。
你的下一步很明显:从零开始实现算法。
标签:
原文地址:http://www.cnblogs.com/gooking/p/4818501.html