본문 바로가기

Kaggle

Kaggle - Bike Sharing Demand : Evaluation (Random Forest, Cross-validation)

반응형

https://steadiness-193.tistory.com/228

 

Kaggle - Bike Sharing Demand : EDA & Feature Engineering

데이터 출처 https://www.kaggle.com/c/bike-sharing-demand/data 컬럼 설명 자료형 datetime 일시 연-월-일 시:분:초 object season 계절 1: 봄 / 2: 여름 / 3: 가을 / 4: 겨울 int64 holiday 휴일 1: 휴일 / 0:..

steadiness-193.tistory.com

https://steadiness-193.tistory.com/229

 

Kaggle - Bike Sharing Demand : EDA & Feature Engineering (2)

https://steadiness-193.tistory.com/228 Kaggle - Bike Sharing Demand : EDA & Feature Engineering 데이터 출처 https://www.kaggle.com/c/bike-sharing-demand/data 컬럼 설명 자료형 datetime 일시 연-월-일..

steadiness-193.tistory.com

 

위 두 포스팅에서 진행한 데이터 탐색과 전처리가 완료된

 

train 데이터셋만을 활용한다.

 

random forest 모델을 이용하여 cross-validation을 실행한다.

 

 

 

 

 

Random Forest

 

 

[RandomForestRegressor]

n_estimatiors : 트리의 갯수, 높을 수록 정확도가 높아지나 시간이 오래 걸린다.

n_jobs : 병렬처리 여부, -1을 입력하면 컴퓨터에 존재하는 모든 코어를 사용한다.

random_state : 결과를 고정시킴, Seed Number와 같은 개념

 

 

 

train 데이터셋의 count를 바로 이용하지 않고

 

casual과 registered 컬럼을 이용한다.

 

 

 

다만, 각각 log1p를 씌운 log_casual, log_registered를 활용하고

 

추후에 exp로 원래 값으로 돌려 받은 뒤

 

그 두개를 합친 count를, 기존(정답) count와 비교해서 점수를 측정한다.

 

 

 

https://steadiness-193.tistory.com/224

 

Numpy - np.log, np.log1p, np.exp

로그 기본 개념 밑 조건 : a > 0 진수 조건 : N > 0 x의 범위는 실수 위 내용 중에서 자연로그에 대해서 알아보자. 자연로그는 자연상수 e를 밑으로 하는 로그함수(natural logarithm)이며 주로 위 세가지 �

steadiness-193.tistory.com

 

 

 

 

 

casual

 

 

 

[cross_val_predict]

model : 점수를 측정할 머신러닝 모델

X_train : train 데이터의 feature

y_log_casual_train : train 데이터의 label

cv : 데이터를 조각낼 개수, 20조각을 내서 알고리즘을 학습한 뒤 예측한다.

 

 

현재는 log1p값을 예측한 것이기 때문에 exp를 이용해서 원래 casual 대여량을 반환받자.

 

 

 

 

 

 

 

registered

 

 

 

 

이렇게 구한

 

y_casual_predict 와 y_registered_predict 를 더하면

 

찾고자 했던 y_predict를 만들 수 있다.

 

 

 

y_predict

 

 

 

이제 이 y_predict를

 

진짜 정답인 y_train과 비교해서 평가를 해주면 된다.

 

 

 

 

 

진짜 정답 : y_train

 

 

 

 

 

 

RMSLE

 

https://www.kaggle.com/c/bike-sharing-demand/overview/evaluation

 

 

Bike Sharing Demand의 평가 방식은 RMSLE이다.

 

 

정답(a, actual) 과 예측값(p, predict)의 차이가 크면 패널티를 덜 주는 방식이다.

log(x + 1)이 그 역할을 한다.

 

 

 

 

 

Mean Squared Logarithmic Error

 

 

sklearn.metrics 라이브러리의 mean_squared_log_error를 이용한다.

 

위 기능에 y_predict와 y_train을 넣어서 점수를 구한 다음,

 

루트(np.sqrt)를 씌우면 RMSLE 방식으로 평가한 점수가 나오게 된다.

 

RMSLE는 점수가 낮을 수록 정확도가 더 높다고 가정한다.

 

 

 

반응형