본문 바로가기
A.I/Machine Learning

Prophet(프로펫) 라이브러리 사용법

by healingmau 2022. 5. 11.

 

Prophet(프로펫) 라이브러리 사용법

 

페이스북에서 제공하고 있는

프로펫(Prophet) 라이브러리

 

먼저 사용하기 전에

모듈을 설치해줘야 하는데요.

 

아나콘다3 프롬프트에서

install : pip install fbprophet를

실행해 줍니다.

 

에러가 난다면

conda install -c conda-forge fbprophet

 

레퍼런스(주소)

https://research.fb.com/prophet-forecasting-at-scale/ https://facebook.github.io/prophet/docs/quick_start.html#python-api

 

Quick Start

Prophet is a forecasting procedure implemented in R and Python. It is fast and provides completely automated forecasts that can be tuned by hand by data scientists and analysts.

facebook.github.io

 

1.

 

1
2
avocado_prophet_df = df[ ['Date','AveragePrice' ] ]
avocado_prophet_df
cs

 

프로펫 분석을 위해서 데이터프레임에서

필요한 컬럼을 가져와 변수

avocado_prophet_df 저장합니다.

 

 

2.

Prophet을 이용한 예측 수행을

하려면 먼저 컬럼명을 ds 와 y로

바꿔줘야 합니다.

 

1
avocado_prophet_df.columns = ['ds''y']
cs

 

 

3.

프로펫 예측하기

 

1
2
3
4
5
# 1. 변수로 만들고
prophet = Prophet()
 
# 2. 데이터로 학습 시키기
prophet.fit(avocado_prophet_df)
cs

 

ex) 365일치를 예측하세요.

 

1
future = prophet.make_future_dataframe(periods=365)
cs

 

프로펫의 predict 함수에

빈 데이터프레임을 넣어서

예측 데이터를 채웁니다.

 

1
forecast = prophet.predict(future)
cs

 

4. 차트로 확인하기

 

프로펫은(prophet)는

차트를 두개 제공합니다.

 

prophet.plot,

prophet.plot_components

 

a.

1
2
prophet.plot(forecast)
plt.savefig('char1.jpg')
cs

 

plt.savefig('char1.jpg')

이미지 저장을 한 이유는?

프로펫이 그래프를 두번 출력하는

버그가 있는데 이미지를 저장하면

한번만 출력됩니다.

 

b.

1
2
prophet.plot_components(forecast)
plt.savefig('char2.jpg')
cs

 

힐링아무의 코딩일기 힐코딩!

댓글