ed-kyu
ee
ed-kyu
전체 방문자
오늘
어제
  • 분류 전체보기 (26)
    • 딥러닝, 머신러닝 (17)
      • NLP (0)
      • Vision (0)
      • 모두를 위한 딥러닝 강의 복습 (9)
      • Andrew Ng 강의 (0)
      • 캐글 (1)
      • 수학 (0)
      • DL Basic (5)
      • 논문 스터디 (2)
      • Product Serving (0)
    • TIL (1)
      • OS (0)
      • Network (0)
      • DB (0)
      • Docker (0)
      • Data Engineering (1)
    • 알고리즘 문제풀이 (3)
      • Baekjoon Algorithm (3)
      • Programmers (0)
    • 주제 없음 (5)
      • Python (2)
      • 기록 (1)
      • etc (2)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • ml
  • 유기농 배추
  • 백준
  • Kaggle
  • Python
  • 오블완
  • 1012
  • 티스토리챌린지
  • DeepLearningZeroToAll

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
ed-kyu

ee

Linear Regression의 cost 최소화 알고리즘의 원리
딥러닝, 머신러닝/모두를 위한 딥러닝 강의 복습

Linear Regression의 cost 최소화 알고리즘의 원리

2022. 1. 4. 17:46

모두를 위한 딥러닝 강의 시즌1을 듣고 복습한 내용입니다.

cost가 최소화되는 W를 찾는 것!

 

Gradient descent algorithm (경사하강법)

- Minimize cost function

- minimization 문제에 자주 사용되었음

- w1, w2, w3... 여러 개 값이 있을 때도 사용 가능

- 경사도를 따라서 1 step 이동 -> 미분을 사용해서 경사를 구할 수 있음

 

2m으로 나눈 것은 미분한 결과가 깔끔하게 나오도록 설정한 것

 

미분 최종 결과

 

 

Convex function

- 어느 점에 시작해도 항상 최솟값을 찾을 수 있음

 

 


텐서플로우 코드 (버전 2.0 이상)

 

import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt

x_train = [1, 2, 3, 4]
y_train = [0, -1, -2, -3]

tf.model = tf.keras.Sequential()
tf.model.add(tf.keras.layers.Dense(units=1, input_dim=1))

sgd = tf.keras.optimizers.SGD(lr=0.1)
tf.model.compile(loss='mse', optimizer=sgd) # 평균 제곱 오차

tf.model.summary()

# fit() trains the model and returns history of train
history = tf.model.fit(x_train, y_train, epochs=100)

y_predict = tf.model.predict(np.array([5, 4]))
print(y_predict)

# Plot training & validation loss values
plt.plot(history.history['loss'])
plt.title('Model loss')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.legend(['Train', 'Test'], loc='upper left')
plt.show()

 

'딥러닝, 머신러닝 > 모두를 위한 딥러닝 강의 복습' 카테고리의 다른 글

Logistic Classification, Logistic Regression의 cost 함수  (0) 2022.01.05
TensorFlow로 파일에서 데이터 읽어오기  (0) 2022.01.04
Multi-variable linear regression  (0) 2022.01.04
Linear Regression  (0) 2022.01.04
기본적인 Machine Learning 의 용어와 개념 설명  (0) 2022.01.04
    '딥러닝, 머신러닝/모두를 위한 딥러닝 강의 복습' 카테고리의 다른 글
    • TensorFlow로 파일에서 데이터 읽어오기
    • Multi-variable linear regression
    • Linear Regression
    • 기본적인 Machine Learning 의 용어와 개념 설명
    ed-kyu
    ed-kyu

    티스토리툴바