Stock Price Prediction Using Machine Learning:

In This Blog, We See A Novel Approach For Predicting Stock Prices and Trend.

Shashank G
7 min readNov 7, 2020

In this blog we can how machine learning helps and how it plays major role in predicting the stock trend .

Predicting Stock price is quite difficult because market moves randomly and makes volatile moves and factors that trader depend upon predicting the price of the stock are Technical Analysis , Fundamental Analysis and Psychological Factor. Fundamental analysis is the analysis of financial state ,health and competitors and markets and Considering the overall state economy of his country index. Technical Analysis interpretation of price action in a stock and the study of the historical data of stocks, including volume and price of the stock. Psychological Factor studied which are overconfidence, conservatism, herding attitude and Greedy behavior of the Trader.

In basic terms, machine learning is the method and process of teaching a computer system how to make accurate predictions when we fed the data to the computer or a model and in this case we try to feed the past price data of stock and teach and to get tentative future trend of stock.

The main task is we try to predict the future trend by using the historical data of data and we try to train the ml model with available back -testing data of the stock to get future trend approximately.

The programming language is used to predict the stock market using machine learning is Python and As there are many ML algorithms like KNN, Recurrent Neural Network, LSTM, Reinforcement learning to predict the stock trend as of now we are using the most basic and widely used machine learning algorithm “linear regression” on dataset.

Introduction:

• Stock Market Prediction is the act of trying to determine the future values of company stock or other

• Stock market prediction is basically defined as trying to determine the stock value and offer a robust idea for the people to know and predict the market and the stock prices. It is generally presented using the quarterly financial ratio using the dataset.

• The use of machine learning and artificial intelligence techniques to predict the prices of the stock is an increasing trend.

OBJECTIVE:

The main objective of this project is to find the best model to predict the value of the stock market.

•During the process Of considering various techniques and variables that must be taken into account, we found out that techniques like random forest, support vector machine were not exploited fully.

•In, this blog we are going to present and review a more feasible method to predict the stock movement with higher accuracy. This blog also presents a machine-learning model to predict the longevity of stock in a competitive market.

The successful prediction of the stock will be a great asset for the stock market institutions and will provide real-life

DATASET USED:

Choosen Stock: Tesla

Web Url: https://finance.yahoo.com/chart/TSLA/

Libraries

1.scikit-learn:

Scikit-learn is an open source machine learning library which supports supervised and unsupervised learning. It also provides various tools for model fitting, data preprocessing, model selection and evaluation.

2.Pandas:

pandas is an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language.

STEPS:

1. The first thing we have taken into account is the dataset of the stock market prices from previous year. The dataset was pre-processed and tuned up for real analysis.

2. Secondly, after preprocessing the data, we will review the use of random forest, support vector machine on the dataset and the outcomes it generates. In addition, the proposed paper examines the use of the prediction system in real-world settings and issues associated with the accuracy of the overall values given.

SYSTEM ARCHITECTURE

The Steps of system architecture are:

  1. Raw Data
  2. Feature Extraction
  3. Training Data
  4. Testing Data
  5. Trained Data Result
  6. Predicted Stock Price

Concepts Involved :

While Predicting Stock Price Prediction Using Machine Learning the concepts and techniques involved are;

Regression:

“Regression analysis is a form of predictive modelling technique which investigates the relationship between a dependent and independent variable”

Uses of Regression

Three major uses for regression analysis are

•Determining the strength of predictors

•Forecasting an effect

•Trend forecasting

Linear Regression:

The core concept is data is modelled using a straight Line and used with continuous Variable and the output /prediction is most like to be value of the variable.

More ever, Linear Regression Accuracy and Goodness of Fit id measured by Loss, R Squared, Adjusted R squared etc.

Selection Criteria:

• Classification and Regression Capabilities

Data Quality

•Computational Complexity

• Comprehensible and Transparent

MODULE IDENTIFICATION

1. Data Collection

Data collection is a very basic module and the initial step towards the project. It generally deals with the collection of the right dataset. The dataset that is to be used in the market prediction has to be used to be filtered based on various aspects. Data collection also complements to enhance the dataset by adding more data that are external. Our data mainly consists of the previous year stock prices

Data pre-processing is a part of data mining, which involves transforming raw data into a more coherent format. Raw data is usually, inconsistent or incomplete and usually contains many errors. The data pre-processing involves checking out for missing values, looking for categorical values, splitting the data set into training and test set and finally do a feature scaling to limit the range of variables so that they can be compared on common environs.

2. Pre Processing

Data pre-processing is a part of data mining, which involves transforming raw data into a more coherent format. Raw data is usually, inconsistent or incomplete and usually contains many errors. The data pre-processing involves checking out for missing values, looking for categorical values, splitting the data set into training and test set and finally do a feature scaling to limit the range of variables.

3. Training the Machine

Training the machine is similar to feeding the data to the algorithm to touch up the test data. The training sets are used to tune and fit the models. The test sets are untouched, as a model should not be judged based on unseen data. Hence, it is divided in the ratio of 80:20 where 80% is for the training set and the rest 20% for a testing set of the data.

4.Data Scoring

The process of applying a predictive model to a set of data is referred to as scoring the data. The technique used to process the dataset is the Random Forest Algorithm. Random forest involves an ensemble method, which is usually used, for classification and as well as regression. The user authentication system control is implemented to make sure that only the authorized entities are accessing the results

The Following ML Model forecast the closing prices of Tesla Stock:

  1. First we load the dependencies pandas and numpy and we import the sklearn library for performing the linear Regression model and import matplotlib for ploting and styling the chart.
  2. We choose the data set and here we have choosen the “TESLA” stock dataset from yahoo finance source.
  3. Further we process the data ‘x’ as High ,Low ,Open ,Volume and ‘y’ as Close value of stock.
  4. For training the model we Split training data as 80% and test data as 20%.

5. Visualizing the close Price Data and under going the Linear regression and Creating a variable to Predict ‘x’ days out into the future

6.Create the Feature data set (X) AND Convert it to a numpy array and remove the the Last’x’ rows/days.

7.Similarly, Create the Target data set (y) AND Convert it to a numpy array and get all the target values expect the Last ‘x’ rows/days.

8. Creating the model and Creating the decision tree regression model and finally, visualizing the forecast upcoming close Price Data of the stock price.

RESULTS:

  • The “Purple Line chart” Represent the Predicted Price of Tesla Stock.

Thank You.

--

--