오늘보다 더 나은 내일의 나에게_

비전공자의 IoT 국비 교육 수강일지 Day_88 본문

비전공자의 코딩일지

비전공자의 IoT 국비 교육 수강일지 Day_88

chan_96 2022. 4. 22. 18:14
728x90

머신러닝

기존 머신러닝과 딥러닝의 차이점

Linear Model(Regression)

=> 수치형(회귀), 범주형(분류)

경사하강법 예제

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

data = pd.DataFrame([[2,20],[4,40],[8,80],[9,90]],
                   index=['예진','해도','세연','명진'],
                   columns=['공부시간','성적'])
data

loss function(비용함수)

: 가설이 실제 데이터에 적합한지 수치화시키는 함수

- 선형회귀는 비용함수로 MSE(평균제곱오차)를 활용한다.

# h(x)
def h(w,x) : # 가설함수
    return w*x+0
h(10,1) # => 10

# MSE
def MSE(data,target,weight): # 문제,정답, 가중치
    y_pre=h(weight,data) # 예측값
    return ((y_pre - target) ** 2).mean()
    
# 시각화
weight_arr = np.linspace(0,20,50)
weight_arr

c_list = [] # MSE을 담아둘 리스트
for w in weight_arr:
    c = MSE(data['공부시간'],data['성적'],w)
    c_list.append(c)
    
plt.plot(weight_arr,c_list, marker='*') # 라인 그래프
plt.show()

 

 

728x90
Comments