본문 바로가기
머신러닝 딥러닝

0901 Classification

by 대금부는개발자 2021. 9. 1.
SMALL

Machine Learning model이 어떤 값을 예측하는가?

1. Regresiio(회귀) - 연속적인 값(continuous value)

2. classification(분류) - 둘 중 하나 이진 분류(discrete value)

 

Linear Regression을 확장해서 Classification Model을 만들어 볼 거예요!

 

로지스틱 회귀 (Logistic regression) - 분류 문제를 해결해요.

Logistic regression은 초창기 인공지능 알고리즘 퍼셉트론(Perceptron)을 발전시킨 개념

 

퍼셉트론(Perceptron) - 사람의 뇌구조 신경세포(Neuron)를 따서 만들었어요.

 

로지스틱 회귀 (Logistic regression)의 개념도 → 기본은  Binary Classification, 확장하면 Multinomial Classification

 

 

 

E-mail 스팸 판별

주식, 채권 ↑ ↓

MRI, CT 의료용 사진을 이용한 병의 여부

신용카드 사용 시 정산적인 결제인지 도난카드 결제인지에 대한 여부

 

Sigmoid를 activation function으로 사용할 경우 0과 1 사이의 실수로 나와요!

임계 함수(threshold

if a>= 0.5 → 1

else → 0

 

코드적으로 살펴보아요!

 

# Logistic regression을 다른 관점에서 한번 살펴보아요!
# 사용하는 Data Set은 mglearn이라는 module에서 가져다가 사용할 거예요

mglearn설치
#pip install mglearn

import numpy as pd
from sklearn import linear_model
import mglearn
import matplotlib.pyplot as plt
import warnings # 경고 메시지 출력을 하지 않기 위해 import

warnings.filterwarnings(action='ignore') # warning이 출력되지 않아요!

#Traninig Data Set 
# 내부적으로 가지고 있는 data들 중에 특정 데이터를 가져다가 x, y에 집어넣어 줘요
x,y = mglearn.datasets.make_forge()  # x는 2차원 ndarray 2개의 column이 있어요. 
# 0번째 column이 x좌표, 1번째 column이 y좌표
print(x) 

[[ 9.96346605  4.59676542] #1
 [11.0329545  -0.16816717] #0
 [11.54155807  5.21116083] #1

...
 [ 9.15072323  5.49832246] #1
 [11.563957    1.3389402 ]] # 0

 


print(y) # [1 0 1 0 0 1 1 0 1 1 1 1 0 0 1 1 1 0 0 1 0 0 0 0 1 0]

#행의 수와 열의 수와 같아요!→ x데이터로 표현되는 2차원 평면상의 점들이 각각 어떤 값을 가지는지 알려주는 데이터

mglearn.discrete_scatter(x[:,0], x[:,1], y)  #x축, y축, 점의 위치 y인자를 세게 넣을 수 있어요

model = linear_model.LinearRegression()  # Linear Regression Model 생성
model.fit(x[:,0].reshape(-1,1), x[:,1].reshape(-1,1))
print(model.coef_, model.intercept_)   #  # W 기울기와 b 절편[[-0.17382295]] [4.5982984]

plt.plot(x[:,0], x[:,0]*model.coef_.ravel() + model.intercept_, color='r')
plt.show()

 

 

 

 

LIST

'머신러닝 딥러닝' 카테고리의 다른 글

0902 분류성능평가지표(Metric)  (0) 2021.09.02
0902 Logistic Regression Model  (0) 2021.09.02
0901 TensorFlow  (0) 2021.09.01
0831 MultipleLlinear Regression  (0) 2021.08.31
0831 정규화(Normalization)  (0) 2021.08.31

댓글