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
'Machine Learning' 카테고리의 다른 글
SVM Support Vector Machine (0) | 2021.11.25 |
---|---|
Training the K-NN model by Python (0) | 2021.11.23 |
Logistic Regression 로지스틱 회귀 with python (0) | 2021.11.22 |
[머신러닝][사이킷런]k-최근접 알고리즘 KNeighborsClassifier (0) | 2021.02.12 |