Skip to content

Instantly share code, notes, and snippets.

View A-safarji's full-sized avatar
🎯
Focusing

Abdultawwab Safarji A-safarji

🎯
Focusing
View GitHub Profile
@A-safarji
A-safarji / NeuralProphet-plot.py
Created December 30, 2021 07:41
plotting NeuralProphet
# plot
fig_forecast = model.plot(forecast)
fig_components = model.plot_components(forecast)
fig_model = model.plot_parameters()
@A-safarji
A-safarji / NeuralProphet.py
Created December 30, 2021 07:26
NeuralProphet Forcasting
# model and fit D= clander days freq
model = NeuralProphet()
metrics = model.fit(apple_features,
freq='D', epochs=1000)
#predict
forecast = model.predict(apple_features)
@A-safarji
A-safarji / read-data.py
Created December 30, 2021 07:15
read the data
# read data
df1 = pd.read_csv("stock.csv")
df1.head()
# select Date and Adj Close from the dataset
df2 = df1[['Date','Adj Close']]
df2.tail()
# change names to fit NeuralProphet req
apple_features = df2.rename(columns = {"Date":"ds","Adj Close":"y"})
@A-safarji
A-safarji / NeuralProphet.py
Created December 30, 2021 07:10
install and import NeuralProphet
# install neuralprophet
!pip install neuralprophet
# import libraries
import pandas as pd
import matplotlib.pyplot as plt
import plotly.offline as py
import matplotlib.pyplot as plt
%matplotlib inline
# import neuralprophet
@A-safarji
A-safarji / BiLSTM-bulid.py
Created December 29, 2021 21:40
Deep learning models for time series forecasting
import numpy as np
import pandas as pd
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
# Reading and converting Date
data = pd.read_csv('AAPL.csv')
data['Date'] = pd.to_datetime(data['Date'], infer_datetime_format=True)
data.info()
@A-safarji
A-safarji / LSTM-buliding.py
Last active January 5, 2022 18:04
LSTM model building
### Create the Stacked LSTM model
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense,Dropout
from tensorflow.keras.layers import LSTM
from tensorflow.keras.initializers import RandomNormal, Constant
import tensorflow as tf
# Set random seed for reproducibility: get the same result after each time running the model
tf.random.set_seed(1234)
@A-safarji
A-safarji / neuralprophet-Split.py
Last active January 5, 2022 18:32
neuralprophet with spliting
### with spliting train and test
m = NeuralProphet()
df_train, df_test = m.split_df(apple_features, valid_p=0.3,freq='D')
# fiting
metricss = m.fit(df_train, validation_df=df_test , freq='D',epochs=1000)
# predict
forecast = model.predict(df_train)
@A-safarji
A-safarji / NeuralProphet.py
Last active January 5, 2022 18:35
NeuralProphet Forcasting
# install neuralprophet
!pip install neuralprophet
# import libraries
import pandas as pd
import matplotlib.pyplot as plt
import plotly.offline as py
import matplotlib.pyplot as plt
%matplotlib inline
# import neuralprophet
@A-safarji
A-safarji / BiLSTM.py
Last active January 5, 2022 18:32
Deep learning models for time series forecasting
### Create the Bidirectional LSTM model
from random import random
from numpy import array
from numpy import cumsum
from keras.models import Sequential
from tensorflow.keras.layers import Dense,Dropout
from keras.layers import TimeDistributed
from keras.layers import Bidirectional
from tensorflow.keras.layers import LSTM
@A-safarji
A-safarji / LSTM.py
Last active December 16, 2022 00:10
LSTM model building
import numpy as np
import pandas as pd
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
# Reading and converting Date
data = pd.read_csv('AAPL.csv')
data['Date'] = pd.to_datetime(data['Date'], infer_datetime_format=True)
data.info()