Machine Learning: Predicting Stock Prices with Linear Regression
A machine learning project to predict Stock Prices using the Python libraries like Pandas, Numpy, SKlearn and Plotly.

Project overview
- This is a machine learning project of the Tesla stock price dataset (from 2020 to 2022).
- A linear regression method was used to predict the prices using historic values as reference.
- The project was made for educational purpose and his values are not an investment advice
- The tools used are the next Python libraries: Pandas, Numpy, Plotly and Sk-Learn.
- All the procedures are recorded in a Jupyter Notebook.
- The prices was obtained from the Yahoo Finance API
- All the files can be downloaded from my GitHub Repository.
Objectives
The goal was to train a machine learning model that tries to predict Tesla (TSLA) stocks prices in a range of the two past years to understand how the pandemic is currently affecting the performance of the company.
Data transformation and preparation
All the data was taken from Yahoo Finance API as a CSV file.
Data Analysis
Candle Chart
 Adjusted Close
 Volume
 Market Capitalization
 Volatility
 Moving Averages (50-200 days)
 Machine Learning
Linear Regression Model
 Conclusions
- The adjusted close price had a positive slope in the period of study.
- The all time high value was 1243$ at 2021-11-04.
- The all time low value was 70$ at 2020-03-18.
- The max volume was 304M$ at 2020-02-04, it had a spike in February, July and December of 2020.
- The Market capitalization had his highest value in December 18, 2020.
- The volatility was around 5% per day.
- The 50-200 days averages were positive most of time.
- If we would have invested in the TSLA stock, at start 2020, we had today a return of 800%.
- The machine learning model has around 98% of accuracy for predicting test values.
- This model is only used for educational purpose. In reality, the market volatility makes extremely difficult to anticipate the rise and fall of the stocks.