MLPredictor is a simple machine learning package that trains a RandomForest model using the Iris dataset and enables users to make predictions. The package is built using scikit-learn and is intended as a demonstration of packaging Python machine learning projects for distribution.
- Train a RandomForestClassifier on the Iris dataset.
- Make predictions on new data after training.
- Save and load trained models.
You can install the package via PyPI or from source.
pip install mlpredictorgit clone https://github.com/ebimsv/mlpredictor.git
cd mlpredictor
pip install .After installation, you can use MLPredictor to train a model and make predictions.
from mlpredictor import MLPredictor
# Initialize the predictor
predictor = MLPredictor()
# Train the model on the Iris dataset
predictor.train()
# Make a prediction on a sample input
sample_input = [5.1, 3.5, 1.4, 0.2]
prediction = predictor.predict(sample_input)
print(f"Predicted class: {prediction}")You can also save the trained model to a file and load it later for future predictions:
from mlpredictor import MLPredictor
# Initialize and train the model
predictor = MLPredictor()
predictor.train()
# Save the trained model to a file
predictor.save_model("my_model.pkl")
# Load the model from the file and make predictions
new_predictor = MLPredictor()
new_predictor.load_model("my_model.pkl")
sample_input = [5.1, 3.5, 1.4, 0.2]
prediction = new_predictor.predict(sample_input)
print(f"Predicted class: {prediction.item()}")This project includes a test suite. You can run tests using pytest:
pip install pytest
pytest testsThis project is licensed under the MIT License. See the LICENSE file for more details.
Contributions are welcome! Please feel free to submit pull requests or open issues if you have any suggestions or find bugs.
- Installation Instructions: Added how to install from both PyPI and source (GitHub).
- Usage Instructions: Provided examples for training, making predictions, saving the model, and loading a saved model.
- Testing Section: Added instructions on how to run the tests using
pytest. - Contributing Section: Encouraged contributions for further improvements.
This updated README should provide users with all the information they need to install, use, and contribute to your project.