\ [Hands-On]데이터 전처리 템플릿 :: Something New
728x90
반응형

Importing the libraries

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

Data.csv(데이터 샘플)

나이 예상급여 차 구입 여부
20 30000000 0
33 40000000 0
28 58000000 1

 

예를 들면 나이, 예상급여를 보고 차를 살지 안 살지를 예측해봄(0이면 구매않음을 예상 1이면 구매예상)

 

Importing the dataset

여기서 쓰인 데이터는 첫번째, 두 번째 열로 세 번째 열을 판단하는 데이터

dataset = pd.read_csv{'Data.csv'}
X= dataset.iloc[:,:-1].values
y = dataset.iloc[:,-1].values

Splitting the dataset into the Training set and Test set

test_size 가 0.25면 데이터가 400개 있음 훈련 데이터는 300개, 테스트 데이터는 100개로 나눔

from sklearn.model_selection import trains_test_split
X_train. X_test, y_trains, y_test = train_test_split(X,y, test_size = 0.25, random_state =0)

Feature Scaling 

때에 따라 해도되고 안 해도 되지만 하면 정확도가 올라감 

from sklearn.preprocessing import StandartScaler
sc = StandardScaler
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

 

Enjoy Machine Learning!

 

본 글은 Udemy의 Machine Learning A-Z: Hands-On Python & R In Data Science 강의를 듣고

작성되었습니다.

 

728x90

+ Recent posts