Prophet 의 `TypeError: float() argument must be a string or a number` 는 `plot` 앞에 `pd.plotting.register_matplotlib_converters()` 를 추가하면 해결된다

Prophet TypeError: float() argument must be a string or a number 는 plot 앞에 pd.plotting.register_matplotlib_converters() 를 추가하면 해결됩니다.



Prophet 의 빠른 시작 사용해보기
import pandas as pd
from fbprophet import Prophet
df = pd.read_csv(
    "https://raw.githubusercontent.com/facebook/prophet/master/"
    "examples/example_wp_log_peyton_manning.csv"
)
df.head()





ds
y




0
2007-12-10
9.590761


1
2007-12-11
8.519590


2
2007-12-12
8.183677


3
2007-12-13
8.072467


4
2007-12-14
7.893572


m = Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=365)
future.tail()
INFO:fbprophet:Disabling daily seasonality. Run prophet with daily_seasonality=True to override this.





ds




3265
2017-01-15


3266
2017-01-16


3267
2017-01-17


3268
2017-01-18


3269
2017-01-19


forecast = m.predict(future)
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()





ds
yhat
yhat_lower
yhat_upper




3265
2017-01-15
8.204005
7.506318
8.897406


3266
2017-01-16
8.529004
7.833604
9.213509


3267
2017-01-17
8.316397
7.598104
9.071751


3268
2017-01-18
8.149020
7.405367
8.816930


3269
2017-01-19
8.160915
7.413687
8.862955


plot 그러면 TypeError
try:
    fig1 = m.plot(forecast)
except TypeError as e:
    print(e)
float() argument must be a string or a number, not 'datetime.datetime'


plot 앞에 pd.plotting.register_matplotlib_converters()를 추가하여 해결하기
(Prophet issue 참조)
pd.plotting.register_matplotlib_converters()
plot 성공
fig1 = m.plot(forecast)

좋은 웹페이지 즐겨찾기