Book Image

Practical Data Science Cookbook

By : Tony Ojeda, Sean Patrick Murphy, Benjamin Bengfort, Abhijit Dasgupta
Book Image

Practical Data Science Cookbook

By: Tony Ojeda, Sean Patrick Murphy, Benjamin Bengfort, Abhijit Dasgupta

Overview of this book

<p>As increasing amounts of data is generated each year, the need to analyze and operationalize it is more important than ever. Companies that know what to do with their data will have a competitive advantage over companies that don't, and this will drive a higher demand for knowledgeable and competent data professionals.</p> <p>Starting with the basics, this book will cover how to set up your numerical programming environment, introduce you to the data science pipeline (an iterative process by which data science projects are completed), and guide you through several data projects in a step-by-step format. By sequentially working through the steps in each chapter, you will quickly familiarize yourself with the process and learn how to apply it to a variety of situations with examples in the two most popular programming languages for data analysis—R and Python.</p>
Table of Contents (18 chapters)
Practical Data Science Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Rewriting simple functions with NumPy


With the impressive test results from the previous recipe, this recipe will focus on rewriting some of the smaller functions in asa.py using NumPy. We will start with the smaller, more manageable find_neighbor_indices function as a prototype for changes to the main function.

Getting ready

To prepare for this recipe, we will create a copy of asa.py and call it asa_np_v1.py.

How to do it…

The following steps will walk you through this recipe:

  1. First, add the @profile decorator to the find_neighbor_indices function in asa.py:

    @profile
    def find_neighbor_indices(points, radii, probe, k):
    
  2. We will use line_profile to benchmark the original find_neighbor_indices function:

    python kernprof.py -l asa_np_v1.py "1R0R.pdb"
    
  3. The results are shown in the following command-line output, and the computed result matches the reference value:

    12114.7 angstrom squared.
    Wrote profile results to asa_np_v1.py.lprof
    
  4. We use line_profiler again to visualize the results:

    python -m line_profiler...