How to predict Bitcoin price using Machine Learning and Python

Manpreet Singh
6 min readApr 28, 2021

Welcome back! A few weeks ago I walked through some methods on predicting stock prices using Machine Learning and Python, we also hit on how to essentially do the same thing with Doge Coin, now let’s try to do the same thing with Bitcoin. Now, this is a pretty high level walkthrough, this is not a full tutorial on learning Machine Learning, more so looking at some capability that Machine Learning may have. First off, we’re going to be using Google Colab to run this code, luckily for us this code was pretty much already developed, please give all the credit to this website for the code, I did add a little bit more functionality with the attached code! Here is the link to access the Google Colab project, you can also copy the code over to your Python IDE if you prefer.

Quick Note: This is a somewhat advanced tutorial, I’m assuming you know you’re way around Python / Object Oriented Programming, a bit of Machine learning, and familiarity with Pandas / Numpy. I have tutorials that should bring you up to speed, but here’s a Basic introduction to Machine Learning that I wrote up, okay now let’s get started!

Importing / Installing the packages

As always we’re going to have to import these packages, we’re using numpy, pandas, matplotlib and SciKit-Learn as well as Yahoo’s finance packages, you can pip install these but since we’re using Google Colab these are already built in. We install these packages by doing this:

#INSTALL THESE PACKAGES IF NEEDED
!pip install yfinance
!pip install yahoofinancials

Now let’s import all of the packages we need, we do this by using the following statements:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.metrics import mean_absolute_error as mae
from sklearn.preprocessing import StandardScaler
import yfinance as yf
from yahoofinancials import YahooFinancials

Awesome! Next up we need to import the dataset, we do this by using the Yahoo finance package yf. command, this will allow us to download the data using the ticket symbol and date range, this is the following code to do so:

#CREATING THE DATAFRAME TO STORE DATA
df = yf.download('BTC-USD'…

--

--