import matplotlib.pylab as plt
import seaborn as sns
import numpy as np
import pandas as pd
penguins = sns.load_dataset('penguins')
penguins
penguins = penguins.dropna().reset_index(drop=True)
penguins
MinMaxScaler로 정규화
수치들을 0 ~ 1로 바꿔준다.
정규화 참고
https://beneagain.tistory.com/183
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
features = penguins[['bill_length_mm','bill_depth_mm','flipper_length_mm','body_mass_g']]
features_normed = scaler.fit_transform(features)
penguins = penguins.assign(bill_length_mm = features_normed[:, 0],
bill_depth_mm = features_normed[:, 1],
flipper_length_mm = features_normed[:, 2],
body_mass_g = features_normed[:, 3])
penguins
from sklearn.preprocessing import LabelEncoder
encoder = LabelEncoder()
features = penguins[['species', 'island', 'sex']]
encoded = features.apply(encoder.fit_transform)
penguins = penguins.assign(species = encoded['species'],
island = encoded['island'],
sex = encoded['sex'])
penguins
from sklearn.model_selection import train_test_split
X = penguins.drop('sex', axis=1)
Y = penguins['sex']
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, shuffle=True)
'파이썬. 머신러닝 > sklearn' 카테고리의 다른 글
로지스틱 회귀, K-최근접 이웃 분류기 (0) | 2024.10.13 |
---|---|
로지스틱 회귀 설명 영상 (0) | 2024.10.12 |
데이터 인코딩 LabelEncoder(), fit, transform (0) | 2024.09.21 |
train_test_split에서 stratify 역할 (0) | 2024.09.21 |
R2_score (0) | 2024.08.16 |