모델 학습

엔드 투 엔드 Machine Learning

Joshua Stapleton

Machine Learning Engineer

오컴의 면도날

  • 가장 단순한 만족스러운 설명이 최선
  • 모델 선택 시 단순한 모델 선호

오컴의 면도날 원리를 보여주는 예시 그림

엔드 투 엔드 Machine Learning

모델링 옵션

로지스틱 회귀

  • 클래스 간 결정 경계 탐색
  • sklearn.linear_model.LogisticRegression

서포트 벡터 분류기

  • 클래스를 분리하는 초평면 탐색
  • sklearn.svm.SVC

의사결정나무

  • 간단한 ‘규칙’으로 분류
  • sklearn.tree.DecisionTreeClassifier

랜덤 포레스트

  • 여러 결정나무를 결합
  • sklearn.ensemble.RandomForestClassifier
엔드 투 엔드 Machine Learning

기타 모델

딥러닝 모델

  • 신경망
  • 합성곱 신경망
  • 생성 사전학습 변환기(GPT)

K-최근접 이웃(KNN)

  • 지도학습 알고리즘

XGBoost

엔드 투 엔드 Machine Learning

학습 원칙

모델:

  • 정제·특성 처리된 데이터셋 사용
  • 학습 데이터의 패턴 학습
  • 심장병 진단 타깃 예측 목표

원칙:

  • 훈련셋 밖의 데이터에 일반화해야 함
  • 일부 데이터를 홀드아웃하여 학습 후 평가
  • 훈련/테스트 분할은 보통 70/30 또는 80/20
  • sklearn.model_selection.train_test_split 사용 가능
엔드 투 엔드 Machine Learning

모델 학습하기

# Importing necessary libraries
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression

# Split the data into training and testing sets (80:20) X_train, X_test, y_train, y_test = train_test_split(features, heart_disease_y, test_size=0.2, random_state=42)
# Define the models logistic_model = LogisticRegression(max_iter=200)
# Train the model logistic_model.fit(X_train, y_train)
엔드 투 엔드 Machine Learning

모델 예측 얻기

# Jane Doe's health data, for example: [age, cholesterol level, blood pressure, etc.]
jane_doe_data = [45, 230, 120, ...]

# Reshape the data to 2D, because scikit-learn expects a 2D array-like input jane_doe_data = jane_doe_data.reshape(1, -1)
# Use the model to predict Jane's heart disease diagnosis probabilities jane_doe_probabilities = logistic_model.predict_proba(jane_doe_data) jane_doe_prediction = logistic_model.predict(jane_doe_data)
엔드 투 엔드 Machine Learning

모델 예측 얻기 (계속)

# Print the probabilities
print(f"Jane Doe's predicted probabilities: {jane_doe_probabilities[0]}")
print(f"Jane Doe's predicted health condition: {jane_doe_prediction[0]}")
Jane Doe's predicted health condition probabilities: [0.2 0.8]

Jane Doe's predicted health condition: 1
엔드 투 엔드 Machine Learning

Ayo berlatih!

엔드 투 엔드 Machine Learning

Preparing Video For Download...