<jupyter_start><jupyter_text>Intro<jupyter_code>import pandas as pd
import quandl
import math
# numpy is a computing library. impporting to be able to use arrays
import numpy  as np 
# preprocessing to scale data on the features, goal is to get features in between -1 and 1
# svm == support vector machines
# model_selection to create training and testing samples
from sklearn import preprocessing, svm, model_selection
from sklearn.linear_model import LinearRegression
df = quandl.get('WIKI/GOOGL')
df.head()
df = df[['Adj. Open', 'Adj. High', 'Adj. Low', 'Adj. Close', 'Adj. Volume']]
df.head()
# Create a new column: Percent Volotility
df['HL_PCT'] = (df['Adj. High'] - df['Adj. Low']) / df['Adj. Low'] * 100
df.head()
# Create column for daily percent change
df['PCT_change'] = (df['Adj. Close'] - df['Adj. Open']) / df['Adj. Open'] * 100
df.head()
df = df[['Adj. Close', 'HL_PCT', 'PCT_change', 'Adj. Volume']]
df.head()<jupyter_output><empty_output><jupyter_text>Regression Features and Labels<jupyter_code>forcast_col = 'Adj. Close'
# in Pandas na can == NaN
# replace NaN with a - in order not to sacrafice data, and treat it as an outlier
df.fillna(-99999, inplace=True)
# Generally we use regression to forcast out
# Here we're trying to predict 1% of the df
forcast_out = int(math.ceil(0.01*len(df)))
print(forcast_out)
# what print is days in advance
# columns will be shifted up
# this way the 'labels' column for each row will be the Adj. Close price 1 day into the future
df['labels'] = df[forcast_col].shift(-forcast_out)
df.dropna(inplace=True)
df.head()<jupyter_output><empty_output><jupyter_text>Regression Training and Testing<jupyter_code># Defined features will be a capital X
# Features are everything except the label column
# df.drop() automatically returns a new df
#  1 == columns, 0 == index
X = np.array(df.drop(['labels'], 1))
# Labels will be a lower case y
y = np.array(df['labels'])

# Here we're scaling X before we feed it through the classifier
X = preprocessing.scale(X)
y = np.array(df['labels'])

print(len(X), len(y))
# training and testing X and y
# test_size is == to 20% of the data that we want to use as testing data
X_train, X_test, y_train, y_test = model_selection.train_test_split(X, y, test_size=0.2)

# for X_train and y_train, we use to fit our classifiers
classifier = LinearRegression(n_jobs=-1)
# to fit or train a classifier
classifier.fit(X_train, y_train)
# fit is synonomys with train, score is synonomys with test
accuracy = classifier.score(X_test, y_test)

# we want to train and test on seperate data 
# with LinearRegression the accuracy is the squared error
print(accuracy)
# Using SVM instead of LinearRegression
classifierSVM = svm.SVR(kernel='poly')
accuracySVM = classifier.score(X_test, y_test)
print(accuracySVM)<jupyter_output>1.0
{'fraction_non_alphanumeric': 0.11349036402569593, 'fraction_numerical': 0.009992862241256246, 'mean_word_length': 5.133479212253829, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '504457', 'license': 'MIT', 'n_tokens_mistral': 985, 'n_tokens_neox': 943, 'n_words': 342, 'path': 'regression.ipynb', 'repo_name': 'misskellymore/Machine-Learning-With-Python', 'size': '2802'}