boostcampaitech7 / level2-competitiveds-recsys-06

level2-competitiveds-recsys-06 created by GitHub Classroom
2 stars 0 forks source link

[Model] Random Forest #46

Closed passi3 closed 1 week ago

passi3 commented 2 weeks ago
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_absolute_error

# 학습 및 테스트 데이터 준비
X_train = train_data.drop(columns=['deposit'])
y_train = train_data['deposit']
X_test = test_data.copy()

# 학습 데이터를 검증용으로 분할
X_train_split, X_val_split, y_train_split, y_val_split = train_test_split(X_train, y_train, test_size=0.2, random_state=42)

# 모델 초기화
rf = RandomForestRegressor(n_estimators=500, max_depth=6, random_state=42)

# 모델 학습
rf.fit(X_train_split, y_train_split)

# 검증 세트에 대한 예측
y_val_pred = rf.predict(X_val_split)

# 테스트 세트에 대한 예측
y_test_pred = rf.predict(X_test)

# 평가
mae_val = mean_absolute_error(y_val_split, y_val_pred)

print(f"Validation MAE: {mae_val}")
passi3 commented 2 weeks ago
passi3 commented 1 week ago