Alan Richmond

Easy AI with Python 3

Survey several basic AI techniques implemented with short, open-source Python code recipes. Appropriate for educators and programmers who want to experiment with AI and apply the recipes to their own problem domains. For each technique, learn the basic operating principle, discuss an approach using Python, and review a worked out-example. We’ll cover database mining using neural nets, automated categorization with a naive Bayesian classifier, solving popular puzzles with depth-first and breadth-first searches, solving more complex puzzles with constraint propagation, and playing a popular game using a probing search strategy.

— Raymond Hettinger, Pycon 2009

I haven’t posted here in a few months (for no particularly good reason). Having recently become interested in Artificial Intelligence (AI), especially Machine Learning (ML), and then more especially Artificial Neural Networks (ANN), I was thinking about posting some short AI programs – but I have yet to write any. So today I came across this video of Raymond Hettinger talking about Easy AI with Python. Now if you don’t know about RH, you’re in for a treat! He’s possibly (IMHO) the world’s best teacher of Python, and he’s written a great deal of the Python interpreter. The code fragments in that (old) video seem to me to be ideal for this site, and so I’ll be posting some of them in due course (updated to Python 3). Meanwhile, please enjoy the video, embedded below!

Note that the codes are in Python 2; as just mentioned, I’ll be posting Python 3 versions, but till then, here are some of the things to change if you can’t wait:

  • Remove the x from xrange;
  • Change print to a function, with brackets;
  • More as I notice them.

I’m not sure whether all the programs he describes would be regarded as true AI by everyone, but they’re certainly fun, interesting, useful, and educational. And anyway some of the techniques typically found in AI/ML seem to me to be just ‘curve-fitting’ or some other piece of mathematics or computer science that doesn’t really warrant a fancy name; most of what we program computers to do previously required some level of intelligence. But I’m still a newb at this so I hope I’ll figure it out eventually!

00:00 Intro
05:00 Eight Queens – Six Lines…
06:45 Alphametics Solver…
11:30 Neural Nets for Data Mining…
16:20 Each unique value gets a neuron
22:10 Code
22:30 Mastermind…
31:20 Shannon’s formula applied to strategy – select probe with greatest information
33:55 Sudoku-style Puzzle…
38:50 Bayesian Classifier or…
43:30 Code44:50 Hettinger…
47:30 Q&A

Thanks to GothAlice for uploading this to YouTube.

[welcomewikilite wikiurl=”” sections=”Short description” settings=””]

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.