AI/DeepLearning

딥러닝 - 로지스틱 회귀(Logistic Regression)

oaho 2023. 3. 1. 03:21
반응형

 

로지스틱 회귀

 
 

머신러닝 로지스틱 회귀 개념을 다룰 때 ‘로지스틱 회귀’에 대한 개념 설명을 자세하게 설명했다.
 

 

로지스틱 회귀 개념, 모델링 과정

Logistic Regression 확률 문제를 선형회귀로 모델링 입력 : x = np.array([10, 20, 30, 40, 50, 60, 70, 80, 90, 100]).reshape(-1, 1) y = np.array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1]).reshape(-1, 1) model = LinearRegression() model.fit(x,y) y_hat = x*m

oaho.tistory.com

 
 


breast_cancer 데이터 사용 
target값 = 0 or 1    => 로지스틱 회귀 문제
 
 

입력:

x.shape, y.shape
 
출력:
 
 
=> 변수 개수 : 30개
 
 
 
 
1. x, y 분리
from sklearn.model_selection import train_test_split

x_train, x_test, y_train, y_test =\
    train_test_split(x, y, test_size=0.2, random_state=2023)
 
 

2. 라이브러리 불러오기

import tensorflow as tf
from tensorflow import keras

 
 
3. 모델링 : Sequential API ⭐
activation = 'sigmoid'
loss='binary_crossentropy'

#1. 세션 클리어
keras.backend.clear_session()

#2. 모델 선언
model = keras.models.Sequential()

#3. 레이어 조립
model.add(keras.layers.Input(shape=(30, )))
model.add(keras.layers.Dense(1, activation='sigmoid'))

#4. 컴파일
model.compile(loss='binary_crossentropy', metrics=['accuracy'],
              optimizer='adam')

 

 
4. 모델 학습

model.fit(x_train, y_train, epochs=10, verbose=1

=> 출력:

 
 
5. 모델 예측

y_pred = model.predict(x_test)

 

반응형