<jupyter_start><jupyter_text><jupyter_code>import warnings
warnings.filterwarnings('ignore')
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import pandas_datareader as web
plt.style.use('seaborn-darkgrid')
plt.rc('figure', figsize=(18,8))
plt.rc('lines', markersize=4)
plt.rc('font', size=18)
!rm -rf ./logs/
%load_ext tensorboard
from sklearn.datasets import fetch_openml
import tensorflow as tf
from tensorflow import keras<jupyter_output>The tensorboard extension is already loaded. To reload it, use:
  %reload_ext tensorboard<jupyter_text>![OIP.jpg](data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAsJCQcJCQcJCQkJCwkJCQkJCQsJCwsMCwsLDA0QDBEODQ4MEhkSJRodJR0ZHxwpKRYlNzU2GioyPi0pMBk7IRP/2wBDAQcICAsJCxULCxUsHRkdLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCz/wAARCAC0AQgDASIAAhEBAxEB/8QAGwAAAgMBAQEAAAAAAAAAAAAAAAECAwYEBQf/xABIEAACAQMDAAcDBwYKCwAAAAAAAQIDBBEFEiEGEzFBUXF0NWGyFCIyNJGxsxVzgZOhwxYjJERScsHR0uElQlRVY2SEkqLw8f/EABsBAAMBAQEBAQAAAAAAAAAAAAECAwQABgUH/8QAKxEAAwACAgEDAgYCAwAAAAAAAAECAxEEEhMFITEjQSQ0YXGBkTLBUfDx/9oADAMBAAIRAxEAPwCfPiHPiAcnp2jEmHPiHPiHICtDphlhz4gArQ6Ychl+IATaKKg58Q5ABSiYc+Ic+IAI0UTDnxDL8Rcj5EaKJhl+IZYAI<KEY>)<jupyter_code>intel = web.DataReader('INTC', data_source='yahoo', start='2012-01-01', end='2019-12-31')
intel
plt.title('Intel Stock Price ($)')
plt.xlabel('Open Stock Price ($)')
plt.ylabel('Close Stock Price ($)')
plt.scatter(intel['Open'],intel['Close'])
plt.show()
plt.title('Intel Stock Price ($)')
plt.xlabel('Years')
plt.ylabel('Close Stock Price ($)')
plt.plot(intel['Close'])
plt.show()
intel = intel[['Close']]
intel.head()
futuredays = 50
intel['prediction'] = intel[['Close']].shift(-futuredays)
intel
x = np.array(intel.drop(['prediction'], 1))[:-futuredays]
x
y =np.array(intel['prediction'])[:-futuredays]
y
from sklearn.model_selection import train_test_split
x_train,x_test, y_train,y_test = train_test_split(x,y, test_size=0.25)
from sklearn.linear_model import LinearRegression
from sklearn.tree import DecisionTreeRegressor
linear = LinearRegression().fit(x_train, y_train)
tree = DecisionTreeRegressor().fit(x_train,y_train)
x_future = intel.drop(['prediction'], 1)[:-futuredays]
x_future = x_future.tail(futuredays)
x_future = np.array(x_future)
x_future
linear_prediction = linear.predict(x_future)
tree_prediction = tree.predict(x_future)
predictions = linear_prediction
valid = intel[x.shape[0]:]
valid["Predictions"] = predictions
plt.title("Intel Stock Price Prediction Model(Linear Regression Model)")
plt.xlabel("Days")
plt.ylabel("Close Price USD ($)")
plt.plot(intel["Close"])
plt.plot(valid[["Close", "Predictions"]])
plt.legend(["Original", "Valid", "Predictions"])
plt.show()
predictions = tree_prediction
valid = intel[x.shape[0]:]
valid["Predictions"] = predictions
plt.title("Intel Stock Price Prediction Model(Decision Tree Regressor Model)")
plt.xlabel("Days")
plt.ylabel("Close Price USD ($)")
plt.plot(intel["Close"])
plt.plot(valid[["Close", "Predictions"]])
plt.legend(["Original", "Valid", "Predictions"])
plt.show()
plt.title('Intel Stock Price in Future($) by Linear')
plt.xlabel('Futuredays Days')
plt.ylabel('Close Stock Price($)')
plt.plot(linear_prediction)
plt.title('Intel Stock Price in Future($) by Tree')
plt.xlabel('Futuredays Days')
plt.ylabel('Close Stock Price($)')
plt.plot(tree_prediction)
sns.pairplot(intel)
sns.distplot(linear_prediction)
sns.distplot(tree_prediction)
intel.corr()
sns.heatmap(intel,cmap='rainbow')
from sklearn import datasets, linear_model
from sklearn.metrics import mean_squared_error, r2_score
regr = linear_model.LinearRegression()
regr.fit(x_train,y_train)
y_pred = regr.predict(x_test)
print('coefficient: \n', regr.coef_)
print('Mean squared Erroe: %2f' % mean_squared_error(y_test, y_pred))
print('Coefficient of determination: %.2f' % r2_score(x_test, y_pred))
plt.scatter(x_test, y_test, color='blue')
plt.plot(x_test, y_pred, color='red', linewidth=3)
from mpl_toolkits.mplot3d import Axes3D
 
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x_test, y_test, marker='.', color='blue')
ax.set_title("3D Linear Regression")
ax.set_xlabel("X1")
ax.set_ylabel("X2")
ax.set_zlabel("y")
plt.plot(x_test, y_pred, color='red', linewidth=1)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1428904428904429, 'fraction_numerical': 0.017715617715617717, 'mean_word_length': 9.314903846153847, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '113172', 'license': 'BSL-1.0', 'n_tokens_mistral': 1829, 'n_tokens_neox': 1707, 'n_words': 271, 'path': 'intel_stock_predict.ipynb', 'repo_name': 'ashok2216-A/Data_Analytics', 'size': '9164'}