Clojure for Machine Learning Successfully leverage advanced machine learning techniques using the Clojure ecosystem Akhil Wali BIRMINGHAM - MUMBAI Clojure for Machine Learning Copyright © 2014 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: April 2014 Production Reference: 1180414 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78328-435-1 www.packtpub.com Cover Image by Jarek Blaminsky ([email protected]) Credits Author Project Coordinator Akhil Wali Mary Alex Reviewers Proofreaders Jan Borgelin Simran Bhogal Thomas A. Faulhaber, Jr. Maria Gould Shantanu Kumar Ameesha Green Dr. Uday Wali Paul Hindle Commissioning Editor Indexer Rubal Kaur Mehreen Deshmukh Acquisition Editor Graphics Llewellyn Rozario Ronak Dhruv Yuvraj Mannari Content Development Editor Abhinash Sahu Akshay Nair Production Coordinator Technical Editors Nitesh Thakur Humera Shaikh Ritika Singh Cover Work Nitesh Thakur Copy Editors Roshni Banerjee Karuna Narayanan Laxmi Subramanian About the Author Akhil Wali is a software developer, and has been writing code since 1997. Currently, his areas of work are ERP and business intelligence systems. He has also worked in several other areas of computer engineering, such as search engines, document collaboration, and network protocol design. He mostly works with C# and Clojure. He is also well versed in several other popular programming languages such as Ruby, Python, Scheme, and C. He currently works with Computer Generated Solutions, Inc. This is his first book. I would like to thank my family and friends for their constant encouragement and support. I want to thank my father in particular for his technical guidance and help, which helped me complete this book and also my education. Thank you to my close friends, Kiranmai, Nalin, and Avinash, for supporting me throughout the course of writing this book. About the Reviewers Jan Borgelin is the co-founder and CTO of BA Group Ltd., a Finnish IT consultancy that provides services to global enterprise clients. With over 10 years of professional software development experience, he has had a chance to work with multiple programming languages and different technologies in international projects, where the performance requirements have always been critical to the success of the project. Thomas A. Faulhaber, Jr. is the Principal of Infolace (www.infolace.com), a San Francisco-based consultancy. Infolace helps clients from start-ups and global brands turn raw data into information and information into action. Throughout his career, he has developed systems for high-performance networking, large-scale scientific visualization, energy trading, and many more. He has been a contributor to, and user of, Clojure and Incanter since their earliest days. The power of Clojure and its ecosystem (for both code and people) is an important "magic bullet" in his practice. He was also a technical reviewer for Clojure Data Analysis Cookbook, Packt Publishing. Shantanu Kumar is a software developer living in Bangalore, India, with his wife. He started programming using QBasic on MS-DOS when he was at school (1991). There, he developed a keen interest in the x86 hardware and assembly language, and dabbled in it for a good while after. Later, he programmed professionally in several business domains and technologies while working with IT companies and the Indian Air Force. Having used Java for a long time, he discovered Clojure in early 2009 and has been a fan ever since. Clojure's pragmatism and fine-grained orthogonality continues to amaze him, and he believes that this is the reason he became a better developer. He is the author of Clojure High Performance Programming, Packt Publishing, is an active participant in the Bangalore Clojure users group, and develops several open source Clojure projects on GitHub. Dr. Uday Wali has a bachelor's degree in Electrical Engineering from Karnatak University, Dharwad. He obtained a PhD from IIT Kharagpur in 1986 for his work on the simulation of switched capacitor networks. He has worked in various areas related to computer-aided design, such as solid modeling, FEM, and analog and digital circuit analysis. He worked extensively with Intergraph's CAD software for over 10 years since 1986. He then founded C-Quad in 1996, a software development company located in Belgaum, Karnataka. C-Quad develops custom ERP software solutions for local industries and educational institutions. He is also a professor of Electronics and Communication at KLE Engineering College, Belgaum. He guides several research scholars who are affiliated to Visvesvaraya Technological University, Belgaum. www.PacktPub.com Support files, eBooks, discount offers and more You might want to visit www.PacktPub.com for support files and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. TM http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books. Why Subscribe? • Fully searchable across every book published by Packt • Copy and paste, print and bookmark content • On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access. Table of Contents Preface 1 Chapter 1: Working with Matrices 7 Introducing Leiningen 7 Representing matrices 9 Generating matrices 15 Adding matrices 20 Multiplying matrices 23 Transposing and inverting matrices 28 Interpolating using matrices 35 Summary 39 Chapter 2: Understanding Linear Regression 41 Understanding single-variable linear regression 42 Understanding gradient descent 51 Understanding multivariable linear regression 55 Gradient descent with multiple variables 59 Understanding Ordinary Least Squares 61 Using linear regression for prediction 63 Understanding regularization 64 Summary 66 Chapter 3: Categorizing Data 67 Understanding the binary and multiclass classification 68 Understanding the Bayesian classification 75 Using the k-nearest neighbors algorithm 91 Using decision trees 93 Summary 99
Description: