
추가부분 (gradientboostring을 사용해서 예측전후의 편차줄이기)학부공부/빅데이터기술_프로젝트2019. 5. 25. 23:09
Table of Contents
반응형
전에 각각의 알고리즘을 적용해서 game_price를 예측했다.
그런데, 알고리즘 적용 후의 예측값과 적용 전의 값의 차이가 존재했고
그 값의 차이를 줄이기 위한 방법은 다음과 같다.
# Gradientboosting regressor 알고리즘을 사용해서 가격예측을 해야한다.
# 예측되어진 값에서 예측전의 값을 빼면 두 값의 편차가 생긴다.
# 이 편차값을 예측되어진 값에서 뺀다면 원래 초기가격에 맞춰지지 않을까 생각을 하였다.
# 이 때 두가지 가정이 주어진다
# 적용 전의 값 - 적용 후의 값 : 양수 or 음수
# 양수일 때는 적용전의 값이 클때이며
# 음수일 때는 적용 후의 값이 더 클때이다.
# 양수일때와 음수일때의 계산을 다르게 해야할 필요를 느꼈다.
코드를 통해서 확인해 본다.
# 예측전의 값과 예측후의 값의 차이를 양수와 음수로 비교해서 , 실제 가격에 맞춘다.
# 예측후의 값에서 예측 전의 값을 뺏을 때 양수일 경우
gbrt_df.loc[gbrt_df['Predicted']-gbrt_df['Actual']>0,"Final_Predict"]=gbrt_df['Predicted']-(gbrt_df['Predicted']-gbrt_df['Actual'])
# 예측후의 값에서 예측 전의 값을 뺏을 때 음수일 경우
gbrt_df.loc[gbrt_df['Predicted']-gbrt_df['Actual']<0,"Final_Predict"]=gbrt_df['Predicted']-(gbrt_df['Predicted']-gbrt_df['Actual'])
print(gbrt_df)
기존의 적용전의 price와 적용후의 price를 담고 있는 dataframe에 편차의 값에 따른 결과값( 양수일때와 음수일때 ) 을
추가해준다.
시각화를 통해 확인해 볼 것이다.
참고한 사이트
Plot individual and voting regression predictions — scikit-learn 0.21.2 documentation
Note Click here to download the full example code Plot individual and voting regression predictions Plot individual and averaged regression predictions for Boston dataset. First, three exemplary regressors are initialized (GradientBoostingRegressor, Random
scikit-learn.org
plt.figure()
plt.plot(gbrt_df['Actual'],'gd', label='Actual_price')
plt.plot(gbrt_df['Predicted'],'b^', label='Predict_price')
plt.plot(gbrt_df['Final_Predict'],'ys', label='Final_Predict_price')
plt.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False)
plt.ylabel('Prieces')
plt.xlabel('Feature_S')
plt.legend(loc="best")
plt.show()
결과값

실제가격 : 초록색
알고리즘 적용 후 예측 값 : 파란색
편차 계산한 값 : 황토색
시각화로 보니 실제가격에 값이 맞춰짐을 알 수 있다.
반응형
'학부공부 > 빅데이터기술_프로젝트' 카테고리의 다른 글
빅데이터기술_최종발표(game_price예측) (0) | 2019.05.25 |
---|---|
game_price 예측(based on linear regression algorithm) (0) | 2019.05.19 |
프로젝트_중간점검(데이터정제과정) (0) | 2019.05.19 |
데이터 모으기(4) (0) | 2019.05.05 |
HTTP Error 403: Forbidden (0) | 2019.05.05 |
@IT grow. :: IT grow.
#IT #먹방 #전자기기 #일상
#개발 #일상