<jupyter_start><jupyter_text>Polynomial Regression in Stonktastic***  Summary:In Stonktastic, we use three machine learning algorithum: Polynomial Regression, Long-Term Short-Term Memory and Random Forest.Linear Regression in its most basic form is a process of finding a straight line that best represents a series of points in a graph. Polynomial Regression is much the same only that we allow for various degrees above two. This type of machine learning algorithum will generate a formula and begin a series of test and changes until the R^2 value of the line is as low as the algorithum can make it.   Stonktastic's use of Polynomial RegressionPolynomial Regression in Stonktastic uses sklearn's following libraries for machine learning calculations:- *linear_model* library for the core machine learning code as well as the ** and ** model for the pol- *preprocessing* : for the *Polynomial* feature and the *Min Max Scaler* library. Data SplitWe split the data not by randomly selecting 80/20 of the data to fall under Train/Test but instead cut off the last 20% to be used as the testing data itself.  Saving and LoadingTo save the data off after our initial calculations are preformed we use the *Pickle* library and save off the results of any calculations to the SQL lite database.  Variables and Optimization Variables looked atWe use two sets of variables in the Polynomial Regression. This includes which data points and what level of polynomial to use for calculations. The value of each is done by ranking options with the results/time taken to preform calculations.   Preping for Analysis<jupyter_code>import sys
sys.path.append('../')

import stonkCode
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

sampleNum = 200<jupyter_output><empty_output><jupyter_text>Pull Optimized Data DataFrame<jupyter_code>linRegOpt = stonkCode.optimization.runLinRegOptimization(stonkCode.config.stockToOpt)<jupyter_output>==========================
Linear Regression Optimization
==========================
SNP | Lin Reg Optimize Variable   : SAR, RSI, MACDHist, BBMiddleBand, BBLowerBand, EMA, Chaikin, StochD, Close, Date
SNP | Lin Reg Optimizd Poly Value : 2<jupyter_text>Linear Regression VariablesWe will be using the *Optimization* part of the script to look at the variables and graph the results of our choices  Exploring Subset of the Initial Variables<jupyter_code>df = linRegOpt.subDf
df.sort_values(by='score', ascending=False, inplace=True)
df = df.reset_index(drop=True)

print(f"Optimized Subset for Polynomial Regression : {', '.join(linRegOpt.optSubSet)}")<jupyter_output>Optimized Subset for Polynomial Regression : SAR, RSI, MACDHist, BBMiddleBand, BBLowerBand, EMA, Chaikin, StochD, Close, Date<jupyter_text>Explore Variable Weight<jupyter_code>linRegVariables = ["SAR","RSI","CCI","MACDHist", "BBUpperBand",
                    "BBMiddleBand","BBLowerBand","EMA", "Chaikin",
                    "StochK","StochD","WILLR"]
RowCount        = [0,0,0,0,0,0,0,0,0,0,0,0] 


linRegCounterDataframe = pd.DataFrame(RowCount,index=linRegVariables, columns=['Count'])

for idx, subsetList in enumerate(linRegOpt.subDf["subset"].values.tolist()):
    for variable in linRegVariables:
        if variable in subsetList:
            linRegCounterDataframe.at[variable,'Count'] = (  linRegCounterDataframe.at[variable, 'Count'] + int(len(linRegOpt.subDf) - idx)  )
            
linRegCounterDataframe.sort_values(by='Count', ascending=False, inplace=True)

#Normalize Data
lowestScore = linRegCounterDataframe['Count'].iloc[-1]
linRegCounterDataframe['Count'] = linRegCounterDataframe['Count'] - lowestScore

# Get percentages of Data
countSum = linRegCounterDataframe["Count"].sum()
linRegCounterDataframe['Count'] = linRegCounterDataframe['Count'].multiply((1/countSum)*100)

linRegCounterDataframe.drop(linRegCounterDataframe.tail(1).index, inplace = True)<jupyter_output><empty_output><jupyter_text>Exploring the relationship between number of variables and results<jupyter_code>g = sns.catplot(
    data=linRegCounterDataframe, kind="bar",
    x="Count", y=linRegCounterDataframe.index.values, palette="dark", alpha=0.8, height=6,
    legend=False
)
sns.set_theme(style="whitegrid")

cmap = sns.cubehelix_palette(rot=-.6, as_cmap=True)

g = sns.relplot(
    data=linRegOpt.subDf.sample(1000),
    x="results", y="time",hue="score",
    palette=cmap, s=20
)

g.set(xlim=(0.993, None))

g.set(yscale="log")
g.ax.xaxis.grid(True, "minor", linewidth=.25)
g.ax.yaxis.grid(True, "minor", linewidth=.25)
g.despine(left=True, bottom=True)<jupyter_output><empty_output><jupyter_text>Polynomial VariablesWe will be using the *Optimization* part of the script to look at the variables and graph the results of our choices. We want to know if the additional time required by the algorithum to preform the calculation using different power levels is worth the additional time and resource cost associated.<jupyter_code>linRegOpt.polyDf
g = sns.catplot(data=linRegOpt.polyDf, x="polyOption", y="score",kind="bar", alpha=0.8)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10181173690429303, 'fraction_numerical': 0.009649468294604176, 'mean_word_length': 5.81744966442953, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '419333', 'license': 'MIT', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1525, 'n_words': 496, 'path': 'notebooks/Documentation_Polynomial_Regression.ipynb', 'repo_name': 'aevear/Stonktastic', 'size': '5078'}