concept visualization in category dask

This is an excerpt from Manning's book Data Science with Python and Dask.
Before we dive into the Dask code, if you haven’t already done so, check out the appendix for instructions on how to install Dask and all the packages you’ll need for the code examples in the remainder of the book. You can also find the complete code notebooks online at www.manning.com/books/data-science-with-python-and-dask and also at http://bit.ly/daskbook. For all the examples throughout the book (unless otherwise noted), I recommend you use a Jupyter Notebook. Jupyter Notebooks will help you keep your code organized and will make it easy to produce visualizations when necessary. The code in the examples has been tested in both Python 2.7 and Python 3.6 environments, so you should be able to use either without issue. Dask is available for both major versions of Python, but I highly recommend that you use Python 3 for any new projects, because the end of support for Python 2 is slated for 2020.
In the previous chapter, we performed some basic analyses of the NYC Parking Ticket data by looking at descriptive statistics and some other numerical properties of the dataset. While describing data numerically is precise, the results can be somewhat difficult to interpret and are generally not intuitive. On the other hand, we humans are very good at detecting and understanding patterns in visual information. Incorporating visualization into our analyses can help us better understand the general makeup of our dataset as well as how different variables interact with one another.
For example, consider the relationship between average temperature and the number of citations issued that we explored in the previous chapter. We calculated a Pearson correlation coefficient of about 0.14. We concluded that the two variables have a weak positive correlation, meaning we should expect the number of citations issued to increase slightly as the average temperature rises. Given our findings, should we expect global climate change to become a lucrative phenomenon for the city of New York? Or does the nature of the relationship change depending on which range of values we’re looking at? A simple correlation coefficient can’t convey all that information. We’ll come back to that question momentarily. For now, to really highlight why visualization is such an important part of data analysis, let’s look at a classic problem in statistics known as Anscombe’s quartet. Anscombe’s quartet is a hypothetical dataset presented in 1973 by an English statistician named Francis Anscombe, who was frustrated by his field’s lack of appreciation for visualization. He wanted to demonstrate that numerical methods alone don’t always tell the full story: each of the four datasets that make up his quartet share the same mean, variance, correlation, regression line, and coefficient of determination. Figure 7.1 displays the four datasets that make up Anscombe’s quartet.
Figure 7.1 Anscombe’s quartet highlights the importance of using visualization for effective data analysis.
![]()
If we relied on numerical methods alone, we might conclude that each of the four datasets is completely identical. However, graphically, they tell a different story. Two of the datasets, X3 and X4, have extreme outliers. Dataset X4appears to have an undefined slope, and dataset X2 appears to be a nonlinear, perhaps parabolic function. Consequently, the appropriate methods we might use to numerically describe and analyze each of the four datasets would be completely different after learning more about the data through visualization.
Notice that Anscombe’s quartet is a very small dataset, so visualizing it as a set of scatterplots is simple and straightforward. However, visualizing large datasets can be tricky due to both the volume and variety of data. Because there are many kinds of visualizations to choose from, for all different kinds of data, we can’t possibly cover all kinds of visualizations in this book. Therefore, we will cover some general patterns and tactics that you can extend to produce many kinds of visualizations, and we will cover a few of the more common visualizations that are useful for analyzing structured data. As always, figure 7.2 shows what we’ve accomplished so far and where we’ll turn our focus next.
Figure 7.2 The Data Science with Python and Dask workflow
![]()
In this chapter, we’ll continue working on exploratory analysis and hypothesis formulation and testing, but with a focus on using visualizations to dig deeper into the analyses. We’ll also blend some data-manipulation techniques you learned in previous chapters, such as aggregations, with new techniques like sampling. All the computations to prepare the data for visualization will be performed with Dask using the DataFrame API.
Listing 8.7 Creating the interactive visualization
nyc311_geo_data = dd.read_parquet('nyc311_webmercator_coords') #1 holoviews.extension('bokeh') #2 stamen_api_url = 'http://tile.stamen.com/terrain/{Z}/{X}/{Y}.jpg' #3 plot_options = dict(width=900, height=700, show_grid=False) #4 tile_provider = geoviews.WMTS(stamen_api_url).opts(style=dict(alpha=0.8), plot=plot_options) #5 points = holoviews.Points(nyc311_geo_data, ['x', 'y']) service_calls = datashade(points, x_sampling=1, y_sampling=1, width=900, height=700) #6 tile_provider * service_calls #7 #1 Read the parquet data back in. #2 Enable the bokeh extension in HoloViews. #3 Set a URL to the Stamen map tile API; {Z} represents zoom level, {X} is the Web Mercator X coordinate, and {Y} is the Web Mercator Y coordinate. #4 Set the display options for the visualization. #5 Create a new Web Mercator tile provider using the specified API url. #6 Plot the X and Y points on a grid. #7 Overlay the map tiles with the heatmap.