This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stock_prophet_df = stock_df[['formatted_date', 'adjclose']] | |
stock_prophet_df = stock_prophet_df.rename(columns = {'formatted_date': 'ds' , 'adjclose': 'y'}) | |
stock_prophet_df |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', |
NewerOlder