inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)

기출4회 유형2 문의드립니다.

해결된 질문

146

서수영

작성한 질문수 5

0

 

기출4회 유형2 문의드립니다.

Macro f1-core는

#*****평가(=교차검증)

from sklearn.model_selection import cross_val_score

score = cross_val_score(model, train, train['Segmentation'], scoring='f1_macro', cv=5)

print(score)

print(score.mean())

이렇게 구하면 되는건가요?

 

 

그리고 아래와 같이 풀이해봤는데

강사님께서 풀이하신 segmentation과 다른데 괜찮나요?

 

풀이과정에 문제는 없는지 확인 부탁드립니다.

 


# 라이브러리 불러오기

import pandas as pd

# 데이터 불러오기

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

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



#*****데이터확인


train.shape, test.shape


train.head(2)

test.head(2)


#문자형 6개

# train.info()


#결측치 없음

train.isnull().sum()

test.isnull().sum()



#*****전처리


#결측값 없음

#train합치기 없음


#인코딩

from sklearn.preprocessing import LabelEncoder


cols= train.select_dtypes(include='object')

cols


for col in cols :

    le = LabelEncoder()

    train[col] = le.fit_transform(train[col])

    test[col] = le.transform(test[col])


#id삭제

train = train.drop('ID',axis=1)

test_ = test.pop('ID')



#*****분리

from sklearn.model_selection import train_test_split

X_tr, X_val, y_tr, y_val = train_test_split(

                                            train.drop('Segmentation',axis=1),

                                            train['Segmentation'],

                                            test_size=0.2,

                                            random_state=2022

)



#*****모델 max_depth=5~7 / n_estimators= 100~1000

from sklearn.ensemble import RandomForestClassifier

model = RandomForestClassifier(random_state=0, max_depth=7, n_estimators=500)

model.fit(X_tr, y_tr)

pred = model.predict(X_val)



#*****평가(=교차검증)

from sklearn.model_selection import cross_val_score

score = cross_val_score(model, train, train['Segmentation'], scoring='f1_macro', cv=5)

print(score)

print(score.mean())


#*****예측

pred = model.predict(test)

pred


submit = pd.DataFrame({

    'ID': test_ID,

    'Segmentation': pred

})

submit


#*****저장

submit.to_csv('submission_csv', index=False)

pd.read_csv('submission_csv')

 

 

python 머신러닝 빅데이터 pandas 빅데이터분석기사

답변 1

0

퇴근후딴짓

네, 큰문제 없어보입니다.

혹시 입문자라면

크로스 밸리데이션보다는 train_test_split로 연습하길 추천해요!

화이팅입니다.

로지스틱회귀, 회귀

0

28

2

회귀 문제를 풀때 질문입니다.

0

32

1

불균형 처리 후 성능이 더 낮아졌다면,

0

44

2

실기 체험 제2유형 에러 문의

0

35

1

LIGHTGBM 으로 하면 pred값이 소수점 6자리까지 나오는게 맞나요

0

35

2

3번문제 등분산 가정

0

35

2

작업형3 target 형 변환 질문

0

29

2

[작업형1] 연습문제 섹션1 ~ 10 의 section4

0

23

3

원핫인코딩과 레이블 인코딩에서 concat

0

44

2

제2유형 질문입니다.

0

39

2

C()

0

36

2

작업형 2에서 strafity 적용 유무

0

43

2

수강 기간 연장 가능 여부 문의드립니다.

0

46

1

ols

0

36

2

2유형 작성관련 질문(일반 심화)

0

31

2

2유형 작성관련 질문

0

30

2

2유형 object컬럼 개수 다르면

0

37

2

코딩팡질문이요ㅠㅠ

0

36

2

관찰값과 기대값의 개념이 헷갈립니다.

0

19

2

작업형2 ID 컬럼 삭제 질문

0

39

2

2유형 작성관련 질문

0

27

2

memoryerror 질문

0

21

2

작업형 유형2 이렇게 고정 템플릿으로 가져가도 될까요?

0

37

1

ID 삭제 필수 인가요?

0

33

3