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 の [Quick Start](https://facebook.github.io/prophet/docs/quick_start.html) を試してみる


```python
import pandas as pd
from fbprophet import Prophet
```


```python
df = pd.read_csv(
    "https://raw.githubusercontent.com/facebook/prophet/master/"
    "examples/example_wp_log_peyton_manning.csv"
)
df.head()
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ds</th>
      <th>y</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>2007-12-10</td>
      <td>9.590761</td>
    </tr>
    <tr>
      <th>1</th>
      <td>2007-12-11</td>
      <td>8.519590</td>
    </tr>
    <tr>
      <th>2</th>
      <td>2007-12-12</td>
      <td>8.183677</td>
    </tr>
    <tr>
      <th>3</th>
      <td>2007-12-13</td>
      <td>8.072467</td>
    </tr>
    <tr>
      <th>4</th>
      <td>2007-12-14</td>
      <td>7.893572</td>
    </tr>
  </tbody>
</table>
</div>




```python
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.





<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ds</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>3265</th>
      <td>2017-01-15</td>
    </tr>
    <tr>
      <th>3266</th>
      <td>2017-01-16</td>
    </tr>
    <tr>
      <th>3267</th>
      <td>2017-01-17</td>
    </tr>
    <tr>
      <th>3268</th>
      <td>2017-01-18</td>
    </tr>
    <tr>
      <th>3269</th>
      <td>2017-01-19</td>
    </tr>
  </tbody>
</table>
</div>




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




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ds</th>
      <th>yhat</th>
      <th>yhat_lower</th>
      <th>yhat_upper</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>3265</th>
      <td>2017-01-15</td>
      <td>8.204005</td>
      <td>7.506318</td>
      <td>8.897406</td>
    </tr>
    <tr>
      <th>3266</th>
      <td>2017-01-16</td>
      <td>8.529004</td>
      <td>7.833604</td>
      <td>9.213509</td>
    </tr>
    <tr>
      <th>3267</th>
      <td>2017-01-17</td>
      <td>8.316397</td>
      <td>7.598104</td>
      <td>9.071751</td>
    </tr>
    <tr>
      <th>3268</th>
      <td>2017-01-18</td>
      <td>8.149020</td>
      <td>7.405367</td>
      <td>8.816930</td>
    </tr>
    <tr>
      <th>3269</th>
      <td>2017-01-19</td>
      <td>8.160915</td>
      <td>7.413687</td>
      <td>8.862955</td>
    </tr>
  </tbody>
</table>
</div>



`plot` すると `TypeError` が発生する


```python
try:
    fig1 = m.plot(forecast)
except TypeError as e:
    print(e)
```

    float() argument must be a string or a number, not 'datetime.datetime'



![output_7_1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/473192/e49f5c60-23df-fc9a-dd4e-f82ffc661e5c.png)



`plot` の前に `pd.plotting.register_matplotlib_converters()` を追加すると解決する
(Prophet の [issue](https://github.com/facebook/prophet/issues/999) を参照）


```python
pd.plotting.register_matplotlib_converters()
```

`plot` 成功


```python
fig1 = m.plot(forecast)
```


![output_11_0.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/473192/6c7889e4-28cc-c03e-e057-365e56a1cbb1.png)