메뉴 건너뛰기

목록
2023.03.24 23:17

씨발

profile
조회 수 39 댓글 0 예스잼 0 노잼 0

No Attached Image

import pandas as pd

import matplotlib.pyplot as plt

import numpy as np

import seaborn as sns

train = pd.read_csv('train.csv')

test = pd.read_csv('test.csv')

 

#DataFrame 열 삭제 

train = train.drop(['intensity'], axis =1)

 

def feature_change(train):

    # type

    train['type'] = train['type'].map({'white': 0, 'red' : 1})

    

    #sweetness

    train['sweetness'] = train['sweetness'].map({'dry': 0, 'off-dry' : 1, 'medium-sweet' : 2})

    return train

 

train = feature_change(train)

train.info()

train.isnull().sum()

 

train = train.rename(columns={'volatile acidity':'VA'})

train = train.rename(columns={'fixed acidity':'FA'})

train = train.rename(columns={'free sulfur dioxide':'FSD'})

train = train.rename(columns={'total sulfur dioxide':'TSD'})

train = train.rename(columns={'citric acid':'CA'})

------------------------------

 

import os

import pandas as pd

import matplotlib.pyplot as plt

import seaborn as sns

 

 

train = pd.read_csv('train.csv')

 

#DataFrame 열 삭제 

train = train.drop(['intensity'], axis =1)

 

def feature_change(train):

    # type

    train['type'] = train['type'].map({'white': 0, 'red' : 1})

    

    #sweetness

    train['sweetness'] = train['sweetness'].map({'dry': 0, 'off-dry' : 1, 'medium-sweet' : 2})

    return train

 

# sweetness 가 꼭 필요한가?

# 와인 색도 꼭 필요함?

# intensity도 NaN이라 그냥 다 지웠는데...

# object는 다 없애버려도 그만아닐까 

 

 

train = feature_change(train)

train.info()

train.isnull().sum()

 

# 의사결정나무로 1차제출

 

from sklearn import model_selection

from sklearn.tree import DecisionTreeClassifier

from sklearn import metrics

 

print(train.shape)

print(train.describe())

 

 

print(train.iloc[:,-1].value_counts())

 

x_data = train.iloc[:,:-1]

y_data = train.iloc[:,-1]

print(x_data.shape) 

print(y_data.shape) 

x_data = x_data.values

y_data = y_data.values

 

x_train, x_test, y_train, y_test = model_selection.train_test_split(x_data, y_data, test_size=0.32)

 

estimator = DecisionTreeClassifier(criterion='gini', max_depth=None, max_leaf_nodes=None, min_samples_split=2, min_samples_leaf=1, max_features=None)

 

estimator.fit(x_train, y_train)

 

y_predict = estimator.predict(x_train) 

score = metrics.accuracy_score(y_train, y_predict)

print(score) 

 

y_predict = estimator.predict(x_test) 

score = metrics.accuracy_score(y_test, y_predict)

print(score)

---------------------------------------------------------------------------------

 

Q) 어떤 경우가 Data leakage에 해당되나요?

: Test 데이터셋은 기본적으로 '아예 볼 수 없다' 라는 가정 하에 진행해야 합니다.

  • label encoding, one-hot encoding 시 test 데이터 셋 활용하여 encoder를 fit하는 경우
  • data scaling 적용 시 test 데이터 셋 활용하여 scaler를 fit하는 경우
  • pandas의 get_dummies() 함수를 test 데이터셋에 적용하는 경우
  • test 데이터 셋의 결측치 처리 시 test 데이터 셋의 통계 값 활용
  • test 데이터 셋을 EDA하여 얻은 인사이트를 통해 학습에 활용하는 경우
  • test 데이터 셋을 학습 과정에 사용하는 모든 행위 (test 데이터셋은 추론에만 활용되어야 합니다)
  • test 데이터 셋의 데이터 개수 정보를 활용하는 경우 (실제 test 데이터셋은 몇개가 입력으로 들어올 지 모르기 때문)
  • 위 예시 외에도 test 데이터 셋이 모델 학습에 활용되는 경우에 Data leakage에 해당됨.

 

 

 

 

 

 

List of Articles
번호 제목 글쓴이 날짜 조회 수 추천
공지 수용소닷컴 이용약관 file asuka 2020.05.16 3863 1
1163 요즘 하는거 또치면과락 2024.11.08 631 0
1162 삭제된 게시글입니다. 반딧불 2024.10.27 557 0
1161 안테나를 만든다 1 무메이 2024.10.23 551 0
1160 센토스 지우고 오픈수세 까랏다 3 file 반딧불 2024.09.17 666 0
1159 잠깐 다른 거 먼저 만져봐야겠다 file 美樹さやか 2024.09.10 867 0
1158 시1발 1 또치면과락 2024.09.10 641 0
1157 차이 좀 있긴 하네 file 美樹さやか 2024.09.09 626 0
1156 어제 만든거 file 美樹さやか 2024.09.09 496 0
1155 슬슬 단축키들 외워야겠다 file 美樹さやか 2024.09.09 395 0
1154 이펙트는 조금 나중에 들어야겠다 file 美樹さやか 2024.09.08 404 0
1153 다음주까지 해보고 진도 잘 안나오면 유료 인강이나 들어야겠다 file 美樹さやか 2024.09.07 390 0
1152 SQL 공부 다시시작 또치면과락 2024.09.07 365 0
1151 어제 자기 전에 복습 겸 만든거 file 美樹さやか 2024.09.06 386 0
1150 오늘은 진도 좀 빼야겠다 file 美樹さやか 2024.09.05 402 0
1149 애니메이션 렌더링은 PC방에서 해야겠네 file 美樹さやか 2024.09.05 379 0
1148 어제 한 뻘짓 file 美樹さやか 2024.09.03 349 0
1147 내일 복습 좀 하고 진도 더 나가야겠다 file 美樹さやか 2024.09.01 359 0
1146 카메라 부분이 아직도 힘드네 file 美樹さやか 2024.08.31 355 0
1145 약 16개만 적으면 게시판 하나 먹게 되는 것이구먼 2 美樹さやか 2024.08.31 364 0
1144 튜토리얼 하나 완료했다 file 美樹さやか 2024.08.31 373 0
목록
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 60 Next
/ 60

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5