<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 DAT210x - Programming with Python for DS
Module5- Lab8
Step1:  A Convenience Function
This convenience method will take care of plotting your test observations, comparing them to the regression line, and displaying the R2 coefficient
Step2:  The Assignment
Load up the data here into a variable called X. As usual, do a .describe and a print of your dataset and compare it to the dataset loaded in a text file or in a spread sheet application
Step3:  Create your linear regression model here and store it in a variable called model. Don't actually train or do anything else with it yet
Step4:  Slice out your data manually (e.g. don't use train_test_split, but actually do the indexing yourself. Set X_train to be year values LESS than 1986, and y_train to be corresponding 'WhiteMale' age values. You might also want to read the note about slicing on the bottom of this document before proceeding
Step5:  Train your model then pass it into drawLine with your training set and labels. You can title it 'WhiteMale'. drawLine will output to the console a 2014 extrapolation / approximation for what it believes the WhiteMale's life expectancy in the U.S. will be... given the pre-1986 data you trained it with. It'll also produce a 2030 and 2045 extrapolation
Step6:  Print the actual 2014 'WhiteMale' life expectancy from your loaded dataset
Step7:  Repeat the process, but instead of for WhiteMale, this time select BlackFemale. Create a slice for BlackFemales, fit your model, and then call drawLine. Lastly, print out the actual 2014 BlackFemale life expectancy
Step8:  Lastly, print out a correlation matrix for your entire dataset, and display a visualization of the correlation matrix, just as we described in the visualization section of the course
<ASSISTANT_TASK:>
Python Code:
import pandas as pd
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
matplotlib.style.use('ggplot') # Look Pretty
Explanation: DAT210x - Programming with Python for DS
Module5- Lab8
End of explanation
def drawLine(model, X_test, y_test, title):
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.scatter(X_test, y_test, c='g', marker='o')
    ax.plot(X_test, model.predict(X_test), color='orange', linewidth=1, alpha=0.7)
    print("Est 2014 " + title + " Life Expectancy: ", model.predict([[2014]])[0])
    print("Est 2030 " + title + " Life Expectancy: ", model.predict([[2030]])[0])
    print("Est 2045 " + title + " Life Expectancy: ", model.predict([[2045]])[0])
    score = model.score(X_test, y_test)
    title += " R2: " + str(score)
    ax.set_title(title)
    plt.show()
Explanation: A Convenience Function
This convenience method will take care of plotting your test observations, comparing them to the regression line, and displaying the R2 coefficient
End of explanation
# .. your code here ..
Explanation: The Assignment
Load up the data here into a variable called X. As usual, do a .describe and a print of your dataset and compare it to the dataset loaded in a text file or in a spread sheet application:
End of explanation
# .. your code here ..
Explanation: Create your linear regression model here and store it in a variable called model. Don't actually train or do anything else with it yet:
End of explanation
# .. your code here ..
Explanation: Slice out your data manually (e.g. don't use train_test_split, but actually do the indexing yourself. Set X_train to be year values LESS than 1986, and y_train to be corresponding 'WhiteMale' age values. You might also want to read the note about slicing on the bottom of this document before proceeding:
End of explanation
# .. your code here ..
Explanation: Train your model then pass it into drawLine with your training set and labels. You can title it 'WhiteMale'. drawLine will output to the console a 2014 extrapolation / approximation for what it believes the WhiteMale's life expectancy in the U.S. will be... given the pre-1986 data you trained it with. It'll also produce a 2030 and 2045 extrapolation:
End of explanation
# .. your code here ..
Explanation: Print the actual 2014 'WhiteMale' life expectancy from your loaded dataset
End of explanation
# .. your code here .. 
Explanation: Repeat the process, but instead of for WhiteMale, this time select BlackFemale. Create a slice for BlackFemales, fit your model, and then call drawLine. Lastly, print out the actual 2014 BlackFemale life expectancy:
End of explanation
# .. your code here ..
plt.show()
Explanation: Lastly, print out a correlation matrix for your entire dataset, and display a visualization of the correlation matrix, just as we described in the visualization section of the course:
End of explanation
<END_TASK>