Skip to content

Instantly share code, notes, and snippets.

View karthikraja95's full-sized avatar

Karthik Bhaskar karthikraja95

View GitHub Profile
@karthikraja95
karthikraja95 / model.py
Created December 2, 2020 22:03
Neural Prophet Model
neural_model = NeuralProphet()
metrics = neural_model.fit(stock_prophet_df, freq='D')
metrics.head()
neural_future = neural_model.make_future_dataframe(stock_prophet_df, periods = 365, n_historic_predictions=len(stock_prophet_df))
neural_forecast = neural_model.predict(neural_future)
# Plot the Predictions
neural_figure = neural_model.plot(neural_forecast)
@karthikraja95
karthikraja95 / format.py
Created December 2, 2020 21:58
Correct Format
stock_prophet_df = stock_df[['formatted_date', 'adjclose']]
stock_prophet_df = stock_prophet_df.rename(columns = {'formatted_date': 'ds' , 'adjclose': 'y'})
stock_prophet_df
@karthikraja95
karthikraja95 / exploratory_data_analysis.py
Created December 2, 2020 21:49
Plot the CIBC Adjusted Close Stock Price for last 5 years
# Arrange the data in asecending order
stock = stock_df.sort_values('formatted_date')
# Plot date and average price
plt.figure(figsize = (10,10))
plt.plot(stock_df['formatted_date'], stock_df['adjclose'])
@karthikraja95
karthikraja95 / libraries_dataset.py
Last active December 2, 2020 21:41
Importing Libraries and Dataset For Stock Price Prediction
# import libraries
import pandas as pd # Import Pandas for data manipulation using dataframes
import numpy as np # Import Numpy for data statistical analysis
import matplotlib.pyplot as plt # Import matplotlib for data visualisation
import random
import seaborn as sns
from neuralprophet import NeuralProphet
from yahoofinancials import YahooFinancials
fig, ax = plt.subplots(1, 2, figsize=(18, 6))
## Code for plot 1 ##
sns.lineplot(global_cases.index, np.exp(y), ax=ax[0])
sns.lineplot(global_cases.index, np.exp(model.predict(x)), ax=ax[0])
ax[0].grid(axis='both', alpha=.2)
sns.despine(top=True, left=True)
g = global_cases/global_cases.shift(1)
fig, ax = plt.subplots(figsize=(18, 6))
sns.lineplot(x=g.index, y=g.values, linewidth=3, ax=ax)
sns.lineplot(x=g.index, y=g.rolling(5).mean().values, linewidth=2, ax=ax, color='blue', alpha=.5)
sns.lineplot(x=g.index, y=g.rolling(15).mean().values, linewidth=2, ax=ax, color='orange')
sns.despine(top=True, left=True)
ig, ax = plt.subplots(1, 2, figsize=(18, 6))
## Code for plot 1 ##
sns.lineplot(x=global_cases.index, y=global_cases.values, linewidth=3, ax=ax[0])
sns.despine(top=True, left=True)
ax[0].grid(axis='both', alpha=.2)
@karthikraja95
karthikraja95 / model_1.py
Last active March 22, 2020 14:03
Covid19
import matplotlib.pyplot as plt
import numpy as np
import os
import pandas as pd
import seaborn as sns
import warnings
from datetime import datetime, timedelta
from sklearn.linear_model import LinearRegression, Ridge, Lasso, ElasticNet
from sklearn.metrics import r2_score
@karthikraja95
karthikraja95 / style_transfer_3.py
Last active March 21, 2020 14:31
PyTorch Style Transfer
# weights for each style layer
# weighting earlier layers more will result in *larger* style artifacts
# notice we are excluding `conv4_2` our content representation
style_weights = {'conv1_1': 1.,
'conv2_1': 0.8,
'conv3_1': 0.5,
'conv4_1': 0.3,
'conv5_1': 0.1}
# you may choose to leave these as is
@karthikraja95
karthikraja95 / style_transfer_2.py
Created March 21, 2020 14:01
PyTorch Style Transfer
def get_features(image, model, layers=None):
""" Run an image forward through a model and get the features for
a set of layers. Default layers are for VGGNet matching Gatys et al (2016)
"""
## The mapping layer names of PyTorch's VGGNet to names from the paper
## Need the layers for the content and style representations of an image
if layers is None:
layers = {'0': 'conv1_1',
'5': 'conv2_1',