1. 연구 주제 및 연구 목적

서울시 공공자전거 (따릉이) 수요 예측


연구 목적

구별 대여량이 가장 많은 마포구의 따릉이 시간대별 따릉이 수요 예측을 통한 따릉이 관리 및 재배치 인력의 효율성 제고

2. 데이터 수집

  1. 공공자전거 대여이력정보
  2. [서울 빅데이터 캠퍼스]
    2017년 4-6월 서울시 내 따릉이 대여일시, 대여정류소, 반납정류소 정보가 있음
    구정보 또한 ’numeric vector’으로 되어있으므로

데이터 전처리

a) 김지원 —- ^^ 아직 안 함. ㅋ

3. 변수 설정:

Dependent Variable Description
Count 특정한 구의 정류소를 이용한 수


4. 연구 범위 설정

기간 설정

데이터량을 고려하여 2017년 전체가 아닌 2017년 2분기를 연구 범위로 설정 #### 기간 설정 이유 1년을 기준으로 1년 중 2분기가 특히 기후 변화의 영향을 크게 받을 것으로 예상
‘날씨’,’따릉이 수요량’간의 관계를 파악하기 용이함

b) 구 설정

station.merge <- read.csv("Data/station_merge.csv", header = TRUE, sep = ",",fileEncoding = 'UTF-8')
ggplot2:: ggplot(data = station.merge, aes(x= station.no, user_count)) +ggtitle("Station numbers and rent frequency of Seoul") +geom_point(aes(size=user_count), shape=21, fill="#02B58A",color="#dadada") +guides(fill=guide_legend(title=NULL)) +geom_text(aes(y=user_count),label=station.merge$gu,vjust=-1.1,size=4) +xlab("Station #") +ylab("Rented") +theme(panel.background = element_rect(fill = "#F6F1EB",size=2),panel.grid.major = element_line(colour = "#DADADA",linetype = "dashed"),panel.grid.minor = element_line(colour = "#F6F1EB"),legend.title = element_blank(),legend.justification = "bottom",legend.key = element_rect(fill = "white"),legend.background=element_rect(colour = '#dadada',size=0.01),plot.title = element_text(colour="#706f6f", size=22,hjust=0.5,vjust=3,face="bold"),axis.title=element_text(colour = "#706f6f",size=15),axis.text = element_text(colour="#706f6f"))

구 설정 이유

‘서울시 구별 따릉이 대여소 수와 대여량’ 분석 결과, 마포구의 대여량이 가장 많은 것으로 나타남
구별 대여량이 많기에 자전거 수작업 재배치는 물론, 관련 기반시설 관리 인력이 많이 필요할 것으로 추측해볼 수 있음

5. 상관분석


6. 회귀모형

회귀분석


##### i) 데이터 정제

ozone, pm10, pm2.5의 NA를 다음 row 값으로 대체
mapo_na <- mapo

for(i in 1:nrow(mapo_na)){
  if(is.na(mapo_na[i, "ozone"])){
    mapo_na[i, "ozone"] <- mapo_na[i+1, "ozone"]
  }
  if(is.na(mapo_na[i, "pm10"])){
    mapo_na[i, "pm10"] <- mapo_na[i+1, "pm10"]
  }
  if(is.na(mapo_na[i, "pm2.5"])){
    mapo_na[i, "pm2.5"] <- mapo_na[i+1, "pm2.5"]
  }
}
NA가 없는 데이터과 , NA를 다음 행 값으로 대체한 데이터 분석 결과, 모델의 AIC, MSE, r-squared 값이 99% 유사하다는 결과가 나왔다. 그밖에 NA를 포함한 데이터는 회귀모형 선정 과정에 오류가 있었으므로 NA가 없는 데이터로 최종 선정하였다.
ii) 다중회귀모형
- 1 기존 독립변수 전부 사용
(1) train/test dataset 생성
p = 0.6, 0.7, 0.8 세 경우에 대해 분석 진행함
## 
## Call:
## lm(formula = count ~ weekend + time.1 + time.2 + time.3 + time.4 + 
##     time.5 + temperature + precipitation + windspeed + humidity + 
##     visibility + ozone + pm10 + pm2.5, data = mapo_na.train)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -202.405  -31.830   -4.369   26.491  221.875 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    -2.345111  20.522905  -0.114  0.90904    
## weekend         9.587975   3.221205   2.977  0.00297 ** 
## time.1         46.913748   5.149246   9.111  < 2e-16 ***
## time.2         15.783697   5.960103   2.648  0.00819 ** 
## time.3         60.314693   6.651077   9.068  < 2e-16 ***
## time.4        159.089302   5.803366  27.413  < 2e-16 ***
## time.5         68.356519   5.084665  13.444  < 2e-16 ***
## temperature     5.018325   0.331569  15.135  < 2e-16 ***
## precipitation -67.014390   8.305186  -8.069 1.63e-15 ***
## windspeed       8.855408   1.455688   6.083 1.56e-09 ***
## humidity       -0.670134   0.132923  -5.042 5.29e-07 ***
## visibility     -0.005348   0.004893  -1.093  0.27455    
## ozone           0.269196 102.992142   0.003  0.99791    
## pm10           -0.303868   0.071935  -4.224 2.57e-05 ***
## pm2.5           0.120484   0.159356   0.756  0.44975    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 51.21 on 1264 degrees of freedom
## Multiple R-squared:  0.6777, Adjusted R-squared:  0.6741 
## F-statistic: 189.8 on 14 and 1264 DF,  p-value: < 2.2e-16
(2) 독립변수 제거
- step function 이용한 독립변수 최적화
- 종속변수 대비 상관계수 0.2미만 독립변수 제거 (cor > 0.2)
- 종속변수 대비 상관계수 0.4미만 독립변수 제거 (cor > 0.4)

