title: Iris Flower Prediction With MachineLearning
emoji: ๐
colorFrom: pink
colorTo: green
sdk: docker
pinned: false
license: apache-2.0
short_description: A beautiful,modern web application that uses MachineLearning
๐ธ Interactive Iris Flower Prediction Web Application ๐ธ
<<<<<<< HEAD A beautiful, modern web application that uses Machine Learning to predict Iris flower species with an enhanced interactive user interface, animated backgrounds, and stunning visual effects.
Hare Checkout:=๐ https://prediction-iris-flower-machine-learning.onrender.com ๐๐ซก
This web is host on render and checkout https://render.com/ this.
5402033a2086745c03342e8a3c63247b4ff7cd0a
Live Demo: https://itsluckysharma01.github.io/Prediction_iris_Flower_Machine_Learning-Flask/ ๐๐ซก
๐ธ Iris Flower Detection ML Project
Author: Lucky Sharma
Project: Machine Learning classification model to predict Iris flower species
๐ Table of Contents
- ๐ฏ Project Overview
- ๐บ About the Iris Dataset
- ๐ Quick Start
- ๐ Features
- ๐ง Installation
- ๐ป Usage
- ๐ค Model Performance
- ๐ Visualizations
- ๐ฎ Making Predictions
- ๐ Project Structure
- ๐ ๏ธ Technologies Used
- ๐ Model Comparison
- ๐จ Interactive Examples
- ๐ค Contributing
- ๐ License
๐ฏ Project Overview
This project implements a Machine Learning classification model to predict the species of Iris flowers based on their physical characteristics. The model analyzes four key features of iris flowers and classifies them into one of three species with high accuracy.
๐ฏ What does this project do?
- Predicts iris flower species (Setosa, Versicolor, Virginica)
- Analyzes flower measurements (sepal length/width, petal length/width)
- Provides multiple ML algorithms comparison
- Offers both interactive notebook and saved model for predictions
๐บ About the Iris Dataset
The famous Iris dataset contains measurements of 150 iris flowers from three different species:
Species | Count | Characteristics |
---|---|---|
๐ธ Iris Setosa | 50 | Smaller petals, distinct features |
๐บ Iris Versicolor | 50 | Medium-sized features |
๐ป Iris Virginica | 50 | Larger petals and sepals |
๐ Features Measured:
- Sepal Length (cm)
- Sepal Width (cm)
- Petal Length (cm)
- Petal Width (cm)
๐ Quick Start
1๏ธโฃ Clone the Repository
git clone <your-repository-url>
cd iris_flower_detection
2๏ธโฃ Install Dependencies
pip install pandas numpy matplotlib seaborn scikit-learn jupyter
3๏ธโฃ Run the Notebook
jupyter notebook iris_flower_Detection_ML-1.ipynb
4๏ธโฃ Make a Quick Prediction
import joblib
import pandas as pd
# Load the trained model
model = joblib.load('iris_flower_model.pkl')
# Make a prediction
sample = [[5.1, 3.5, 1.4, 0.2]] # [sepal_length, sepal_width, petal_length, petal_width]
prediction = model.predict(sample)
print(f"Predicted species: {prediction[0]}")
๐ Features
๐ Data Analysis
- โ Comprehensive data exploration
- โ Missing value analysis
- โ Statistical summaries
- โ Data visualization
๐ค Machine Learning Models
- โ Logistic Regression - Primary model
- โ Decision Tree Classifier - Alternative approach
- โ K-Nearest Neighbors - Distance-based classification
- โ Model comparison and performance evaluation
๐ Visualizations
- โ Histograms for feature distributions
- โ Scatter plots for feature relationships
- โ Species distribution analysis
๐พ Model Persistence
- โ Save models using joblib
- โ Save models using pickle
- โ Load and use pre-trained models
๐ง Installation
Requirements
pandas>=1.3.0
numpy>=1.21.0
matplotlib>=3.4.0
seaborn>=0.11.0
scikit-learn>=1.0.0
jupyter>=1.0.0
Install via pip
pip install -r requirements.txt
Or install individually
pip install pandas numpy matplotlib seaborn scikit-learn jupyter
๐ป Usage
๐ Interactive Notebook
Open iris_flower_Detection_ML-1.ipynb
in Jupyter Notebook to:
- Explore the complete data science workflow
- Visualize data patterns
- Train and compare different models
- Make interactive predictions
๐ฎ Using the Saved Model
import joblib
import pandas as pd
# Load the pre-trained model
model = joblib.load('iris_flower_model.pkl')
# Create sample data
sample_data = {
'sepal_length': [5.1],
'sepal_width': [3.5],
'petal_length': [1.4],
'petal_width': [0.2]
}
# Convert to DataFrame
df = pd.DataFrame(sample_data)
# Make prediction
prediction = model.predict(df)
print(f"Predicted Iris species: {prediction[0]}")
๐ค Model Performance
๐ Accuracy Results
Algorithm | Training Accuracy | Test Accuracy |
---|---|---|
Logistic Regression | ~95-98% | ~95-98% |
Decision Tree | ~100% | ~95-97% |
K-Nearest Neighbors (k=3) | ~95-98% | ~95-98% |
๐ฏ Why These Results?
- High Accuracy: Iris dataset is well-separated and clean
- Low Complexity: Only 4 features make classification straightforward
- Balanced Dataset: Equal samples for each class
๐ Visualizations
The project includes several visualization techniques:
๐ Available Plots
- Histograms - Feature distribution analysis
- Scatter Plots - Relationship between features
- Pair Plots - Multiple feature comparisons
- Box Plots - Statistical summaries by species
๐จ Example Visualization Code
import matplotlib.pyplot as plt
import seaborn as sns
# Create scatter plot
plt.figure(figsize=(10, 6))
sns.scatterplot(data=iris, x='sepal_length', y='sepal_width', hue='species')
plt.title('Sepal Length vs Width by Species')
plt.show()
๐ฎ Making Predictions
๐งช Interactive Prediction Function
def predict_iris_species(sepal_length, sepal_width, petal_length, petal_width):
"""
Predict iris species based on measurements
Parameters:
- sepal_length: float (cm)
- sepal_width: float (cm)
- petal_length: float (cm)
- petal_width: float (cm)
Returns:
- species: string (Setosa, Versicolor, or Virginica)
"""
model = joblib.load('iris_flower_model.pkl')
sample = [[sepal_length, sepal_width, petal_length, petal_width]]
prediction = model.predict(sample)
return prediction[0]
# Example usage
species = predict_iris_species(5.1, 3.5, 1.4, 0.2)
print(f"Predicted species: {species}")
๐ฏ Example Predictions
Measurements | Predicted Species | Confidence |
---|---|---|
[5.1, 3.5, 1.4, 0.2] | Setosa | High |
[5.9, 3.0, 5.1, 1.8] | Virginica | High |
[6.2, 2.8, 4.8, 1.8] | Virginica | Medium |
๐ Project Structure
iris_flower_detection/
โ
โโโ ๐ iris_flower_Detection_ML-1.ipynb # Main Jupyter notebook
โโโ ๐ค iris_flower_model.pkl # Saved ML model (joblib)
โโโ ๐ค iris_model.pkl # Saved ML model (pickle)
โโโ ๐ README.md # This file
โโโ ๐ requirements.txt # Python dependencies
๐ ๏ธ Technologies Used
๐ Core Libraries
- pandas - Data manipulation and analysis
- numpy - Numerical computing
- scikit-learn - Machine learning algorithms
๐ Visualization
- matplotlib - Basic plotting
- seaborn - Statistical visualizations
๐ Development Environment
- Jupyter Notebook - Interactive development
- Python 3.7+ - Programming language
๐ง Model Management
- joblib - Model serialization (recommended)
- pickle - Alternative model serialization
๐ Model Comparison
๐ Algorithm Strengths
Algorithm | Pros | Cons | Best For |
---|---|---|---|
Logistic Regression | Fast, interpretable, probabilistic | Linear boundaries only | Quick baseline |
Decision Tree | Easy to understand, handles non-linear | Can overfit | Interpretability |
K-Nearest Neighbors | Simple, no training period | Sensitive to outliers | Small datasets |
๐ฏ Recommendation
For the Iris dataset, Logistic Regression is recommended because:
- โ High accuracy with fast training
- โ Provides probability estimates
- โ Less prone to overfitting
- โ Good for deployment
๐จ Interactive Examples
๐งช Try These Samples
๐ธ Setosa Examples
# Typical Setosa characteristics
predict_iris_species(5.0, 3.0, 1.0, 0.5) # โ Setosa
predict_iris_species(4.8, 3.2, 1.4, 0.3) # โ Setosa
๐บ Versicolor Examples
# Typical Versicolor characteristics
predict_iris_species(6.0, 2.8, 4.0, 1.2) # โ Versicolor
predict_iris_species(5.7, 2.9, 4.2, 1.3) # โ Versicolor
๐ป Virginica Examples
# Typical Virginica characteristics
predict_iris_species(6.5, 3.0, 5.2, 2.0) # โ Virginica
predict_iris_species(7.2, 3.2, 6.0, 1.8) # โ Virginica
๐ฎ Interactive Prediction Game
def iris_guessing_game():
"""Fun interactive game to test your iris knowledge!"""
samples = [
([5.1, 3.5, 1.4, 0.2], "Setosa"),
([6.7, 3.1, 4.4, 1.4], "Versicolor"),
([6.3, 2.9, 5.6, 1.8], "Virginica")
]
for i, (measurements, actual) in enumerate(samples):
print(f"\n๐ธ Sample {i+1}: {measurements}")
user_guess = input("Guess the species (Setosa/Versicolor/Virginica): ")
prediction = predict_iris_species(*measurements)
print(f"Your guess: {user_guess}")
print(f"ML Prediction: {prediction}")
print(f"Actual: {actual}")
print("โ
Correct!" if user_guess.lower() == actual.lower() else "โ Try again!")
# Run the game
iris_guessing_game()
๐ฌ Advanced Usage
๐ Model Evaluation Metrics
from sklearn.metrics import classification_report, confusion_matrix
# Generate detailed performance report
y_pred = model.predict(X_test)
print("Classification Report:")
print(classification_report(y_test, y_pred))
print("\nConfusion Matrix:")
print(confusion_matrix(y_test, y_pred))
๐ฏ Cross-Validation
from sklearn.model_selection import cross_val_score
# Perform 5-fold cross-validation
cv_scores = cross_val_score(model, X, y, cv=5)
print(f"Cross-validation scores: {cv_scores}")
print(f"Average CV score: {cv_scores.mean():.3f} (+/- {cv_scores.std() * 2:.3f})")
๐ค Contributing
๐ How to Contribute
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
๐ก Ideas for Contributions
- ๐จ Add more visualization techniques
- ๐ค Implement additional ML algorithms
- ๐ Create a web interface
- ๐ฑ Build a mobile app
- ๐ง Add hyperparameter tuning
- ๐ Include more evaluation metrics
๐ Learning Resources
๐ Learn More About
๐ฏ Next Steps
- Try other datasets (Wine, Breast Cancer, etc.)
- Experiment with ensemble methods
- Add feature engineering techniques
- Deploy the model as a web service
- Create a real-time prediction app
โจ New Enhanced Features
๐จ Interactive Design
- Modern UI/UX: Beautiful gradient backgrounds with glassmorphism effects
- Animated Background Video: Looping flower videos for immersive experience
- Interactive Flower Cards: Click-to-fill example values with hover effects
- Floating Particles: Dynamic flower emojis floating across the screen
- Smooth Animations: CSS keyframe animations for all elements
๐บ Flower Showcase
- Real Flower Images: Actual photographs of each iris species
- Visual Flower Display: High-quality images showing true flower colors
- Detailed Information: Comprehensive facts about each flower type with color names
- Interactive Examples: Click any flower card to auto-fill the form
- Species-Specific Styling: Unique colors and animations for each iris type
- Dynamic Backgrounds: Background colors change based on predicted flower type
๐ Enhanced Functionality
- Form Validation: Real-time input validation with visual feedback
- Number Inputs: Proper numeric inputs with step controls
- Confidence Scoring: Display prediction confidence percentages
- Error Handling: Graceful error messages with helpful suggestions
- Responsive Design: Works perfectly on desktop, tablet, and mobile
๐ญ Visual Effects
- Real Flower Photography: High-quality images of actual iris flowers
- Dynamic Background Colors: Background changes based on predicted flower species
- Background Videos: Multiple fallback video sources for reliability
- Particle System: Dynamic floating flower animations
- Confetti Effects: Celebration animations for successful predictions
- Glow Effects: Smooth glowing animations throughout the interface
- Hover Interactions: Elements respond to user interactions
- Custom Favicon: Beautiful iris flower favicon for all devices and sizes
- PWA Support: Web app manifest for mobile installation
- Color-Themed Results: Each flower type displays with its natural color scheme
๐จ Favicon and Branding
The application now includes a complete set of favicon files for optimal display across all devices and platforms:
๐ธ Design Elements
- Gradient backgrounds: Beautiful purple to pink gradients matching the app theme
- Iris flower motifs: Custom-designed flower shapes in the favicon
- Consistent branding: All icons follow the same color scheme and design language
- Multiple sizes: Optimized for different display contexts and resolutions
๐ฑ PWA Features
- Installable: Users can install the app on their mobile devices
- Standalone mode: App runs in full-screen mode when installed
- Custom theme colors: Matches the application's visual design
- Optimized icons: Perfect display in app drawers and home screens
๐ ๏ธ Technical Features
Machine Learning
app.py
- The main Flask applicationiris_model.pkl
/new_iris_model.pkl
- The trained machine learning modeltemplates/
- Folder containing HTML templatesform.html
- Input form for flower measurementsresult.html
- Page showing prediction results
static/
- Folder containing static files
How to Run
- Double-click on
run_app.bat
or runpython app.py
in your terminal - Open your web browser and go to http://127.0.0.1:5000
- Enter the flower measurements and click "Predict Flower Species"
Sample Measurements
Iris Setosa
- Sepal Length: 5.1 cm
- Sepal Width: 3.5 cm
- Petal Length: 1.4 cm
- Petal Width: 0.2 cm
Iris Versicolor
- Sepal Length: 6.0 cm
- Sepal Width: 2.7 cm
- Petal Length: 4.2 cm
- Petal Width: 1.3 cm
Iris Virginica
- Sepal Length: 6.8 cm
- Sepal Width: 3.0 cm
- Petal Length: 5.5 cm
- Petal Width: 2.1 cm
Troubleshooting
If you encounter issues:
- Run
python test_app.py
to verify the model is working correctly - Check that you have all the required Python packages installed:
- Flask
- scikit-learn
- joblib
- numpy
- Try generating a new model with
python create_new_model.py
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Ronald A. Fisher - For creating the famous Iris dataset (1936)
- Scikit-learn Team - For excellent machine learning tools
- Jupyter Team - For the amazing notebook environment
- Python Community - For the incredible ecosystem
๐ Star this repository if you found it helpful! ๐
Made with โค๏ธ for the Machine Learning Community
๐ Happy Coding!
Remember: The best way to learn machine learning is by doing. Keep experimenting, keep learning! ๐
Ready to explore the beautiful world of Iris flowers! ๐ธ๐คโจ