- 유방암 환자 데이터를 통하여 유방암 여부를 분류
- 딥러닝을 활용하여 이진분류 딥러닝 모델 설계 및 학습
- sklearn.datasets 에서 제공하는 breast_cancer (유방암) 데이터 활용
라이브러리 불러오기
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.datasets import load_breast_cancer
데이터 불러오기 및 분리
data = load_breast_cancer()
# 문제, 정답 분리
X = data['data']
y = data['target']
# train, test split
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42, stratify=y)
# data: 입력 특성
# feature_names: 입력 특성의 실제 이름 (컬럼명)
# target: label, 정답 데이터 (인덱스 형태)
# target_names: 정답 데이터의 실제 이름
# DESCR: 데이터에 대한 설명data['target_names'] # = data.target_names
# 0 - 'malignant' : 악성 (암)
# 1 - 'benign' : 양성 (깨끗한 종양)
# 클래스가 2개 -> 이진분류 학습이 필요하다~신경모델망 설계
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Input, Dense, Activation
model = Sequential()
# input
model.add(Input(shape=(30,)))
# hidden
model.add(Dense(units=8, activation='sigmoid'))
model.add(Dense(units=16, activation='sigmoid'))
model.add(Dense(units=32, activation='sigmoid'))
# output -> 이진분류 (직선 1개 필요)
model.add(Dense(uniuts=1, activation='sigmoid'))
학습 방법 및 평가 방법 설정
model.compile(loss = 'binary_crossentropy',
optimizer = 'SGD',
metrics = ['accuracy'])
모델 학습
h1 = model.fit(X_train, y_train, validation_split=0.2, epochs=20)
결과 확인
plt.plot(h1.history['accuracy'], label = 'acc')
plt.plot(h1.history['val_accuracy'], label = 'val_acc')
plt.legend()
