이번주도 파이썬 수업을 진행했습니다. 거의 4년째 파이썬 수업을 진행하고 있는데 배움의 열기가 매번 뜨겁습니다. ^^
올해 IT업계의 화두는 단연코 클라우드라고 생각합니다. 10년 이상을 지지부진하던 MS도 최근 살아나고 있고 AWS의 세미나와 기술 열기가 장난 아닙니다. 저도 내년도 강의를 준비하면서 Azure ML Studio와 데이터 사이언스 분야를 계속 준비하고 있습니다.
아래의 코드는 파이썬을 사용하는 개발자나 데이터 사이언스들에게는 매우 익숙한 코드입니다. 100년동안의 지구의 온도에 대한 회귀 연구 데이터입니다. 작업이 끝난 결과도 제가 링크를 오픈해 두었습니다. 한번 접속하셔서 결과를 보셔도 됩니다. numpy와 scikit-learn, senborn을 사용해서 분석하고 시각화 한 결과입니다.
https://notebooks.azure.com/papasmf1/projects/climate-change
import matplotlib.pyplot as plt
import numpy as np
from sklearn.linear_model import LinearRegression
import seaborn as sns; sns.set()
yearsBase, meanBase = np.loadtxt('5-year-mean-1951-1980.csv',
delimiter=',', usecols=(0, 1), unpack=True)
years, mean = np.loadtxt('5-year-mean-1882-2014.csv', delimiter=',',
usecols=(0, 1), unpack=True)
plt.scatter(yearsBase, meanBase)
plt.title('Scatter plot of mean temp difference vs year')
plt.xlabel('years', fontsize=12)
plt.ylabel('mean temp difference', fontsize=12)
plt.show()
m, b = np.polyfit(yearsBase, meanBase, 1)
def f(x):
return m*x + b
plt.scatter(yearsBase, meanBase)
plt.plot(yearsBase, f(yearsBase))
plt.title('scatter plot of mean temp difference vs year')
plt.xlabel('years', fontsize=12)
plt.ylabel('mean temp difference', fontsize=12)
plt.show()
model = LinearRegression(fit_intercept=True)
model.fit(yearsBase[:, np.newaxis], meanBase)
mean_predicted = model.predict(yearsBase[:, np.newaxis])
plt.scatter(yearsBase, meanBase)
plt.plot(yearsBase, mean_predicted)
plt.title('scatter plot of mean temp difference vs year')
plt.xlabel('years', fontsize=12)
plt.ylabel('mean temp difference', fontsize=12)
plt.show()
print(' y = {0} * x + {1}'.format(model.coef_[0], model.intercept_))