Skip to content

MLcoderss/ML-project

Repository files navigation

layout title date author website category tags categories
post
Stock Prediction
2017-01-22 16:00:00 +0530
saketharsh
Project
summer16
project
ML
project

Machine learning Project

Stock Market Predictor

Summarised Description

This Project predicts closing value of a stock of a particular day in a market, given its value of opening, maximum, minimum and volume of a stock of that day.

  • The entire code has been written in Torch and Lua
  • This project implements the basic algorithms of Machine Learning.

Installation of Torch

This project uses Torch , a language particularly made for Machine Learning. Torch can be installed easily on linux from its terminal. I

Other module needed can be installed by using below commands.

$ luarocks install nn
$ luarocks install itorch
$ luarocks install image
$ luarocks install optim

The Data Set used for training the Neural Network can be found here. here.

Tutorials, Books and Links that we used

Here is the name and links of important persons and important stuffs.

Description

In total we have five main files:

Dataset description

The Dataset has been taken from other data repository ,which contains more than one lakh stocks of one year. Our dataset just contains 20,232 stocks of which 10,232 has been used as Training Set and remaining as Validation Set. We have ignored dates and tickers as they are not useful for us to calculate our desired output. One can see how we have done it in stock_function.lua.

fullset = database("Dataset.txt")	.
trainset = {
 size = 10232,
 data = fullset['datainput'][{{1,10232}}],
 label = fullset['dataoutput'][{{1,10232}}]
}
validationset = {
 size = 10000,
 data = fullset['datainput'][{{10233,20232}}],
 label = fullset['dataoutput'][{{10233,20232}}]
}

Here 'database' is an user defined function in file stock_function.lua which helps us to convert Dataset.txt to convert into a Double Tensor so that we can apply arithmetic operations on it.

Description of Model

Our model contains two hidden layer.One has 70 neurons and other one has 50 neurons.

 model = nn.Sequential()		
 model:add(nn.Linear(4,70))
 model:add(nn.Tanh())
 model:add(nn.Linear(70,50))
 model:add(nn.Tanh())
 model:add(nn.Linear(50,1))
 model:add(nn.Tanh())

This model applies Tanh function. Tanh is defined as f(x) = (exp(x)-exp(-x))/(exp(x)+exp(-x))

We have used MSECriterion(Mean Squared Error) for our loss function. Since we are not intersted in backpropagation. One can find about this criterion here.

criterion = nn.MSECriterion() 

Since we are optimizing our model through Stochastic Gradient we have used module "optim.sgd". The tutorial link is here

_, fs = optim.sgd(feval,x,sgd_params) 

The training set has been trained by "step" function.The code for it is simple and can be understood after going through the Turorials given above. We have used batches of batch_size = 200 .

eval function gives us accuracy calculated after testing validation set with the parameters we got after training trainingset in "step" function.

After iterating the same datasets for 200 times or (200 epochs) we have saved the final parameters of model in other file model.net. This helps us to use these parameters any other time without iterating over 200 times. This file has been used in files like final_output.lua and graph_output.lua.

ScreenShot

The final_ouput.lua , as the name itself says, gives us the closing stock value when given value of opening , highest , lowest and overall volume of a stock of a day as an input.

ScreenShot

The graph_ouput.lua gives us the graph between the predicted closing value and actual closing value .It also save the graph in home directory as a .png file.

ScreenShot

Contributors

Team Name = ML-Coderss

Team Membres :

Credits

Website

Our website is : http://mlcoderss.github.io/ML-project/

About

A project for face recognition

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages