how to write unittest cases for stock prediction data

0 votes
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


def get_data():
    df = Quandl.get("WIKI/AMZN",api_key='tJbUksb_TeZXtwAgDeia')
    return df
df = get_data()

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)
    return df
df = preprocess_data(df.head(100))

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))

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)

def train(X_testtrain,y_testtrain):
    model = LinearRegression(n_jobs=-1),y_testtrain)
    return m,b,model
m,b,model = train(X_testtrain,y_testtrain)

#model = train(X_train,y_train)

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
#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
Feb 20, 2020 in Python by Vasu
• 140 points

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

How to write inline if statement for print in Python?

Inline if-else expression must always contain the else ...READ MORE

answered Dec 4, 2018 in Python by Nymeria
• 3,520 points

edited Dec 6, 2018 by Nymeria 11,648 views
0 votes
1 answer

How to write data to a file in Python?

Refer to the below code. data=’whatever your data ...READ MORE

answered May 12, 2019 in Python by Shaam
0 votes
1 answer

How to write a python script for downloading a video from YouTube and saving it to a directory?

First download pytube using the following code  pip ...READ MORE

answered Sep 4, 2019 in Python by Neel
• 3,020 points
+2 votes
2 answers

How to use BeatifulSoup for webscraping?

your programme is fine until you start ...READ MORE

answered Apr 4, 2018 in Python by charlie_brown
• 7,780 points
+3 votes
5 answers

How to read multiple data files in python

Firstly we will import pandas to read ...READ MORE

answered Apr 6, 2018 in Python by DeepCoder786
• 1,720 points
+1 vote
4 answers

How to write nested dictionaries to a CSV file

Using DictWriter there is no need in ...READ MORE

answered Oct 18, 2018 in Python by Richard William
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,855 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points