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로 연습하길 추천해요!

화이팅입니다.

작업형2 카테고리

0

8

1

110강 회귀_8번 문의

0

9

2

XGBRegressor 학습 시 warning 출력

0

13

2

데이터 프레임을 변경해도 되나요?

0

10

2

10회 기출 작업형3 문제 2-1 질문

0

15

2

작업형 2 질문

0

15

2

작업형 2 템플릿 확인 요청

0

13

2

작업형2 인코딩 질문

0

22

2

작업형 3 벼락치기 공부방법 질문

0

30

2

기출 11회 작업형 2_전체 데이터 학습 여부

0

31

2

예측값 결과 소수점 차이

0

28

2

기출 문제와 실전챌린지 연습문제 무엇부터 푸는게 나은가요?

0

35

1

전처리 train() test([ ])

0

23

2

작업형 1 배경지식 질문

0

33

2

옳게 풀은건지 질문드립니다!

0

22

1

roc_auc_score

0

30

2

추가질문 합니다

0

22

2

시험환경 구름

0

21

2

2유형 질문드려요

0

21

2

RandomForest vs lgb

0

28

2

전처리 관련질문

0

29

3

작업형3 기출

0

20

2

유형2에서 데이터분할 생략 가능여부

0

33

2

9회 기출 유형3 질문

0

21

2