This project contains a machine learning-based cryptocurrency prediction API using Flask, Docker, and a pre-trained joblib
model. The API retrieves recent Bitcoin data using the yfinance
library, performs preprocessing, and serves predictions through a simple REST interface.
- 📊 Bitcoin price prediction using a pre-trained machine learning model.
- 🔧 Preprocessing pipeline including log returns, lags, and binning of features.
- 🛠️ Dockerized application for easy deployment and scalability.
- ⚡ Flask API to serve predictions via HTTP.
- 🧠 Model storage using
joblib
for fast and efficient prediction serving.
- Flask - Python micro-framework to serve the API.
- Joblib - Efficient serialization of the trained machine learning model.
- yFinance - Data retrieval for cryptocurrency (Bitcoin) prices.
- Docker - Containerization for portability and easy deployment.
.
├── Dockerfile # Dockerfile to build the API container
├── app.py # Flask API implementation
├── RF_BTC_1D.joblib # Pre-trained machine learning model
├── requirements.txt # Dependencies for the project
└── README.md # Project documentation
-
Install Docker: Make sure you have Docker installed on your system. You can download it here.
-
Build the Docker Image:
docker build -t btc-prediction-api .
-
Run the Docker Container:
docker run -d -p 5000:5000 btc-prediction-api
-
The API will now be available at
http://localhost:5000
.
-
Clone the repository:
git clone https://github.com/kinshuksinghbist/btc-prediction-api.git
-
Navigate to the project directory:
cd btc-prediction-api
-
Install dependencies:
pip install -r requirements.txt
-
Run the Flask app locally:
python app.py
The API will now be running locally at http://localhost:5000
.
Once the API is up and running, you can use the following endpoint:
Fetches the latest Bitcoin data and returns a prediction based on the pre-trained model.
curl http://localhost:5000/
{
"predictions": [1, -1, 1, 1, -1, 1]
}
HTTP Method | Endpoint | Description |
---|---|---|
GET |
/ |
Returns predicted Bitcoin price moves |
- Data Retrieval: We use the
yfinance
library to retrieve Bitcoin data for the past 19 days. - Preprocessing: The model applies several transformations to the data:
- Log Returns: Calculates the log of the price changes.
- Lags: Adds lag features to capture temporal dependencies.
- Binning: Converts continuous features into bins to make predictions easier.
The model is pre-trained and saved in the RF_BTC_1D.joblib
file. It's a Random Forest classifier that predicts the future direction of Bitcoin price changes.
We welcome contributions! To get started:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes.
- Push to your branch and submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.