2022 May Week 2 WIL

Hyuntae Jung·2022년 5월 15일
0

WIL

목록 보기
3/5

2022-05-09 ~ 2022-05-15

멋사 3주차

3주차는 Unsupervised Learning에 대해서 학습하였다. 또한 데이터분석에서 매우 중요한 pandas의 기본 사용법을 배웠다.

1. Pandas

Data Load
탐색기 등을 통해 directory에 접근하여 무슨 파일이 있는지 확인할 수 없거나 파일이 너무 많아 다루기 힘든 경우에는 os의 method들을 이용해 처리하는 것이 좋다.

https://pandas.pydata.org/Pandas_Cheat_Sheet.pdf

2. 차원 축소

(1) 차원의 저주(Curse of dimensionality)

훈련 샘플 각각이 수백만 개의 특성을 가지고 있고, 수많은 특성은 훈련을 느리게 함
차원 축소시 일부 정보가 유실되어 훈련 속도가 빨라질 수 있지만, 시스템의 성능이 조금 나빠질 수 있다.

(2) 차원 축소 기법

  • PCA (Principal component analysis, 주성분 분석)
  • 커널 PCA
  • LLE (Locally linear embedding, 지역 선형 임베딩

sklearn:

  • Random projection
  • MDS (Multidimensional scaling, 다차원 스케일링)
  • lsomap
  • t-SNE (t-distributed stochastic neighbor embedding)

3. Unsupervised Learning

입력 특성 X는 있지만 레이블 y는 없음. 일일이 레이블을 매길 필요 없이 알고리즘이 레이블이 없는 데이터를 사용한다.

(1) Clustering

비슷한 샘플을 구별해 하나의 Cluster로 할당하는 작업

  • K-means
  • DBSCAN

sklearn:

  • 병합 군집
  • BIRCH
  • 평균-이동
  • 유사도 전파
  • 스펙트럼 군집

군집은 지도 학습 알고리즘을 적용하기 전에 전처리 단계로 사용할 수 있다.

멀캠 프로젝트 5주차

1. FB Prophet Basic

(1) Concept

다른 ARIMA methods와 비교해 상대적으로 좋다는 의미x, 분석을 위한 대체 Library

예측 결과를 만들기 위해 필요한 코드가 길지 않다.

ARIMA 모델과는 다르게 약간의 기술적인 블랙박스 구간이 필요

<딥러닝 블랙박스>
End to End 방식이고 중간 과정에 연구자의 개입이 이루어지지 않기 때문에, 그 과정을 알 수도 없고(후술) 개입도 안 하기 때문에 알수가 없다.
딥러닝 과정을 Blackbox라고 표현하는 것에 있어서 반대하는 주장이 있는데,
딥러닝 자체도 결국 layer가 쌓이면서 저차원의 선형회귀식으로 표현되기 때문이다.
FB Prophet은 Layer가 공개되어 있지않다.

(2) additive regression model with four main components

  • A piecewise linear or logistic growth curve trend. Prophet automatically detects changes in trends by selecting changepoints from the data.자동으로 처리하기 때문에, 다른 모델 부분에 대해 서로 다른 가중치를 찾아내는 단계는 없을 것 (예측 모델이 알아서 해줌)
  • A yearly seasonal component modeled using Fourier series.(푸리에 급수)
  • A weekly seasonal component using dummy variables.
  • A user-provided list of important holidays.

(3) 사용법

  • 열이름 지정

df.colum 하드 코딩 돼 있어서 설정필요

df.columns = ['ds','y']
  • ds 열 날짜/시간 객체
df[’ds’] = pd.to_datetime(df[’ds’])
  • Model fit
m = Prophet()
m.fit(df)

2. FB Prophet Details

  • 요소
    • Capacities : 시계열 데이터 전체의 최대값
    • Change Points : 추세가 변화하는 시점
    • Holidays & Seasonality : 추세에 영향을 미치는 시기적 요인
    • Smoothing : 각각의 요소들이 전체 추이에 미치는 영향의 정도

(1) Trend Changepoints

자동으로 changepoints를 찾아줌. 세밀한 조정, overfitting 방지 위해 조정 가능

  1. 기본적으로 80%의 changepoints 찾는다 (과적합 방지)

  2. Scale 조정 (추세 유연성)

m = Prophet(changepoint_prior_scale=0.5)

m = Prophet(changepoint_prior_scale=0.001)

  1. Changepoint 위치 지정
m = Prophet(changepoints=['2014-01-01'])
forecast = m.fit(df).predict(future)
fig = m.plot(forecast)

(2) Seasonality, Holiday Effects, And Regressors

  • Specifying Custom Seasonalities

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 발생

  • Seasonalities that depend on other factors

시즌 구분

# 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

0개의 댓글