본문 바로가기

전체 글50

K Nearest Neighbors (KNN) : 실습 목적 : 새로운 샘플에서 가장 인접한 k개 샘플의 class에 따라 현재 class 분류 0. 3개의 class가 이미 training data로 들어와 있다. 1. distance 계산 2. 상위 4개를 뽑음 3. 어떤 class가 제일 많은지 확인 → 회식class도 끼워주세영~ ▼ 패키지 선언 import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn.datasets import make_classification from sklearn.model_selection import train_test_split ▼ Dataset 생성 X, y = make_classification(n_samples=500, n_.. 2023. 12. 18.
K-Nearest Neighbor (KNN) Supervised Learning (지도학습) : Model-based Learning ● Linear/Ridge/Lasso/Elastic Regression ● Deep Learning(MLP & CNN) ● Support Vector Machine ● Desicion Tree Unsupervised Learning (비지도학습) ● KNN Method(or Algorithm) : [Memory-based Learning] or [Lazy Learning] KNN Algorithm ● 선형 vs 비선형 ● KNN 응용 1. KNN 분류 인접한 K개의 데이터로부터 Majority Voting 2. KNN 추정(예측) 인접한 K개의 데이터로부터 평균/중간값/Min/Max 중에서 택 1 KNN Algori.. 2023. 12. 18.
Entropy Entropy : Measurement for Uncertainty 불확실성의 정도를 나타내는 수치 동전의 앞면 동전의 뒷면 Calculation Entropy 50% 50% - (0.5*log0.5 + 0.5*log0.5) = 1 1 100% 0% - (1.0*log1.0 + 0.0*log0.0) = 0 0 90% 10% - (0.9*log0.9 + 0.1*log0.1) = 0.47 0.47 ex1) "내일 해가 뜬다" 의 Entropy=0 ex2) 내가 사기를 쳐서 동전의 양 면이 다 앞면일 때, Entropy=0 ● 불확실성이 높을수록 Entropy는 큰 값을 가짐 Binary Classification : 0 2023. 12. 18.
Support Vector Machine : Gradient Decent Method (GD) 목적 : Margin을 최대화하는 optimal separating hyperplane 구하기 ● Loss function 으로 Hinge loss 를 사용 ● Hinge loss 으로 Gradient 를 구해야 함 Support Vector Machine (GD Method) ▼ 패키지 선언 import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn.datasets import make_blobs ▼ Dataset 생성 X, y = make_blobs(n_samples=50, n_features=2, centers=2, cluster_std=1.05, random_state=40) plt.scatter(X[:, .. 2023. 12. 18.
Support Vector Machine : Quadratic Programming(2차 계획법) 목적 : Margin을 최대화 하는 optimal separating hyperplane 구하기 margin이 클수록 더 잘 분리시킬 수 있음 → max-margin을 구해야 함 → max margin classifier ▶ Support Vector Machine (SVM) support vector들이 SVM의 train data이다. slab variable : 허용치를 조금 더 주는 것 optimal separating hyperplane으로부터 support vector 까지의 거리를 알아야 함 인데, 가장 간단한 1과 -1로 rescaling 함 2023. 12. 18.
MNIST Classification using SLP, MLP Perceptron 을 이용한 MNIST 손글씨 데이터셋 분류 MNIST Datebase (Modified National Institute of Standards and Technology) - 손으로 쓴 숫자들로 이루어진 대형 데이터베이스 - Train dataset 60,000개, Test dataset 10,000개로 구성됨 1. Single Layer Perceptron (SLP) 실습 목표 : MNIST 손글씨 데이터를 분류하는 single layer(단층) perceptron 모델 학습 입력 : 손글씨 이미지 (28x28x1) 출력 : 0~9까지 숫자들의 정답 확률 ▼ 패키지 선언 import torch import torch.nn as nn import torchvision.datasets.. 2023. 12. 17.