Python ve Fbprophet Kullanarak Zaman Serileriyle Geleceği Tahmin Etmek
adresinde ele aldığım kaynak kodlarını aşağıda bulabilirsiniz.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
""" Program: Ahmet Aksoy Yazım tarihi: 20.04.2020 Python: 3.7 (Anaconda) pandas: 0.25.3 matplotlib: 3.1.2 plotly 4.6.0 fbprophet: 0.6 # conda install -c conda-forge fbprophet conda: 4.8.0 https://tr.investing.com/currencies/us-dollar-index-historical-data """ import pandas as pd import matplotlib.pyplot as plt import fbprophet df1 = pd.read_csv('USD_TRY.csv',decimal=',') # Kullanılacak kolonları seç df = df1[['Tarih','Şimdi']] # Prophet için ds (Tarih) and y (Değer) kolonları gerekiyor df = df.rename(columns={'Tarih': 'ds', 'Şimdi': 'y'}) # Tarih formatını düzenle df['ds'] = pd.to_datetime(df['ds'], format='%d.%m.%Y') # Satırlarımız sadece 2018'den sonrasını içersin df = df[(df['ds']>='2018-01-01')&(df['ds']<='2020-04-20')] df = df.sort_values(by=['ds'],ascending=True) # https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.plot.html plt.plot(df['ds'], df['y'],'r') # kırmızı renk plt.title('Gerçek USDTRY Fiyat Değişimi') plt.ylabel('Fiyat (TRY)') plt.draw() # prophet modelini hazırla ve fit metodunu uygula # https://facebook.github.io/prophet/docs/quick_start.html#python-api df_prophet = fbprophet.Prophet(changepoint_prior_scale=0.15) df_prophet.fit(df) # 12 aylık gelecek tahmini yap tahmin_suresi=365 df_forecast = df_prophet.make_future_dataframe(periods= tahmin_suresi, freq='D') # Tahminleri gerçekleştir df_forecast = df_prophet.predict(df_forecast) # Sonuçları görselleştir df_prophet.plot(df_forecast, xlabel = 'Tarih', ylabel = '1 $ karşılığı TRY değeri') plt.title(f'{tahmin_suresi} günlük USDTRY Tahmin') plt.title('USDTRY Fiyat Değişimi') plt.ylabel('Fiyat (TRY)') plt.show() # tahmin bileşenlerini grafiğe aktar df_prophet.plot_components(df_forecast) plt.show() # import plotly.tools as tls # import plotly.plotly as py # mpl_fig=plt.figure() # plotly_fig = tls.mpl_to_plotly(mpl_fig) # unique_url = py.plot(plotly_fig) |
Ahmet Aksoy