시카고 범죄 현황
먼저 Date 컬럼 가공
iso 표준 시간으로 바꿔주기
chicago_df['Date'] = pd.to_datetime(chicago_df['Date'] , format = '%m/%d/%Y %I:%M:%S %p')
인덱스 설정
https://seonggongstory.tistory.com/164
데이터 준비
chicago_prophet = chicago_df.resample('D').size()
chicago_prophet = chicago_prophet.reset_index()
프로펫 라이브러리 사용하려면 날짜는 'ds' 예측수치는 y로 세팅을 해야한다
chicago_prophet.columns=['ds','y']
예측하기
prophet = Prophet()
prophet.fit(chicago_prophet)
freq조절 문자
https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#timeseries-offset-aliases
페이스북 프로펫 페이지 예
https://facebook.github.io/prophet/docs/non-daily_data.html
2년치(730일)예측을 한다면
future = prophet.make_future_dataframe(periods = 730 , freq = 'D')
forecast = prophet.predict(future)
시각화
prophet.plot(forecast)
plt.show()
plt.savefig('chart11.jpg')
prophet.plot_components(forecast)
plt.show()
plt.savefig('chart12.jpg')
'파이썬 > 라이브러리' 카테고리의 다른 글
pandas: resample이용하여 Time Series 년도별,월별,일별 group화 하기 (0) | 2023.01.03 |
---|---|
pandas: collaborative filtering을 통한 영화 추천시스템 구현 (0) | 2023.01.03 |
파이썬 압축파일 푸는 방법 (0) | 2022.12.30 |
파이썬 라이브러리22 pandas 데이터프레임 정렬하기/sort/ascending (0) | 2022.11.25 |
파이썬 라이브러리21 pandas 데이터프레임 : applying 함수 (0) | 2022.11.25 |