# Machine Learning Algorithm To Predict Stock Direction

Machine Learning Algorithm To Predict Stock DirectionIn 2014 the Robinhood Commision free trading app opened up for business..Fast forward 4 years later, and now I set to apply quantitative techniques to determine stock price direction in order to turn a profit.GoalsThis post will teach the reader how to apply ML techniques to predict stock price direction..In addition, it will shed light on how to use the repository’s backtesting module for use with your own algorithms.bballboy21/stock_surfaceMachine Learning Algorithm To Predict Stock Direction — bballboy21/stock_surfacegithub.comHigh School Math → Machine LearningMostly everyone in high school had some sort of class where they took observations (maybe measuring the height of a plant over time in biology class).Here is an example of plant height data.Let’s plot the data:Then in class, you would be asked to add a trend line (blue dotted line)..Our input data points are now called features and what we’re predicting/measuring are our target values.In our problem of predicting stock direction, we aren’t looking at something like height that can take on any number 0 to +infinity..Now our table looks more like it could be our stock data.Now, our goal is to train a model where we could give it a new unseen feature set and have it predict the price direction for some future target date.ex: [5, 0.6, 7] → 1, [4, 0.3, 8] → -1Background — ML TechniquesNote: This module is written in Python and uses the Scikit-learn library..Unsupervised learning is when the feature set doesn’t come with target values, and the algorithm’s goal is to group the input data based on the different features of the input data..Supervised learning is when the target values are provided for each of the feature sets..The price can stay the same, but we’re counting this as a negative outcome in this case.The module lets the user input their own custom feature sets, and it matches them up to a target value, +1 stock goes up -1 stock goes down, for a specified amount of days into the future..The moving average data will be the feature set and the binary outcome (price direction up or down) will be the target value..Then, the module pipeline generates a model that can be used to predict the stock price direction on a new unseen set of data.Let’s Get CodingFirst, we need to fetch the stock data..The module only takes into account daily stock closing prices; however, you can modify it to use different types of data.Selecting A Feature SetOne of the most important parts of any machine learning algorithm is the selection and manipulation of data into a feature set you believe is correlated with what you are trying to predict..In this case, the target value would be -1 since the stock price dropped over the next two days (blue cell → green cell).Plugging In The Machine LearningNow that we have our feature set and our target values associated with our feature set, let’s train a supervised learning algorithm to predict price direction based on our feature sets.. More details