메뉴 건너뛰기

목록
2023.03.24 23:17

씨발

profile
조회 수 12 댓글 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 1339 1
1015 오늘 학교 과제내준거 삼김식감 2023.04.11 33 0
1014 23-03 삼성 코테풀이 1 삼김식감 2023.04.10 56 0
1013 블록체인 공부 시작하겠음... 삼김식감 2023.04.07 21 0
1012 결국 교수상이 AI를 언급해버리고 말았음 2 file 삼육두유 2023.04.05 66 0
1011 개인용 1 나는무적이다코인은신이고 2023.04.05 16 0
1010 회귀분석만 하면 뭐함? 1 삼김식감 2023.04.03 26 0
1009 MSE 에 루트 씌우면 RSME 라는데 삼김식감 2023.04.02 14 0
1008 대충 써봄 6 file 삼김식감 2023.04.01 29 0
1007 시발 file 삼김식감 2023.03.27 38 0
1006 대회에 대해 생각해봤음 삼김식감 2023.03.27 28 0
1005 코드검증용 삼김식감 2023.03.27 17 0
1004 데이터 분석 잘하는 수붕이 있냐 file 삼김식감 2023.03.27 11 0
1003 .dat 파일형식 만드는 방법좀 삼김식감 2023.03.27 24 0
1002 다듬은 내용 3 file 삼김식감 2023.03.25 22 0
1001 트레이닝세트하고 테스트셋 설명좀 11 file 삼김식감 2023.03.25 24 0
» 씨발 삼김식감 2023.03.24 12 0
999 내일까지 ... 해본다 삼김식감 2023.03.24 5 0
998 안드로이드 프로그래밍 절반정도는 말에미쳤다 2023.03.19 29 0
997 기계학습 다시 공부하니까 말에미쳤다 2023.03.19 27 0
996 안드로이드 과제해결 ... 1 말에미쳤다 2023.03.17 24 0
목록
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 56 Next
/ 56