<jupyter_start><jupyter_text>Stochastic Gradient Descent Regression Part 2<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

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 = dataset.reset_index()
dataset['Increase_Decrease'] = np.where(dataset['Volume'].shift(-1) > dataset['Volume'],'Increase','Decrease')
dataset['Buy_Sell_on_Open'] = np.where(dataset['Open'].shift(-1) > dataset['Open'],1,0)
dataset['Buy_Sell'] = np.where(dataset['Adj Close'].shift(-1) > dataset['Adj Close'],1,0)
dataset['Return'] = dataset['Adj Close'].pct_change()
dataset = dataset.dropna()
dataset.head()
dataset.tail()
dataset.shape
from sklearn.linear_model import SGDRegressor
X = np.array(dataset['Open']).reshape(1171,-1)
Y = np.array(dataset['Adj Close']).reshape(1171,-1)
sgd = SGDRegressor()
sgd.fit(X, Y)
sgd.coef_
sgd.intercept_ 
sgd.predict(Y)
from sklearn.metrics import r2_score # Continous and Binary
r2_score(X,Y)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1547911547911548, 'fraction_numerical': 0.029484029484029485, 'mean_word_length': 6.935064935064935, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '395935', 'license': 'MIT', 'n_tokens_mistral': 477, 'n_tokens_neox': 449, 'n_words': 90, 'path': 'Stock_Algorithms/Stochastic_Gradient_Descent_Regression_Part2.ipynb', 'repo_name': 'clairvoyant/Deep-Learning-Machine-Learning-Stock', 'size': '1221'}