# ▣ 빅데이터 분석 기사 실기 유형2번 코드 암기하기(분류 파트)
# ■ 시험환경 만들기1. sklearn 에서 유방암 환자 데이터 불러오기
import pandas as pd from sklearn.datasets import load_breast_cancer brst = load_breast_cancer() x, y = brst.data, brst.target
col = brst.feature_names # 컬럼명 불러오기 X = pd.DataFrame(x , columns=col) # 학습 데이터 y = pd.DataFrame(y, columns=['cancer']) # 정답 데이터
# cust_id 컬럼을 추가합니다. X.insert(0, 'cust_id', range(1, 1 + len(X))) # X.insert(컬럼자리번호, 컬럼명, 데이터 )
# ■ 시험환경 만들기2. 훈련 데이터와 테스트 데이터를 생성합니다.
# 훈련 데이터와 테스트 데이터를 분리합니다. from sklearn.model_selection import train_test_split x_train, x_test, y_train, y_test = train_test_split(X, y,test_size=0.2, random_state=1)
# 만든 데이터를 시험환경에 저장합니다. x_train.to_csv("X_train.csv", index=False) y_train.to_csv("y_train.csv", index=False) x_test.to_csv("X_test.csv", index=False) |