(3) 적절한 모형 선택
## [1] 2777.69
p = 0.6, backward / stepwise 방법으로 도출한 모델이 가장 AIC가 낮았음
MSE, r-squared는 AIC에 비해 변화가 크지 않음
iii) 회귀 모형 평가

## 
##  Shapiro-Wilk normality test
## 
## data:  mapo.final$residuals
## W = 0.97347, p-value = 1.405e-14
##  lag Autocorrelation D-W Statistic p-value
##    1       0.3810735      1.237521       0
##  Alternative hypothesis: rho != 0
## Non-constant Variance Score Test 
## Variance formula: ~ fitted.values 
## Chisquare = 139.623    Df = 1     p = 3.218537e-32
## 
## Call:
## lm(formula = count ~ weekend + time.1 + time.2 + time.3 + time.4 + 
##     time.5 + temperature + precipitation + windspeed + humidity + 
##     visibility + pm10, data = mapo_na.train)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -202.747  -31.850   -4.341   26.177  221.897 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     4.920757  17.573764   0.280  0.77952    
## weekend         9.454271   3.206714   2.948  0.00325 ** 
## time.1         46.889730   5.026584   9.328  < 2e-16 ***
## time.2         16.123478   5.928393   2.720  0.00662 ** 
## time.3         60.882266   6.520420   9.337  < 2e-16 ***
## time.4        159.795389   5.718248  27.945  < 2e-16 ***
## time.5         68.738760   5.053046  13.603  < 2e-16 ***
## temperature     4.985080   0.320228  15.567  < 2e-16 ***
## precipitation -68.125650   8.153869  -8.355  < 2e-16 ***
## windspeed       8.679329   1.381247   6.284 4.54e-10 ***
## humidity       -0.691589   0.126387  -5.472 5.36e-08 ***
## visibility     -0.007265   0.004078  -1.781  0.07512 .  
## pm10           -0.287664   0.068622  -4.192 2.96e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 51.18 on 1266 degrees of freedom
## Multiple R-squared:  0.6775, Adjusted R-squared:  0.6745 
## F-statistic: 221.7 on 12 and 1266 DF,  p-value: < 2.2e-16
## 
## 
## ASSESSMENT OF THE LINEAR MODEL ASSUMPTIONS
## USING THE GLOBAL TEST ON 4 DEGREES-OF-FREEDOM:
## Level of Significance =  0.05 
## 
## Call:
##  gvlma::gvlma(x = mapo.final) 
## 
##                     Value   p-value                   Decision
## Global Stat        290.50 0.000e+00 Assumptions NOT satisfied!
## Skewness            72.72 0.000e+00 Assumptions NOT satisfied!
## Kurtosis            69.35 1.110e-16 Assumptions NOT satisfied!
## Link Function      134.93 0.000e+00 Assumptions NOT satisfied!
## Heteroscedasticity  13.51 2.376e-04 Assumptions NOT satisfied!
iv) 회귀모형의 해석
##       weekend        time.1        time.2        time.3        time.4 
##      1.018713      1.712127      2.354639      3.009038      2.173863 
##        time.5   temperature precipitation     windspeed      humidity 
##      1.704080      1.658911      1.219278      1.614306      3.195380 
##    visibility          pm10 
##      2.803297      1.698957

##                  Weights
## pm2.5          0.3772272
## weekend        0.4133684
## time.1         0.9679139
## pm10           1.2656510
## time.5         1.9862820
## time.2         1.9971855
## visibility     2.5441255
## precipitation  3.6582674
## time.3         5.1599312
## ozone          5.1996888
## humidity       7.1397981
## windspeed      8.7470220
## temperature   20.8720952
## time.4        39.6714437
Standardized Coefficients::
(Intercept) time.1 time.2 time.3
0.00000000 0.21908334 0.06114777 0.23704393
time.4 time.5 temperature precipitation
0.65026107 0.30878509 0.34403638 -0.15360869
windspeed humidity pm10
time.4 (퇴근시간대/저녁), temperature는 시간별 자전거 이용량에 높은 영향을 준다.

7. 모형 성능 개선

8. 결론

9. 후기