CodeOnWeb
로그인

Linear Regression 05

오 태호 2018/09/07, 19:00

내용

AI PM 강의 (49)

Python 환경 만들기 Python 기초 실습 Python 기초 요약 Python 활용 실습 Python 활용 요약 Linear Regression 01 Linear Regression 02 Linear Regression 03 Linear Regression 04 Linear Regression 05 Linear Regression 06 Linear Regression 요약 Logistic Regression 01 Logistic Regression 02 Logistic Regression 03 Logistic Regression 04 Logistic Regression 05 Logistic Regression 요약 추천 시스템 실습 - 내용 기반 추천 추천 시스템 실습 - 협업 필터링1 추천 시스템 실습 - 협업 필터링2 TMDB API키 만들기 추천 시스템 요약 ML 방법론 및 결과 해석 실습 - 데이터셋 나누기 ML 방법론 및 결과 해석 실습 - Skewed Classes ML 방법론 및 결과 해석 실습 - Precision/Recall ML 방법론 및 결과 해석 실습 - Down/Up Sampling ML 방법론 및 결과 해석 요약 Neural Network 01 Neural Network 02 Neural Network 03 Neural Network 04 Neural Network 요약 Convolutional Neural Network 01 Convolutional Neural Network 02 Convolutional Neural Network 03 Convolutional Neural Network 04 Convolutional Neural Network 05 Convolutional Neural Network 06 Convolutional Neural Network 요약 ML as a Service (MLaaS)

AI PM 강의 V1

Boston Housing Dataset에서 Tensorflow를 사용하여 집값을 추정해 봅니다.

  • 필요한 package들을 import합니다.

  • 집의 data를 읽어옵니다.

  • 집의 data의 내용을 살펴봅니다.

정답SHOW

  • 집 주변의 정보, 집의 가격을 넣어줄 placeholder를 x_input, y_input에 저장합니다.
    • $ x\_input= \begin{pmatrix} x_1^{(1)} & x_2^{(1)} & \cdots & x_{13}^{(1)} \\ x_1^{(2)} & x_2^{(2)} & \cdots & x_{13}^{(2)} \\ \vdots & \vdots & \ddots & \vdots \\ x_1^{(m)} & x_2^{(m)} & \cdots & x_{13}^{(m)} \end{pmatrix} $
    • $ y\_input= \begin{pmatrix} y^{(1)} \\ y^{(2)} \\ \vdots \\ y^{(m)} \end{pmatrix} $

  • 계산도중에 사용할 variable을 만들어서 theta0_var, thetan_var에 저장합니다.
    • $ theta0\_var= \begin{pmatrix} \theta_0 \end{pmatrix} $
    • $ thetan\_var= \begin{pmatrix} \theta_1 \\ \theta_2 \\ \vdots \\ \theta_{13} \\ \end{pmatrix} $

  • 집의 추정 가격의 계산과정을 정의합니다.
    • $ h_\theta(x_1,x_2,\cdots,x_{13})=\theta_0+\theta_1x_1+\theta_2x_2+\cdots+\theta_{13}x_{13} =\theta_0+ \begin{pmatrix} x_1 & x_2 & \cdots & x_{13} \end{pmatrix} \begin{pmatrix} \theta_1 \\ \theta_2 \\ \vdots \\ \theta_{13} \end{pmatrix} $
    • $ y\_output= \begin{pmatrix} h_{\theta}(x_1^{(1)},x_2^{(1)},\cdots,x_{13}^{(1)}) \\ h_{\theta}(x_1^{(2)},x_2^{(2)},\cdots,x_{13}^{(2)}) \\ \vdots \\ h_{\theta}(x_1^{(m)},x_2^{(m)},\cdots,x_{13}^{(m)}) \\ \end{pmatrix} = \begin{pmatrix} \theta_0 \\ \theta_0 \\ \vdots \\ \theta_0 \end{pmatrix} + \begin{pmatrix} x_1^{(1)} & x_2^{(1)} & \cdots & x_{13}^{(1)} \\ x_1^{(2)} & x_2^{(2)} & \cdots & x_{13}^{(2)} \\ \vdots & \vdots & \ddots & \vdots \\ x_1^{(m)} & x_2^{(m)} & \cdots & x_{13}^{(m)} \end{pmatrix} \begin{pmatrix} \theta_1 \\ \theta_2 \\ \vdots \\ \theta_{13} \end{pmatrix} $

  • cost의 계산과정을 정의합니다.
    • $J(\theta_0,\theta_1,\cdots,\theta_{13})=\frac{1}{m}\sum_{i=1}^{m}(h_\theta(x_1^{(i)},x_2^{(i)},\cdots,x_{13}^{(i)})-y^{(i)})^{2}$
    • $h_\theta(x_1,x_2,\cdots,x_{13} )=\theta_0+\theta_1x_1+\theta_2x_2+\cdots+\theta_{13}x_{13}$
    • $ (y\_output-y\_input)^2= \begin{pmatrix} (h_{\theta}(x_1^{(1)},x_2^{(1)},\cdots,x_{13}^{(1)}) - y^{(1)})^2 \\ (h_{\theta}(x_1^{(2)},x_2^{(2)},\cdots,x_{13}^{(2)}) - y^{(2)})^2 \\ \vdots \\ (h_{\theta}(x_1^{(m)},x_2^{(m)},\cdots,x_{13}^{(m)}) - y^{(m)})^2 \end{pmatrix} $

  • cost를 최소화시키는 operation을 AdamOptimizer으로 정의하여 train_step에 저장합니다.

  • x_input, y_input, theta0_var, thetan_var, y_output, cost_output, train_step을 print로 출력해 봅니다. 모두 값이 보이지 않는 알아보기 힘든 결과가 출력됩니다.

  • Tensorflow Session을 open합니다.

  • theta0, thetan, cost를 초기화합니다.

  • Gradient Descent를 사용하여 cost가 가장 작아지는 $\theta$값들을 찾습니다.

  • $\theta$값들을 theta0, thetan에 저장하고, cost를 cost에 저장하고, 추정된 집 가격을 y_pred에 저장합니다.

  • 학습된 $\theta$값들을 출력하고 cost를 출력합니다.

  • 집의 가격과 집의 추정 가격을 그래프로 그립니다.

  • Tensorflow Session을 close합니다.


867 읽음
이전 Linear Regression 04
다음 Linear Regression 06

저자

토론이 없습니다

Please log in to leave a comment

16.5.11618.20190612.allo
문제 보고 · 사용조건 · 개인정보보호
래블업 주식회사 · 대한민국 서울 테헤란로 145 · 대표: 신정규 · 사업자번호: 864-88-00080 · +82 70-8200-2587

거절 확인

닫기
좋아요 책갈피 토론

아래 주소를 복사하세요