import quandl as Quandl, math
import numpy as np
import pandas as pd
from sklearn import preprocessing, model_selection as cross_validation, svm
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
from matplotlib import style
import datetime
import pickle
style.use('ggplot")
def get_data():
df = Quandl.get("WIKI/AMZN",api_key='tJbUksb_TeZXtwAgDeia')
return df
df = get_data()
#print(df.head(5))
def preprocess_data(df):
#taking Adj. Open, Adj. High, Adj. Low, Adj. Close, Adj. Volume from dataframe
df = df[['Adj. Open', 'Adj. High', 'Adj. Low', 'Adj. Close', 'Adj. Volume']]
#calculating the high low percentage
df['HL_PCT'] = (df['Adj. High'] - df['Adj. Low']) / df['Adj. Low'] * 100.0
#calculating high low percentage
df['PCT_change'] = (df['Adj. Close'] - df['Adj. Open']) / df['Adj. Open'] * 100.0
#adding HL_PCT, PCT_change to the dataframe
df = df[['Adj. Close', 'HL_PCT', 'PCT_change', 'Adj. Volume']]
df.fillna(value=-99999, inplace=True)
df.dropna(inplace=True)
return df
df = preprocess_data(df.head(100))
#print(df)
def pred_split(df):
forecast_col = 'Adj. Close'
#calculating the forecast_out
forecast_out = int(math.ceil(0.01 * len(df)))
df['label'] = df[forecast_col].shift(-forecast_out)
X = np.array(df.drop(['label'], 1))
#assign the X_testtrain data
X_testtrain= X[:-forecast_out]
#assign the X_pred data
X_pred= X[-forecast_out:]
y = np.array(df['label'])
#assign the y_testtrain data
y_testtrain = y[:-forecast_out]
#assign the y_pred data
y_pred = y[-forecast_out:]
return X_pred,y_pred,X_testtrain,y_testtrain
X_pred,y_pred,X_testtrain,y_testtrain = pred_split(df.head(100))
#print(len(X_pred))
#print(len(y_pred))
#print(len(X_testtrain))
#print(len(y_testtrain))
def split(X_testtrain,y_testtrain):
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X_testtrain, y_testtrain, test_size=0.2)
return X_train, X_test, y_train, y_test
X_train, X_test, y_train, y_test = split(X_testtrain,y_testtrain)
#print(len(X_train))
#print(len(X_test))
#print(len(y_train))
#print(len(y_test)
def train(X_testtrain,y_testtrain):
model = LinearRegression(n_jobs=-1)
model.fit(X_testtrain,y_testtrain)
m=model.coef_
b=model.intercept_
return m,b,model
m,b,model = train(X_testtrain,y_testtrain)
print("coeff,intercept",m,b)
#model = train(X_train,y_train)
#print(model)
def test(X_testtrain,y_testtrain):
confidence = model.score(X_testtrain, y_testtrain)
return confidence
confidence = test(X_testtrain,y_testtrain)
#print('Confidence:', confidence)
def predict(X_pred):
#find the future prediction values
y_predict = model.predict(X_pred)
return y_predict
y_predict=predict(X_pred)
#print("predict values",y_predict)
i wrote above code
i need unittest cases for the above code for each function
please help me with test cases