Correlation Between Ticker Price and NASDAQ Price Prediction Using Python and Scikit Linearregression Model

Determination is likely being affected by one variant to one variable, or one variant to multiple variables. Machine makes decision based on maths. So in this article, I would walk through how to generate a price prediction score between a stock ticker and NASDAQ price correlation. I would show the methods using Python and Scikit Linear Regression model.

price prediction

Determination is likely being affected by one variant to one variable, or one variant to multiple variables. The machine makes decisions based on maths. So in this article, I would walk through how to generate a price prediction score between a stock ticker and NASDAQ price correlation. I would show the methods using Python and Scikit Linear Regression models.

Tables of Content: Correlation Between Stock Ticker Price and NASDAQ Price Prediction Using Python and Scikit Linearregression Model

Import required dataset and libraries

For counting the price prediction score, here are the Python libraries we need to import before the project starts.

import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split

from sklearn.linear_model import LinearRegression

Then, I take Apple stock price and Nasdaq over the past 7 years as the dataset sample

For a cbar visualization creation purpose, I create a price ratio between Apple stock price and Nasdaq price, which is Apple price historical daily price divided by Nasdaq’s historical daily price.

Data Preprocessing

As well as a common machine learning process, data preprocessing is critical as it ensures the data type and data size are consistent.

In this project, we have 3 pieces of the dataset, which are the Apple ticker, Nasdaq, and their ratio. As the raw dataset shared the same date range across each dataset, so we only need to reshape and ensure each dataset has the same data dimension.

apple_price = dataSet['AAPL']

appl_price = np.array(apple_price).reshape(-1,1)

indexQ_price = dataSet['NASDAQ']

index_price = np.array(indexQ_price).reshape(-1,1)

price1_ratio = dataSet['Ratio']

For the ratio, from my personal preference, I learned that without reshape shows more contrast in the plot visualization. Being said that you can reshape it as well. But in the article, I would use the original shape because it’s for showing the color map.

Linear regression model data training and test

For testing if the score result might be affected by the size of the data sample, we need to leverage Scikit Learn to split the dataset first. Here is the code sample for this project which has three datasets

apple_train, apple_test, nasdaq_train, nasdaq_test, priceRatio_train, priceRatio_test = train_test_split(

   appl_price, index_price, price1_ratio, test_size=0.5)

Test_size can be adjusted on and off to check which score result is close to each other or has a bigger contrast. In practical application, a proper score very depends on the project goal. Sometimes lower score can be a good signal for automation.

Model.fit() and generate the score

Now it’s ready to add the Linear regression model. I would suggest you run this section on a Cloud coding platform, like Google Collab. It’s because it normally needs a higher hardware specification requirement. Sometimes it might crash your laptop if your dataset is too large.

Then, along with adjusting the test_size, the score result can be different. Here shows one result I generated. I tried a few portions of the test, the result is very close to each other.

model = LinearRegression()

model.fit(apple_train, nasdaq_train)

print(model.score(apple_test, nasdaq_test))

Scatter plot visualization and 10 sets of correlation for your test

I’m not going to go deep dive to elaborate on how to use Matplotlib to visualize the dataset in a scatter plot. If you are interested in the details, please follow the next section and subscribe to use getting the full script.

Conversely, I like to share with you 10 sets of correlations in three professional areas you might be working in. They are a stock investment, e-commerce selling, and Google search advertising. You can collect the dataset you own or go to Kaggle to look it up accordingly to test the prediction score.

Stock Investment

  1. Correlation between stock price and trading volume
  2. Correlation between stock price and market index (e.g., S&P 500)
  3. Correlation between stock price and interest rates
  4. Correlation between stock price and earnings per share (EPS)
  5. Correlation between stock price and dividend yield
  6. Correlation between stock price and price-to-earnings (P/E) ratio
  7. Correlation between stock price and market capitalization
  8. Correlation between stock price and sector-specific index (e.g., technology sector index)
  9. Correlation between stock price and analyst recommendations (e.g., buy, sell, hold)
  10. Correlation between stock price and economic indicators (e.g., GDP growth, inflation rate)

eCommerce Selling

  1. Correlation between product price and sales volume
  2. Correlation between product rating and sales volume
  3. Correlation between product reviews count and sales volume
  4. Correlation between product discount and sales volume
  5. Correlation between product promotion duration and sales volume
  6. Correlation between product availability and sales volume
  7. Correlation between product shipping time and sales volume
  8. Correlation between product description length and sales volume
  9. Correlation between product image quality and sales volume
  10. Correlation between product category and sales volume

Google Search Advertising

  1. Correlation between ad position and click-through rate (CTR)
  2. Correlation between ad copy length and CTR
  3. Correlation between ad headline keywords and CTR
  4. Correlation between ad description keywords and CTR
  5. Correlation between ad display URL and CTR
  6. Correlation between ad relevance and CTR
  7. Correlation between ad landing page quality and conversion rate
  8. Correlation between ad bidding strategy and cost per click (CPC)
  9. Correlation between ad targeting settings (location, demographics) and conversion rate
  10. Correlation between ad scheduling and conversion rate

Full Python Script of Feature importance generator

If you are interested inCorrelation Between Ticker Price and NASDAQ Price Prediction Using Python and Scikit Linearregression Model, please subscribe to our newsletter by adding the message ‘scatter plot + price prediction’. We would send you the script immediately to your mailbox.

I hope you enjoy reading Correlation Between Ticker Price and NASDAQ Price Prediction Using Python and Scikit Linearregression Model. If you did, please support us by doing one of the things listed below, because it always helps out our channel.

Data Science & Machine Learning Couresa Course Recommendation