File size: 17,519 Bytes
bdf8e66 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
---
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
[](https://www.python.org/downloads/)
[](https://jupyter.org/)
[](https://scikit-learn.org/)
[](https://opensource.org/licenses/MIT)
> **Author:** Lucky Sharma
> **Project:** Machine Learning classification model to predict Iris flower species
## ๐ Table of Contents
- [๐ฏ Project Overview](#-project-overview)
- [๐บ About the Iris Dataset](#-about-the-iris-dataset)
- [๐ Quick Start](#-quick-start)
- [๐ Features](#-features)
- [๐ง Installation](#-installation)
- [๐ป Usage](#-usage)
- [๐ค Model Performance](#-model-performance)
- [๐ Visualizations](#-visualizations)
- [๐ฎ Making Predictions](#-making-predictions)
- [๐ Project Structure](#-project-structure)
- [๐ ๏ธ Technologies Used](#๏ธ-technologies-used)
- [๐ Model Comparison](#-model-comparison)
- [๐จ Interactive Examples](#-interactive-examples)
- [๐ค Contributing](#-contributing)
- [๐ License](#-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**
```bash
git clone <your-repository-url>
cd iris_flower_detection
```
### 2๏ธโฃ **Install Dependencies**
```bash
pip install pandas numpy matplotlib seaborn scikit-learn jupyter
```
### 3๏ธโฃ **Run the Notebook**
```bash
jupyter notebook iris_flower_Detection_ML-1.ipynb
```
### 4๏ธโฃ **Make a Quick Prediction**
```python
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**
```txt
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**
```bash
pip install -r requirements.txt
```
### **Or install individually**
```bash
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**
```python
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**
1. **Histograms** - Feature distribution analysis
2. **Scatter Plots** - Relationship between features
3. **Pair Plots** - Multiple feature comparisons
4. **Box Plots** - Statistical summaries by species
### ๐จ **Example Visualization Code**
```python
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**
```python
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**
```python
# 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**
```python
# 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**
```python
# 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**
```python
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**
```python
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**
```python
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**
1. **Fork** the repository
2. **Create** a feature branch (`git checkout -b feature/AmazingFeature`)
3. **Commit** your changes (`git commit -m 'Add some AmazingFeature'`)
4. **Push** to the branch (`git push origin feature/AmazingFeature`)
5. **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**
- [Iris Dataset History](https://en.wikipedia.org/wiki/Iris_flower_data_set)
- [Scikit-learn Documentation](https://scikit-learn.org/stable/)
- [Machine Learning Basics](https://www.coursera.org/learn/machine-learning)
- [Data Science with Python](https://www.python.org/about/apps/)
### ๐ฏ **Next Steps**
1. Try other datasets (Wine, Breast Cancer, etc.)
2. Experiment with ensemble methods
3. Add feature engineering techniques
4. Deploy the model as a web service
5. 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 application
- `iris_model.pkl` / `new_iris_model.pkl` - The trained machine learning model
- `templates/` - Folder containing HTML templates
- `form.html` - Input form for flower measurements
- `result.html` - Page showing prediction results
- `static/` - Folder containing static files
## How to Run
1. Double-click on `run_app.bat` or run `python app.py` in your terminal
2. Open your web browser and go to http://127.0.0.1:5000
3. 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:
1. Run `python test_app.py` to verify the model is working correctly
2. Check that you have all the required Python packages installed:
- Flask
- scikit-learn
- joblib
- numpy
3. Try generating a new model with `python create_new_model.py`
---
## ๐ License
This project is licensed under the **MIT License** - see the [LICENSE](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
---
---
<div align="center">
### ๐ **Star this repository if you found it helpful!** ๐
**Made with โค๏ธ for the Machine Learning Community**
</div>
---
## ๐ **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! ๐ธ๐คโจ** |