Try to fit the sine function with Gaussian noise, but the amplitude and phase of the fitting results are very different. Can you help me?
- Dominant language
- Python
- Stars
- 20.4k
- Forks
- 4.6k
- Avg merge
- 19h 52m
- Merged PRs (30d)
- 1
Description
import numpy as np
import pandas as pd
from prophet import Prophet
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.use('TkAgg')
# 生成含有高斯噪声的正弦信号
np.random.seed(123)
t = np.arange(0, 100, 1)
y = np.sin(t) + np.random.normal(0, 0.1, len(t))
# 将数据整理成Prophet模型所需的格式
df = pd.DataFrame({'ds': pd.to_datetime(t, unit='d'), 'y': y})
# 拟合Prophet模型
m = Prophet(daily_seasonality=True, yearly_seasonality=False, weekly_seasonality=True)
m.fit(df)
# 预测未来一段时间内的正弦信号
future = m.make_future_dataframe(periods=300, freq='d', include_history=True)
forecast = m.predict(future)
# 可视化预测结果和实际值
fig, ax = plt.subplots(figsize=(12, 6))
# m.plot(forecast, ax=ax)
ax.plot(y, 'r')
ax.plot(forecast['yhat'] - forecast['trend'], 'b')
ax.set_xlabel('Time')
ax.set_ylabel('Value')
plt.show()
Contributor guide
Assessment
This issue has not been assessed yet.