<jupyter_start><jupyter_text>Google stock prediction using linear regression  We will use quandl to get the dataset<jupyter_code>import pandas as pd
import quandl
df=quandl.get('WIKI/GOOGL')<jupyter_output><empty_output><jupyter_text>Lets check out how the data looks like.- So lets print first 5 rows.<jupyter_code>df.head()
df.columns<jupyter_output><empty_output><jupyter_text>**Okay so we have some columns out here.There are 2 columns that should be added by us to make good predictions.**- one column that we should add is change in stocks which is described below as 'Change'- and other column we should add is percentage change in high and close columns described by 'High_low_percent'<jupyter_code>df=df[['Adj. Open', 'Adj. High', 'Adj. Low', 'Adj. Close', 'Adj. Volume']]
df['Change']=(df['Adj. Close']-df['Adj. Open'])/df['Adj. Open']
df['High_low_percent']=(df['Adj. High']-df['Adj. Close'])/df['Adj. Close']
df=df[['Adj. Volume','Adj. Close','Change','High_low_percent']]
df.head()<jupyter_output><empty_output><jupyter_text>Shifting out 1% data upwards<jupyter_code>prediction_shift=int(0.01*len(df))
prediction_shift
temp_variable='Adj. Close'<jupyter_output><empty_output><jupyter_text>defining labels<jupyter_code>df['labels']=df[temp_variable].shift(-prediction_shift)
df.head()
from sklearn import preprocessing,cross_validation,svm
from sklearn.linear_model import LinearRegression<jupyter_output><empty_output><jupyter_text>Finally we define features and labels for prediction<jupyter_code>import numpy as np
X=df[['Adj. Volume','Adj. Close','Change','High_low_percent']]
Y=df['labels']
# X=np.array(df.drop(['labels']))
# Y=np.array[df['labels']]
X.head()
Y.head()
X=(X-X.max())/(X.max()-X.min())
X.head()<jupyter_output><empty_output><jupyter_text>Dropping nan<jupyter_code>Y.dropna(inplace=True)
Y.isnull().sum()
print(len(X),len(Y))<jupyter_output>3424 3390<jupyter_text>We are making sure that we have features only for the labels we had as we shifted the labels up by prediction_shift<jupyter_code>X=X[:-prediction_shift]
print(len(X),len(Y))
print(X.isnull().sum(),Y.isnull().sum())
print(len(X),len(Y))
X_train=X[:2900]
Y_train=Y[:2900]
print(len(X_train),len(Y_train))
X_test=X[2901:]
Y_test=Y[2901:]
# X_train,X_test,Y_train,Y_test=cross_validation.train_test_split(X,Y)
clf=LinearRegression()
clf.fit(X_train,Y_train)

clf.score(X_test,Y_test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15634095634095635, 'fraction_numerical': 0.012474012474012475, 'mean_word_length': 8.740890688259109, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '296678', 'license': 'MIT', 'n_tokens_mistral': 934, 'n_tokens_neox': 907, 'n_words': 182, 'path': 'Regression.ipynb', 'repo_name': 'jb1998/Stock-prediction', 'size': '2405'}