inflearn logo
강의

Khóa học

Chia sẻ kiến thức

[Việc riêng sau giờ tan làm] Kỳ thi thực hành chứng chỉ phân tích dữ liệu lớn (Dạng bài 1, 2, 3)

코딩팡 2호선 전처리 종합 28번 중고 카메라 매입가 문제 최적화 질문드립니다.

5

garambbi

3 câu hỏi đã được viết

0

안녕하세요.

코딩팡 2호선 노선도 문제에서 28번 중고 카메라 매입가 문제를 풀었는데, 어떻게 해도 RMSE 값이 낮아지지 않아서 질문드립니다. 현재 아래와 같은 코드로 했을 때 가장 정확도가 높았고, 'shutter_count'를 중앙값이나 평균 등으로 채울 경우 정확도가 더 떨어졌었습니다.

해당 코드에서 어떤 부분을 수정해야 정확도가 높아질 수 있는지 모르겠어서 질문드립니다.

감사합니다.

import pandas as pd
pd.set_option('display.max_column', None)

train = pd.read_csv("data/camera_train.csv")
test = pd.read_csv("data/camera_test.csv")

# EDA
# print(train.shape, test.shape) # (2500, 11) (800, 10)
# print(train.info(), test.info()) # non-null, 대부분 obj, item_id drop, shutter_count '?' 유의
# print(train.describe(include='object'), test.describe(include='object')) # different
# print(train.isnull().sum())

# Pre - price
y_train = train.pop('price')
train = train.drop(['item_id'], axis=1)
test = test.drop(['item_id'], axis=1)
# encoding
import numpy as np
train['unknown'] = np.where(train['shutter_count']=='?', 1, 0)
test['unknown'] = np.where(test['shutter_count']=='?', 1, 0)
train['shutter_count'] = train['shutter_count'].replace({'?':'-1'}).astype(int)
test['shutter_count'] = test['shutter_count'].replace({'?':'-1'}).astype(int)

train['megapixel'] = train['megapixel'].str.replace('MP', '', regex=False).astype(float)
test['megapixel'] = test['megapixel'].str.replace('MP', '', regex=False).astype(float)
from sklearn.preprocessing import LabelEncoder,RobustScaler
le = LabelEncoder()
cols = train.select_dtypes(include='object').columns
tmp = pd.concat([train, test], axis=0)
for col in cols:
    tmp[col] = le.fit_transform(tmp[col])
train = tmp.iloc[:len(train)].copy()
test = tmp.iloc[len(train):].copy()
sc = RobustScaler()
train['shutter_count'] = sc.fit_transform(train[['shutter_count']])
test['shutter_count'] = sc.transform(test[['shutter_count']])
# print(train.head(10))
# Valid
from sklearn.model_selection import train_test_split
X_tr, X_val, y_tr, y_val = train_test_split(train, y_train, test_size=0.2, random_state=0)

# Modeling - RMSE
from sklearn.metrics import mean_squared_error
def val(name, pred):
    print(f"[{name}] RMSE = {(mean_squared_error(y_val, pred)) ** 0.5}")
# RF
from sklearn.ensemble import RandomForestRegressor
rf = RandomForestRegressor(random_state=0, n_estimators=600)
rf.fit(X_tr, y_tr)
pred_rf = rf.predict(X_val)
val('RF n_estimators=600', pred_rf)
# XGB
from xgboost import XGBRegressor
xgb = XGBRegressor(random_state=0, max_depth=5)
xgb.fit(X_tr, y_tr)
pred_xgb = xgb.predict(X_val)
val('XGB max_depth=5', pred_xgb)
# LGBM
from lightgbm import LGBMRegressor
lgb = LGBMRegressor(random_state=0, n_estimators=400, learning_rate=0.03, verbose=-1, max_depth=7)
lgb.fit(X_tr, y_tr)
pred_lgb = lgb.predict(X_val)
val('LGB max_depth=7 n_estimators=400', pred_lgb)

# [RF def] RMSE = 129.19054561590218
# [XGB def] RMSE = 85.62395927743444
# [LGB def] RMSE = 104.9641856432373

# [RF n_estimators=600] RMSE = 125.20707171872648
# [XGB max_depth=5] RMSE = 79.00022250759804
# [LGB max_depth=7 n_estimators=400] RMSE = 102.49297269651322

# Submit
xgb.fit(train, y_train)
pred = xgb.predict(test)
pd.DataFrame({'pred':pred}).to_csv('result.csv', index=False)
res = pd.read_csv('result.csv')
print(res.shape, res.head())

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

Câu trả lời 0

8회 작업형2

0

4

1

작업형2 모의문제2 updated 2026.10

0

14

3

단순선형 회귀분석 신뢰구간,예측구간 관련질문

0

20

2

판다스 부분 강의 듣고 있는데..

0

27

2

코딩팡 Pro 등록방법 문의

0

24

1

'자동으로 저장할 수 없습니다. 이 파일은 원격으로 또는 다른 탭에서 업데이트되었습니다.'

0

18

2

random_state에 따른 최종스코어 점수차이

0

27

2

코랩 백엔드

0

49

3

xgboost 사용 시 오류 이유

0

41

2

작업형 2 제출하는 법

0

52

2

Section 5. 문자열 슬라이싱, 파생변수, 평균값 질문 드립니다.

0

36

1

예시문제 작업형2(ver. 2025)

0

43

2

수강 연장 문의드립니다.

0

40

2

예시문제 작업형2(ver. 2025)

0

48

2

작업형2 모의문제 3 질문

0

57

1

수강연장 관련 문의

0

60

2

안녕하세요 강사님 문의사항이 있습니다

0

45

1

수강 연장 문의

0

91

4

수강기간 연장 관련 문의

0

61

2

작업형2모의문제3_updated2026.10

0

77

2

안녕하세요. 수강연장 신청드립니다

0

58

2

코랩 링크

0

49

2

작업형2 모의문제2 updated 2026.10 질문

0

64

2

카이제곱 독립성검정 질문합니다.

0

54

2