본문 바로가기
CS(Computer Science)/인공지능

8. 사이킷런 경사하강법

by 동욷 2023. 3. 19.

사이킷런 (sklearn.linear_model)에서 제공하는 경사하강법 모듈

from sklearn.linear_model import SGDClassifier
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
import numpy as np
import matplotlib.pyplot as plt

cancer = load_breast_cancer()
x = cancer.data
y = cancer.target

x_train, x_test, y_train, y_test = train_test_split(x,y,stratify=y, test_size=0.2, random_state=42)
np.unique(y_train, return_counts=True)

sgd = SGDClassifier(loss='log_loss', max_iter = 100, tol=1e-3, random_state=42)
sgd.fit(x_train, y_train)
print(sgd.score(x_train,y_train))

sgd.predict(x_test[0:10])

 

정확도

0.8813186813186813 => 약 88.1%의 정확도 보유

728x90

'CS(Computer Science) > 인공지능' 카테고리의 다른 글

9. 과대적합, 과소적합, 규제, 교차 검증  (0) 2023.03.19
7. 단일층 신경망  (0) 2023.03.19
6. 로지스틱 회귀  (0) 2023.03.19
5. 뉴런 생성 & 시그모이드 함수  (0) 2023.03.18
4. 경사하강법  (0) 2023.03.18