Book Image

Machine Learning Algorithms

Book Image

Machine Learning Algorithms

Overview of this book

In this book, you will learn all the important machine learning algorithms that are commonly used in the field of data science. These algorithms can be used for supervised as well as unsupervised learning, reinforcement learning, and semi-supervised learning. The algorithms that are covered in this book are linear regression, logistic regression, SVM, naïve Bayes, k-means, random forest, TensorFlow and feature engineering. In this book, you will how to use these algorithms to resolve your problems, and how they work. This book will also introduce you to natural language processing and recommendation systems, which help you to run multiple algorithms simultaneously. On completion of the book, you will know how to pick the right machine learning algorithm for clustering, classification, or regression for your problem
Table of Contents (22 chapters)
Title Page
Credits
About the Author
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface

Preface

This book is an introduction to the world of machine learning, a topic that is becoming more and more important, not only for IT professionals and analysts but also for all those scientists and engineers who want to exploit the enormous power of techniques such as predictive analysis, classification, clustering and natural language processing. Of course, it's impossible to cover all the details with the appropriate precision; for this reason, some topics are only briefly described, giving the user the double opportunity to focus only on some fundamental concepts and, through the references, examine in depth all those elements that will generate much interest. I apologize in advance for any imprecision or mistakes, and I'd like to thank all Packt editors for their collaboration and constant attention.

I dedicate this book to my parents, who always believed in me and encouraged me to cultivate my passion for this extraordinary subject.

What this book covers

Chapter 1, A Gentle Introduction to Machine Learning, introduces the world of machine learning, explaining the fundamental concepts of the most important approaches to creating intelligent applications.

Chapter 2, Important Elements in Machine Learning, explains the mathematical concepts regarding the most common machine learning problems, including the concept of learnability and some elements of information theory.

Chapter 3, Feature Selection and Feature Engineering, describes the most important techniques used to preprocess a dataset, select the most informative features, and reduce the original dimensionality.

Chapter 4, Linear Regression, describes the structure of a continuous linear model, focusing on the linear regression algorithm. This chapter covers also Ridge, Lasso, and ElasticNet optimizations, and other advanced techniques.

Chapter 5, Logistic Regression, introduces the concept of linear classification, focusing on logistic regression and stochastic gradient descent algorithms. The second part covers the most important evaluation metrics.

Chapter 6, Naive Bayes, explains the Bayes probability theory and describes the structure of the most diffused naive Bayes classifiers.

Chapter 7, Support Vector Machines, introduces this family of algorithms, focusing on both linear and nonlinear classification problems.

Chapter 8, Decision Trees and Ensemble Learning, explains the concept of a hierarchical decision process and describes the concepts of decision tree classification, Bootstrap and bagged trees, and voting classifiers.

Chapter 9, Clustering Fundamentals, introduces the concept of clustering, describing the k-means algorithm and different approaches to determining the optimal number of clusters. In the second part, the chapter covers other clustering algorithms such as DBSCAN and spectral clustering.

Chapter 10, Hierarchical Clustering, continues the explanation started in the previous chapter and introduces the concept of agglomerative clustering.

Chapter 11, Introduction to Recommendation Systems, explains the most diffused algorithms employed in recommender systems: content- and user-based strategies, collaborative filtering, and alternating least square.

Chapter 12, Introduction to Natural Language Processing, explains the concept of bag-of-words and introduces the most important techniques required to efficiently process natural language datasets.

Chapter 13, Topic Modeling and Sentiment Analysis in NLP, introduces the concept of topic modeling and describes the most important algorithms, such as latent semantic analysis and latent Dirichlet allocation. In the second part, the chapter covers the problem of sentiment analysis, explaining the most diffused approaches to address it.

Chapter 14, A Brief Introduction to Deep Learning and TensorFlow, introduces the world of deep learning, explaining the concept of neural networks and computational graphs. The second part is dedicated to a brief exposition of the main concepts regarding the TensorFlow and Keras frameworks, with some practical examples.

Chapter 15, Creating a Machine Learning Architecture, explains how to define a complete machine learning pipeline, focusing on the peculiarities and drawbacks of each step.

What you need for this book

There are no particular mathematical prerequisites; however, to fully understand all the algorithms, it's important to have a basic knowledge of linear algebra, probability theory, and calculus.

All practical examples are written in Python and use the scikit-learn machine learning framework, Natural Language Toolkit (NLTK), Crab, langdetect, Spark, gensim, and TensorFlow (deep learning framework). These are available for Linux, Mac OS X, and Windows, with Python 2.7 and 3.3+. When a particular framework is employed for a specific task, detailed instructions and references will be provided.

Note

scikit-learn, NLTK, and TensorFlow can be installed by following the instructions provided on these websites: http://scikit-learn.org, http://www.nltk.org, and https://www.tensorflow.org.

Who this book is for

This book is for IT professionals who want to enter the field of data science and are very new to machine learning. Familiarity with the Python language will be invaluable here. Moreover, basic mathematical knowledge (linear algebra, calculus, and probability theory) is required to fully comprehend the content of most of the chapters.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning. Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We have created a configuration through the SparkConf class."

Any command-line input or output is written as follows:

>>> nn = NearestNeighbors(n_neighbors=10, radius=5.0, metric='hamming')
>>> nn.fit(items)

New terms and important words are shown in bold.

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support, and register to have the files e-mailed directly to you. You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.
  5. Select the book for which you're looking to download the code files.
  6. Choose from the drop-down menu where you purchased this book from.
  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Machine-Learning-Algorithms. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/MachineLearningAlgorithms_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title. To view the previously submitted errata, go to https://www.packtpub.com/books/content/support, and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy. Please contact us at [email protected] with a link to the suspected pirated material. We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.