import pandas as pd
import numpy as np
Getting datas from cleaned folder
changes = pd.read_csv("./data/cleaned/changes.csv", header = 0)
immg = pd.read_csv("./data/cleaned/immg.csv", header = 0)
black = pd.read_csv("./data/cleaned/black.csv", header = 0)
white = pd.read_csv("./data/cleaned/white.csv", header = 0)
high_edu = pd.read_csv("./data/cleaned/high_edu.csv", header = 0)
low_edu = pd.read_csv("./data/cleaned/low_edu.csv", header = 0)
un_rate = pd.read_csv("./data/cleaned/un_rate.csv", header = 0)
Correlations between each variables with immigration grouth.
Including:
* Correlation between Immigration Growth and the Unemployment Rate growth of native
* Correlation between Immigration Growth and the Unemployment Rate Growth of Afican American
* Correlation between Immigration Growth and the Unemployment Rate Growth of White
* Correlation between Immigration Growth and the Unemployment Rate Growth of US Citizens with High Education Level
* Correlation between Immigration Growth and the Unemployment Rate Growth of US Citizens with Low Education Level
data = [['Native', un_rate], ['African American', black], ['White', white], ['US Citizens with High Education Level', high_edu], ['US Citizens with Low Education Level', low_edu]]
immg['Growth'] = immg['2010'] - immg['2000']
for indivial_group in data:
name, group = indivial_group[0], indivial_group[1]
group['Growth'] = group['2010'] - group['2000']
indivial_group.append(immg['Growth'].corr(group['Growth']))
corr = indivial_group[2]
print "Correlation between Immigration Growth and the Unemployment Rate Growth of " + name + ": "
print corr
Correlation between Immigration Growth and the Unemployment Rate Growth of Native: 0.301573591924 Correlation between Immigration Growth and the Unemployment Rate Growth of African American: 0.093822335801 Correlation between Immigration Growth and the Unemployment Rate Growth of White: 0.34570144212 Correlation between Immigration Growth and the Unemployment Rate Growth of US Citizens with High Education Level: 0.362991288287 Correlation between Immigration Growth and the Unemployment Rate Growth of US Citizens with Low Education Level: 0.346589794559
Showing the histogram of correlations of each variables.
import matplotlib.pyplot as plt
from matplotlib.pyplot import plot,savefig
N = 5
correlations = [group[2] for group in data]
ind = np.arange(N)
width = 0.5
fig, ax = plt.subplots()
rects = ax.bar(ind, correlations, width, color='b')
ax.set_ylabel('Correlations')
ax.set_title('Correlations for different variables')
ax.set_xticks(ind+width/2)
ax.set_xticklabels(('Native', 'African American', 'White', 'High Education', 'Low Education'))
def autolabel(rects):
for rect in rects:
height = rect.get_height()
autolabel(rects)
savefig('./visualizations/Correlation.png')
plt.show()
def regression_y(x, y):
coefficients = numpy.polyfit(x, y, 1)
polynomial = numpy.poly1d(coefficients)
ys = polynomial(immg['Growth'])
return ys
Immigration Growth and the Unemployment Rate Growth of Native
i = 0
name, group, corr, r2 = data[i][0], data[i][1], data[i][2], (data[i][2])**2
x, y = immg['Growth'], group['Growth']
fig = plt.figure()
plt.scatter(x, y)
plot(x, regression_y(x, y))
fig.suptitle(name + " (corr = " + str(corr.round(3)) + ", R^2 = " + str(r2.round(3)) + ")", fontsize=14)
plt.xlabel('Immigration Growth', fontsize=14)
plt.ylabel('Unemployment Rate Growth of '+name, fontsize=14)
savefig("./visualizations/" + name)
i += 1
Immigration Growth and the Unemployment rat Growth of African American
name, group, corr, r2 = data[i][0], data[i][1], data[i][2], (data[i][2])**2
x, y = immg['Growth'], group['Growth']
fig = plt.figure()
plt.scatter(x, y)
plot(x, regression_y(x, y))
fig.suptitle(name + " (corr = " + str(corr.round(4)) + ", R^2 = " + str(r2.round(4)) + ")", fontsize=14)
plt.xlabel('Immigration Growth', fontsize=14)
plt.ylabel('Unemployment Rate Growth of '+name, fontsize=14)
savefig("./visualizations/" + name)
i += 1
Immigration Growth and the Unemployment Rate Growth of White
name, group, corr, r2 = data[i][0], data[i][1], data[i][2], (data[i][2])**2
x, y = immg['Growth'], group['Growth']
fig = plt.figure()
plt.scatter(x, y)
plot(x, regression_y(x, y))
fig.suptitle(name + " (corr = " + str(corr.round(3)) + ", R^2 = " + str(r2.round(3)) + ")", fontsize=14)
plt.xlabel('Immigration Growth', fontsize=14)
plt.ylabel('Unemployment Rate Growth of '+name, fontsize=14)
savefig("./visualizations/" + name)
i += 1
Immigration Growth and the Unemployment Rate Growth of the United Stats Citizens with High Education level
name, group, corr, r2 = data[i][0], data[i][1], data[i][2], (data[i][2])**2
x, y = immg['Growth'], group['Growth']
fig = plt.figure()
plt.scatter(x, y)
plot(x, regression_y(x, y))
fig.suptitle(name + " (corr = " + str(corr.round(3)) + ", R^2 = " + str(r2.round(3)) + ")", fontsize=14)
plt.xlabel('Immigration Growth', fontsize=14)
plt.ylabel('Unemployment Rate Growth of '+name, fontsize=14)
savefig("./visualizations/" + name)
i += 1
Immigration Growth and the Unemployment Rate Growth of the United States Citizens with Low Education Level
name, group, corr, r2 = data[i][0], data[i][1], data[i][2], (data[i][2])**2
x, y = immg['Growth'], group['Growth']
fig = plt.figure()
plt.scatter(x, y)
plot(x, regression_y(x, y))
fig.suptitle(name + " (corr = " + str(corr.round(3)) + ", R^2 = " + str(r2.round(3)) + ")", fontsize=14)
plt.xlabel('Immigration Growth', fontsize=14)
plt.ylabel('Unemployment Rate Growth of '+name, fontsize=14)
savefig("./visualizations/" + name)
i += 1
fig = plt.figure()
pd.scatter_matrix(changes, figsize=(35, 35))
savefig('./visualizations/Changes.png')
<matplotlib.figure.Figure at 0x10c192f10>
List the team members contributing to this notebook, along with their responsabilities: