파이썬/머신러닝-지도학습
파이썬 머신러닝 데이터 정규화
큰고양2
2023. 9. 21. 15:09
https://bigcat5312.tistory.com/80
파이썬 머신러닝 지도학습 - 데이터 분리 (sklearn - train_test_split
import from sklearn.model_selection import train_test_split train_test_split 데이터를 머신러닝에 사용하기 위해서 학습 데이터와 테스트 데이터를 무작위로 분리하는 함수로 train_test_split(x , y, test_size = or train_siz
bigcat5312.tistory.com
코드를 사용하여 x_train , x_test를 가지고 있는 상태로
학습시킬 데이터인 x_train을 기준으로 정규화를 진행한다
정규화 공식은 (x - xmin ) / (xmax -xmin)이다
x_min = x_train.min()
x_max = x_train.max()
x_train = (x_train - x_min) / (x_max - x_min)
x_test = (x_test - x_min) / (x_max - x_min)
으로 직접 구해도 되고
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
scaler.fit(x_train)
x_train = scaler.transform(x_train)
x_test = scaler.transform(x_test)
MinMaxScaler 함수를 사용해도 된다