The Analytic Edge Lecture code in Python Week8 WHO

VIDEO 4 - A BASIC SCATTERPLOT

Read in data

Plot from Week 1

png

Let's redo this using ggplot

There is a ggplot library developed by yhat for python, but it is not as developed as ggplot2 in R.

Since the ggplotin Python is based on matplotlib, there are some small differences.

Create the ggplot object with the data and the aesthetic mapping:

Add the geom_point geometry

png

Make a line graph instead:

png

Switch back to our points:

png

Redo the plot with blue triangles instead of circles:

To specify the type of plotting symbols, reference the marker in matplotlib Also notice the size is different.

png

Another option:

png

Add a title to the plot:

png

Save our plot:

VIDEO 5 - MORE ADVANCED SCATTERPLOTS

Color the points by region:

png

Color the points according to life expectancy:

png

Is the fertility rate of a country was a good predictor of the percentage of

the population under 15?

png

Let's try a log transformation:

png

Simple linear regression model to predict the percentage of the population

under 15, using the log of the fertility rate:

Add this regression line to our plot:

png

99% confidence interval

png

No confidence interval in the plot

png

Change the color of the regression line:

png

Leave a Reply

Your email address will not be published. Required fields are marked *