2022-05-09 ~ 2022-05-15
3주차는 Unsupervised Learning에 대해서 학습하였다. 또한 데이터분석에서 매우 중요한 pandas의 기본 사용법을 배웠다.
Data Load
탐색기 등을 통해 directory에 접근하여 무슨 파일이 있는지 확인할 수 없거나 파일이 너무 많아 다루기 힘든 경우에는 os의 method들을 이용해 처리하는 것이 좋다.
https://pandas.pydata.org/Pandas_Cheat_Sheet.pdf
훈련 샘플 각각이 수백만 개의 특성을 가지고 있고, 수많은 특성은 훈련을 느리게 함
차원 축소시 일부 정보가 유실되어 훈련 속도가 빨라질 수 있지만, 시스템의 성능이 조금 나빠질 수 있다.
sklearn:
입력 특성 X는 있지만 레이블 y는 없음. 일일이 레이블을 매길 필요 없이 알고리즘이 레이블이 없는 데이터를 사용한다.
비슷한 샘플을 구별해 하나의 Cluster로 할당하는 작업
sklearn:
군집은 지도 학습 알고리즘을 적용하기 전에 전처리 단계로 사용할 수 있다.
다른 ARIMA methods와 비교해 상대적으로 좋다는 의미x, 분석을 위한 대체 Library
예측 결과를 만들기 위해 필요한 코드가 길지 않다.
ARIMA 모델과는 다르게 약간의 기술적인 블랙박스
구간이 필요
<딥러닝 블랙박스>
End to End 방식이고 중간 과정에 연구자의 개입이 이루어지지 않기 때문에, 그 과정을 알 수도 없고(후술) 개입도 안 하기 때문에 알수가 없다.
딥러닝 과정을 Blackbox라고 표현하는 것에 있어서 반대하는 주장이 있는데,
딥러닝 자체도 결국 layer가 쌓이면서 저차원의 선형회귀식으로 표현되기 때문이다.
FB Prophet은 Layer가 공개되어 있지않다.
df.colum 하드 코딩 돼 있어서 설정필요
df.columns = ['ds','y']
df[’ds’] = pd.to_datetime(df[’ds’])
m = Prophet()
m.fit(df)
자동으로 changepoints를 찾아줌. 세밀한 조정, overfitting 방지 위해 조정 가능
기본적으로 80%의 changepoints 찾는다 (과적합 방지)
Scale 조정 (추세 유연성)
m = Prophet(changepoint_prior_scale=0.5)
m = Prophet(changepoint_prior_scale=0.001)
m = Prophet(changepoints=['2014-01-01'])
forecast = m.fit(df).predict(future)
fig = m.plot(forecast)
The inputs to this function are a name, the period of the seasonality in days, and the Fourier order for the seasonality. For reference, by default Prophet uses a Fourier order of 3 for weekly seasonality and 10 for yearly seasonality.
Defalut:
Weekly - 3
Monthly - 5
Yearly - 10
너무 높게 설정하면 Overfitting 발생
시즌 구분
# Python
def is_nfl_season(ds):
date = pd.to_datetime(ds)
return (date.month > 8 or date.month < 2)
df['on_season'] = df['ds'].apply(is_nfl_season)
df['off_season'] = ~df['ds'].apply(is_nfl_season)
m = Prophet(weekly_seasonality=False)
m.add_seasonality(name='weekly_on_season', period=7, fourier_order=3, condition_name='on_season')
m.add_seasonality(name='weekly_off_season', period=7, fourier_order=3, condition_name='off_season')
future['on_season'] = future['ds'].apply(is_nfl_season)
future['off_season'] = ~future['ds'].apply(is_nfl_season)
forecast = m.fit(df).predict(future)
fig = m.plot_components(forecast)
Reference: https://facebook.github.io/prophet/docs/quick_start.html#python-api