In this book, we start with an exploratory tour of the basics of graphical models, their types, why they are used, and what kind of problems they solve. We then explore subproblems in the context of graphical models, such as their representation, building them, learning their structure and parameters, and using them to answer our inference queries.
This book attempts to give just enough information on the theory, and then use code samples to peep under the hood to understand how some of the algorithms are implemented. The code sample also provides a handy template to build graphical models and answer our probability queries. Of the many kinds of graphical models described in the literature, this book primarily focuses on discrete Bayesian networks, with occasional examples from Markov networks.
Chapter 1, Probability, covers the concepts of probability required to understand the graphical models.
Chapter 2, Directed Graphical Models, provides information about Bayesian networks, their properties related to independence, conditional independence, and D-separation. This chapter uses code snippets to load a Bayes network and understand its independence properties.
Chapter 3, Undirected Graphical Models, covers the properties of Markov networks, how they are different from Bayesian networks, and their independence properties.
Chapter 4, Structure Learning, covers multiple approaches to infer the structure of the Bayesian network using a dataset. We also learn the computational complexity of structure learning and use code snippets in this chapter to learn the structures given in the sampled datasets.
Chapter 5, Parameter Learning, covers the maximum likelihood and Bayesian approaches to parameter learning with code samples from PyMC.
Chapter 6, Exact Inference Using Graphical Models, explains the Variable Elimination algorithm for accurate inference and explores code snippets that answer our inference queries using the same algorithm.
Chapter 7, Approximate Inference Methods, explores the approximate inference for networks that are too large to run exact inferences on. We will also go through the code samples that run approximate inferences using loopy belief propagation on Markov networks.
Appendix, References, includes all the links and URLs that will help to easily understand the chapters in the book.
To run the code samples in the book, you'll need a laptop or desktop with IPython installed. We use several software packages in this book, most of them can be installed using the Python installation procedure such as pip
or easy_install
. In some cases, the software needs to be compiled from the source and may require a C++ compiler.
This book is aimed at developers conversant with Python and who wish to explore the nuances of graphical models using code samples.
This book is also ideal for students who have been theoretically introduced to graphical models and wish to realize the implementations of graphical models and get a feel for the capabilities of different (graphical model) libraries to deal with real-world models.
Machine-learning practitioners familiar with classification and regression models and who wish to explore and experiment with the types of problems graphical models can solve will also find this book an invaluable resource.
This book looks at graphical models as a tool that can be used to solve problems in the machine-learning domain. Moreover, it does not attempt to explain the mathematical underpinnings of graphical models or go into details of the steps for each algorithm used.
In this book, you will find a number of styles of text 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 can do the same by creating a TfidfVectorizer
object."
A block of code is set as follows:
clf = MultinomialNB(alpha=.01) print "CrossValidation Score: ", np.mean(cross_validation.cross_val_score(clf,vectors, newsgroups.target, scoring='f1')) CrossValidation Score: 0.954618416381
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <[email protected]>
, and mention the book title via 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 on www.packtpub.com/authors.
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.
You can download the example code files for all Packt books you have purchased 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.
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 would 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 on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyright 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.
You can contact us at <[email protected]>
if you are having a problem with any aspect of the book, and we will do our best to address it.