This repository contains a machine learning API project built with Flask.
This project provides an API for making predictions using a trained machine learning model. The model is trained on the Iris dataset and can predict the species of iris flowers based on their sepal and petal measurements.
-
Clone the repository:
git clone https://github.com/lainceline/machine-learn.git cd machine-learn -
Set up a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the required dependencies:
pip install -r requirements.txt
To train the machine learning model, run the following command:
python model.pyThis script trains a RandomForestClassifier on the Iris dataset and saves the trained model to a file named model.joblib.
To start the Flask API, run the following command:
python app.pyThe API will be accessible at http://127.0.0.1:5000/.
GET /: Welcome messagePOST /predict: Make a prediction
To make a prediction, send a POST request to http://127.0.0.1:5000/predict with the following JSON data:
[
{"sepal length (cm)": 5.1, "sepal width (cm)": 3.5, "petal length (cm)": 1.4, "petal width (cm)": 0.2}
]The API will return a JSON response with the predicted species:
[0, 1, 2]-
Ensure you are in the virtual environment.
-
Run the tests using
unittest:python -m unittest discover -s tests
model.py: Script for training and saving the machine learning model.app.py: Flask application providing the API.requirements.txt: Python dependencies.tests/: Directory containing unit tests.
This project is licensed under the MIT License.
If you'd like to contribute to this project, please follow these guidelines:
- Fork the repository
- Create a new branch (
git checkout -b feature-branch) - Make your changes
- Commit your changes (
git commit -m 'Add new feature') - Push to the branch (
git push origin feature-branch) - Create a new Pull Request
For any questions or inquiries, please contact sarahmyers180@gmail.com.
Happy coding!