Skip to content

kinshuksinghbist/btc-prediction-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


🚀 BTC/USDT Prediction API with Docker and Flask

Docker Flask Python Joblib yFinance

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.

📋 Table of Contents

✨ Features

  • 📊 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.

🛠️ Tech Stack

  • 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.

📂 Project Structure

.
├── 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

🐳 Docker Setup

  1. Install Docker: Make sure you have Docker installed on your system. You can download it here.

  2. Build the Docker Image:

    docker build -t btc-prediction-api .
  3. Run the Docker Container:

    docker run -d -p 5000:5000 btc-prediction-api
  4. The API will now be available at http://localhost:5000.

⚙️ Installation

  1. Clone the repository:

    git clone https://github.com/kinshuksinghbist/btc-prediction-api.git
  2. Navigate to the project directory:

    cd btc-prediction-api
  3. Install dependencies:

    pip install -r requirements.txt
  4. Run the Flask app locally:

    python app.py

The API will now be running locally at http://localhost:5000.

🚀 Usage

Once the API is up and running, you can use the following endpoint:

GET /

Fetches the latest Bitcoin data and returns a prediction based on the pre-trained model.

Example Request:

curl http://localhost:5000/

Example Response:

{
    "predictions": [1, -1, 1, 1, -1, 1]
}

📈 API Endpoints

HTTP Method Endpoint Description
GET / Returns predicted Bitcoin price moves

🏗️ Model & Preprocessing

  • 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.

🤝 Contributing

We welcome contributions! To get started:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Make your changes.
  4. Push to your branch and submit a pull request.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published