<jupyter_start><jupyter_text>In-Sample Evaluation and Out-of-Sample Evaluation In-sample: data is what you have.       Out-of-sample: is the data you do not have and want to forecast or estimate.  A way to numerically determine how good the model fits on dataset.Two important measures to determine the fit of a model:     Mean Squared Error (MSE)     R-squared (R^2)<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

import warnings
warnings.filterwarnings("ignore")

# fix_yahoo_finance is used to fetch data 
import fix_yahoo_finance as yf
yf.pdr_override()
# input
symbol = 'AMD'
start = '2014-01-01'
end = '2018-08-27'

# Read data 
dataset = yf.download(symbol,start,end)

# View columns 
dataset.head()
dataset.shape
X = np.array(dataset['Open']).reshape(1172,-1)
Y = np.array(dataset['Adj Close']).reshape(1172,-1)
from sklearn.linear_model import LinearRegression
lm = LinearRegression()

lm.fit(X, Y)
# Find the R^2
lm.score(X, Y)
Yhat = lm.predict(X)
Yhat[0:4]
from sklearn.metrics import mean_squared_error

# mean_squared_error(Y_true, Y_predict)
mean_squared_error(dataset['Adj Close'],Yhat)<jupyter_output><empty_output><jupyter_text>R-squared (R^2)The coefficient of Determination or R-squared.      Measurment to defined how close the data fit the regression line.       R-squared is the percentage of variation of the traget variable (Y) that is explained by the linear model.      Comparing a regression model to a simple model is the mean of the data points.      R^2 = (1 - (MSE of regression line/MSE of the average of the data))Coefficient of Determination (R^2)      The blue line represents the regression line.R-squared = Explained variation / Total variationR-squared is always between 0 and 100%:MSE is close to zero is good fit because the numerator is small and error is small.<jupyter_code>lm.score(X,Y) # R^2 (coefficient of determination) regression   
df = dataset.drop(['Open','High','Low','Close','Volume'], axis=1)
df.head()
plt.plot(df)<jupyter_output><empty_output><jupyter_text>Out-of-Sample Data Create new data (forecast)<jupyter_code>import pandas as pd
from fbprophet import Prophet
data = dataset.reset_index()
data = data.drop(['Open','High','Low','Close','Volume'], axis=1)
new_df = data.rename(columns={'Date':'ds', 'Adj Close':'y'})
new_df.head()
# Python
m = Prophet(daily_seasonality=True)
m.fit(new_df)
Out_of_Sample = m.make_future_dataframe(periods=365)
Out_of_Sample.head()
Out_of_Sample.tail()
forecast = m.predict(Out_of_Sample)
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
fig1 = m.plot(forecast)
fig2 = m.plot_components(forecast)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11464968152866242, 'fraction_numerical': 0.017234919445485202, 'mean_word_length': 5.449275362318841, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '276648', 'license': 'MIT', 'n_tokens_mistral': 947, 'n_tokens_neox': 879, 'n_words': 269, 'path': 'In_Sample_Out_Sample.ipynb', 'repo_name': 'sonukumarraj007/Deep-Learning-Machine-Learning-Stock', 'size': '2669'}