기출4회 유형2 문의드립니다.
기출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')
답변 1
작업형2모의문제3_updated2026.10
0
10
1
작업형2 모의문제3_updated2026.10
0
15
2
38강에서 불균형 데이터 처리하는 stratify를 꼭 해줘야하는건지 질문합니다.
0
18
2
수강강의 연장 관련 문의
0
21
1
작업형1_연습문제1 section2
0
24
2
수강기간 연장 문의드립니다
0
24
1
작업형2 모의문제2_updated2026.10
0
32
2
수강기간 연장문의
0
28
1
작업형 2 질문
0
34
2
강의 연장 관련하여 문의드립니다.
0
38
1
섹션7 자료 다운로드
0
42
2
작업형 1 연습문제 Section12
0
41
2
수강기간 연장 문의
0
53
1
안녕하세요, 혹시 수강기간 연장이 가능할까요?
0
45
2
판다스 강의자료는 어디서 받을 수 있나요?
0
55
2
작업형2 모의고사3 자료 업데이트 요청
0
60
4
수강 연장가능여부 문의드립니다!
0
50
2
수강기간 연장 문의드립니다!
0
44
2
최빈값
0
48
2
수강 가이드라인
0
41
2
수강 연장 가능 여부 문의
0
65
2
강의 구매했는데 교재 필수일까요
0
50
2
수강기간 연장 가부 문의드립니다.
0
46
2
수강기간 연장이 가능한지 양해를 구하며 문의를 드립니다.
0
46
2





