<jupyter_start><jupyter_text><jupyter_code># installing dependencies 
# The train_test_split function is for splitting a single dataset for two different
import numpy as np
import pandas as pd
from sklearn.tree import DecisionTreeRegressor
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
plt.style.use('bmh') 
from google.colab import files
uploaded = files.upload()
# store the data in a dframe
df = pd.read_csv('NFLX.csv', delimiter=',', header=None, skiprows=1, names=['Date','Open','High','Low','Close','Adj Close','Volume'])
df
# show the first 10 rows
df.head(10)
# Get number of trained days in dataset
df.shape
# Visualize the close price data 
plt.figure(figsize = (32, 8))
plt.title('Netflix Stock Price')
plt.xlabel('Days')
plt.ylabel('NFLX Close Price')
plt.plot(df['Close'])
plt.show()
# Get the Close price
df = df[['Close']]
df.head(10)
df.shape
# Predict n days into the future
future_days = 10
# Create a new column target data - Predict values n days away from current price
df['Prediction'] = df[['Close']].shift(-future_days)
df.head(4)
# check the end shift
df.tail(10)
# Create a feature dataset and create a numpy array and remove the NaN days/rows 
X = np.array(df.drop(['Prediction'], 1))[:-future_days]
print(X)


# Create target set
Y = np.array(df['Prediction'])[:-future_days]
print(Y)
# train and test ratio is 7:3
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size = 0.30)
# Create models
# Decision Tree Regressor model
tree = DecisionTreeRegressor().fit(x_train, y_train)
# Linear Regression Model
linr = LinearRegression().fit(x_train, y_train) 
# Get x rows on future data set
x_future = df.drop(['Prediction'], 1)[:-future_days]
x_future = x_future.tail(future_days)
x_future = np.array(x_future)
x_future
# Prediction model for Decision Tree Regressor
tree_prediction = tree.predict(x_future)
print(x_future)
# Prediction model for Linear Regression model
linear_prediction = linr.predict(x_future)
print(x_future)
# Visualize the data
predictions = tree_prediction

valid = df[X.shape[0]:]
valid['Predictions'] = predictions
plt.figure(figsize = (32, 8))
plt.title('Decision Tree Model')
plt.xlabel('Days')
plt.ylabel('NFLX Close USD($)')
plt.plot(df['Close'])
plt.plot(valid[['Close', 'Predictions']])
plt.legend(['Org', 'Val', 'Pred'])
plt.show()
# Visualize the data 
predictions = linear_prediction

valid = df[X.shape[0]:]
valid['Predictions'] = predictions
plt.figure(figsize = (32, 8))
plt.title('Decision Tree Model')
plt.xlabel('Days')
plt.ylabel('NFLX Close USD($)')
plt.plot(df['Close'])
plt.plot(valid[['Close', 'Predictions']])
plt.legend(['Org', 'Val', 'Pred'])
plt.show()<jupyter_output>/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:5: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  """
{'fraction_non_alphanumeric': 0.13866494679135763, 'fraction_numerical': 0.010641728474685586, 'mean_word_length': 6.018099547511312, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '465817', 'license': 'Apache-2.0', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1050, 'n_words': 296, 'path': 'NFLX.ipynb', 'repo_name': 'narc-kany/Netflix-Stock-Price-Prediction', 'size': '3101'}