Spaces:
Sleeping
Sleeping
Upload 25 files
Browse files- Dockerfile +24 -0
- README.md +101 -4
- __pycache__/app.cpython-310.pyc +0 -0
- __pycache__/model_pipeline.cpython-310.pyc +0 -0
- __pycache__/visualization.cpython-310.pyc +0 -0
- app.py +455 -0
- feedback.json +16 -0
- gitignore +62 -0
- model_pipeline.py +1966 -0
- requirements.txt +30 -0
- run.py +38 -0
- setup.py +73 -0
- static/css/style.css +302 -0
- static/js/script.js +252 -0
- templates/404.html +39 -0
- templates/500.html +45 -0
- templates/about.html +219 -0
- templates/base.html +109 -0
- templates/configure.html +675 -0
- templates/documentation.html +183 -0
- templates/feedback.html +108 -0
- templates/index.html +259 -0
- templates/predict.html +139 -0
- templates/predict_locked.html +125 -0
- templates/result.html +317 -0
Dockerfile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
# Install system dependencies for matplotlib
|
| 6 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 7 |
+
gcc \
|
| 8 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
+
|
| 10 |
+
# Copy requirements first for better caching
|
| 11 |
+
COPY requirements.txt .
|
| 12 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 13 |
+
|
| 14 |
+
# Copy application code
|
| 15 |
+
COPY . .
|
| 16 |
+
|
| 17 |
+
# Create necessary directories
|
| 18 |
+
RUN mkdir -p uploads saved_models
|
| 19 |
+
|
| 20 |
+
# HF Spaces requires port 7860
|
| 21 |
+
ENV PORT=7860
|
| 22 |
+
EXPOSE 7860
|
| 23 |
+
|
| 24 |
+
CMD ["python", "app.py"]
|
README.md
CHANGED
|
@@ -1,10 +1,107 @@
|
|
| 1 |
---
|
| 2 |
title: Data2Model
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
|
|
|
| 7 |
pinned: false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
title: Data2Model
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: red
|
| 6 |
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
pinned: false
|
| 9 |
+
license: mit
|
| 10 |
+
short_description: Upload data, train models, deploy instantly
|
| 11 |
+
tags:
|
| 12 |
+
- machine-learning
|
| 13 |
+
- automl
|
| 14 |
+
- flask
|
| 15 |
+
- scikit-learn
|
| 16 |
+
- classification
|
| 17 |
+
- regression
|
| 18 |
+
- clustering
|
| 19 |
---
|
| 20 |
|
| 21 |
+
# π Data2Model
|
| 22 |
+
|
| 23 |
+
**Automated Machine Learning Pipeline β From Raw Data to Deployable Web App**
|
| 24 |
+
|
| 25 |
+
Upload a dataset β Configure preprocessing β Train models β Download a ready-to-deploy prediction app
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
## β¨ Features
|
| 30 |
+
|
| 31 |
+
| Feature | Description |
|
| 32 |
+
|---|---|
|
| 33 |
+
| **One-Click AutoML** | Upload CSV/Excel/JSON and automatically train & compare 8+ ML algorithms |
|
| 34 |
+
| **Smart Type Detection** | Automatically distinguishes numeric vs categorical columns with manual override |
|
| 35 |
+
| **Per-Column Preprocessing** | Configure scaling (Standard, MinMax, Robust, Normalizer) and encoding (One-Hot, Label, Ordinal, Binary) individually per column |
|
| 36 |
+
| **Flexible Null Handling** | Per-column imputation: mean, median, mode, custom constant, or row deletion |
|
| 37 |
+
| **Column Dropping** | Exclude irrelevant columns (IDs, timestamps, etc.) before training |
|
| 38 |
+
| **Flexible Data Splits** | Train/Test or Train/Test/Validation with configurable percentages |
|
| 39 |
+
| **Data Dashboard** | Auto-generated visualizations: histograms, correlation heatmaps, distributions |
|
| 40 |
+
| **Deployable App Export** | Download a complete Flask web app (ZIP) with your trained model built-in |
|
| 41 |
+
| **Prediction Interface** | Upload new data for batch predictions with a trained model |
|
| 42 |
+
| **Auto Cleanup** | Uploaded datasets are automatically deleted after training and on server shutdown |
|
| 43 |
+
|
| 44 |
+
## π§ Supported Algorithms
|
| 45 |
+
|
| 46 |
+
### Classification
|
| 47 |
+
Logistic Regression Β· Random Forest Β· Gradient Boosting Β· Decision Tree Β· KNN Β· Naive Bayes Β· SVM Β· AdaBoost Β· XGBoost Β· LightGBM
|
| 48 |
+
|
| 49 |
+
### Regression
|
| 50 |
+
Linear Regression Β· Random Forest Β· Gradient Boosting Β· Decision Tree Β· KNN Β· SVR Β· AdaBoost Β· XGBoost Β· LightGBM
|
| 51 |
+
|
| 52 |
+
### Unsupervised
|
| 53 |
+
K-Means Β· DBSCAN Β· Agglomerative Clustering Β· PCA
|
| 54 |
+
|
| 55 |
+
---
|
| 56 |
+
|
| 57 |
+
## π§ How to Use
|
| 58 |
+
|
| 59 |
+
1. **Upload** β Drop your CSV, Excel, or JSON dataset
|
| 60 |
+
2. **Configure** β Set null handling, scaling, encoding, and column selection per column
|
| 61 |
+
3. **Train** β Choose problem type, target column, and data split strategy
|
| 62 |
+
4. **Evaluate** β View metrics (Accuracy, F1, RΒ², RMSE) and preprocessing summary
|
| 63 |
+
5. **Deploy** β Download the trained model or a complete Flask prediction app (ZIP)
|
| 64 |
+
|
| 65 |
+
## π Project Structure
|
| 66 |
+
|
| 67 |
+
```
|
| 68 |
+
βββ app.py # Flask web application
|
| 69 |
+
βββ model_pipeline.py # AutoML pipeline engine
|
| 70 |
+
βββ Dockerfile # Container configuration for HF Spaces
|
| 71 |
+
βββ requirements.txt # Python dependencies
|
| 72 |
+
βββ templates/ # Jinja2 HTML templates
|
| 73 |
+
β βββ base.html # Base layout
|
| 74 |
+
β βββ index.html # Home / upload page
|
| 75 |
+
β βββ configure.html # Preprocessing & training config
|
| 76 |
+
β βββ result.html # Training results & metrics
|
| 77 |
+
β βββ predict.html # Prediction interface
|
| 78 |
+
β βββ ... # About, docs, feedback, error pages
|
| 79 |
+
βββ static/ # CSS & JavaScript
|
| 80 |
+
βββ uploads/ # Temporary uploads (auto-cleaned)
|
| 81 |
+
βββ saved_models/ # Trained models & deployable ZIPs
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
## π‘οΈ Data Privacy
|
| 85 |
+
|
| 86 |
+
- Uploaded datasets are **never stored permanently**
|
| 87 |
+
- Files are deleted immediately after training completes
|
| 88 |
+
- All remaining uploads are wiped on server shutdown
|
| 89 |
+
|
| 90 |
+
---
|
| 91 |
+
|
| 92 |
+
## π» Run Locally
|
| 93 |
+
|
| 94 |
+
```bash
|
| 95 |
+
git clone https://huggingface.co/spaces/YOUR_USERNAME/Data2Model
|
| 96 |
+
cd Data2Model
|
| 97 |
+
pip install -r requirements.txt
|
| 98 |
+
python app.py
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
Open **http://localhost:5000** in your browser.
|
| 102 |
+
|
| 103 |
+
---
|
| 104 |
+
|
| 105 |
+
<p align="center">
|
| 106 |
+
Built with β€οΈ using Flask & scikit-learn
|
| 107 |
+
</p>
|
__pycache__/app.cpython-310.pyc
ADDED
|
Binary file (8.62 kB). View file
|
|
|
__pycache__/model_pipeline.cpython-310.pyc
ADDED
|
Binary file (56.9 kB). View file
|
|
|
__pycache__/visualization.cpython-310.pyc
ADDED
|
Binary file (6.33 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,455 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Data2Model - Flask Web Application
|
| 3 |
+
Updated to handle all 8 system improvements.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from flask import Flask, render_template, request, redirect, url_for, send_file, flash
|
| 7 |
+
import os, json, time, atexit, shutil
|
| 8 |
+
import pandas as pd
|
| 9 |
+
from werkzeug.utils import secure_filename
|
| 10 |
+
from model_pipeline import AutoMLPipeline
|
| 11 |
+
from datetime import datetime
|
| 12 |
+
|
| 13 |
+
app = Flask(__name__)
|
| 14 |
+
app.secret_key = 'data2model-secret-key-2025'
|
| 15 |
+
|
| 16 |
+
UPLOAD_FOLDER = 'uploads'
|
| 17 |
+
MODEL_FOLDER = 'saved_models'
|
| 18 |
+
ALLOWED_EXTENSIONS = {'csv', 'xlsx', 'xls', 'json'}
|
| 19 |
+
|
| 20 |
+
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
| 21 |
+
app.config['MODEL_FOLDER'] = MODEL_FOLDER
|
| 22 |
+
|
| 23 |
+
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
| 24 |
+
os.makedirs(MODEL_FOLDER, exist_ok=True)
|
| 25 |
+
|
| 26 |
+
current_pipeline = None
|
| 27 |
+
current_results = None
|
| 28 |
+
|
| 29 |
+
# ββ Workflow state ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 30 |
+
# Predict is unlocked when a model is trained successfully (with either split)
|
| 31 |
+
model_state = {
|
| 32 |
+
'trained': False,
|
| 33 |
+
'split_type': None, # 'train_test' or 'train_test_val'
|
| 34 |
+
'split_info': None, # human-readable e.g. "60% / 20% / 20%"
|
| 35 |
+
'model_name': None,
|
| 36 |
+
'problem_type': None,
|
| 37 |
+
'scaler_path': None, # path to saved scaler pkl (None if not applied)
|
| 38 |
+
'encoder_path': None, # path to saved encoder pkl (None if not applied)
|
| 39 |
+
'scaling_applied': False,
|
| 40 |
+
'encoding_applied': False,
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
def predict_unlocked():
|
| 44 |
+
return model_state['trained']
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def allowed_file(filename):
|
| 48 |
+
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
# ββ Context processor: inject predict_unlocked into every template βββββββββββ
|
| 52 |
+
@app.context_processor
|
| 53 |
+
def inject_state():
|
| 54 |
+
return {
|
| 55 |
+
'predict_unlocked': predict_unlocked(),
|
| 56 |
+
'model_state': model_state,
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 61 |
+
def cleanup_old_files():
|
| 62 |
+
"""Delete files in uploads older than 1 hour to prevent permanent storage."""
|
| 63 |
+
now = time.time()
|
| 64 |
+
for filename in os.listdir(app.config['UPLOAD_FOLDER']):
|
| 65 |
+
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
| 66 |
+
if os.path.isfile(file_path):
|
| 67 |
+
if os.stat(file_path).st_mtime < now - 3600:
|
| 68 |
+
try:
|
| 69 |
+
os.remove(file_path)
|
| 70 |
+
except Exception as e:
|
| 71 |
+
print(f"Error cleaning up file {file_path}: {e}")
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def cleanup_file(filepath):
|
| 75 |
+
"""Safely delete a single file if it exists."""
|
| 76 |
+
try:
|
| 77 |
+
if filepath and os.path.isfile(filepath):
|
| 78 |
+
os.remove(filepath)
|
| 79 |
+
print(f"π Cleaned up: {os.path.basename(filepath)}")
|
| 80 |
+
except Exception as e:
|
| 81 |
+
print(f"Warning: Could not delete {filepath}: {e}")
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def cleanup_all_session_files():
|
| 85 |
+
"""Delete ALL session artifacts (uploads + saved models/zips) on shutdown."""
|
| 86 |
+
# 1. Clean uploads
|
| 87 |
+
upload_dir = app.config['UPLOAD_FOLDER']
|
| 88 |
+
if os.path.isdir(upload_dir):
|
| 89 |
+
for filename in os.listdir(upload_dir):
|
| 90 |
+
file_path = os.path.join(upload_dir, filename)
|
| 91 |
+
try:
|
| 92 |
+
if os.path.isfile(file_path):
|
| 93 |
+
os.remove(file_path)
|
| 94 |
+
except Exception:
|
| 95 |
+
pass
|
| 96 |
+
print("π All uploaded files cleaned up on shutdown.")
|
| 97 |
+
|
| 98 |
+
# 2. Clean saved_models (model .pkl, scaler .pkl, encoder .pkl, deployable_app .zip)
|
| 99 |
+
model_dir = app.config['MODEL_FOLDER']
|
| 100 |
+
if os.path.isdir(model_dir):
|
| 101 |
+
for filename in os.listdir(model_dir):
|
| 102 |
+
# Preserve .gitkeep so the directory stays tracked in git
|
| 103 |
+
if filename == '.gitkeep':
|
| 104 |
+
continue
|
| 105 |
+
file_path = os.path.join(model_dir, filename)
|
| 106 |
+
try:
|
| 107 |
+
if os.path.isfile(file_path):
|
| 108 |
+
os.remove(file_path)
|
| 109 |
+
except Exception:
|
| 110 |
+
pass
|
| 111 |
+
print("π All saved models and deployable app zips cleaned up on shutdown.")
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
# Register shutdown hook β wipes uploads + saved models when server stops
|
| 115 |
+
atexit.register(cleanup_all_session_files)
|
| 116 |
+
|
| 117 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 118 |
+
@app.route('/')
|
| 119 |
+
def index():
|
| 120 |
+
return render_template('index.html')
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 124 |
+
@app.route('/upload', methods=['POST'])
|
| 125 |
+
def upload_file():
|
| 126 |
+
global current_pipeline, current_results
|
| 127 |
+
|
| 128 |
+
try:
|
| 129 |
+
cleanup_old_files()
|
| 130 |
+
|
| 131 |
+
if 'file' not in request.files:
|
| 132 |
+
flash('No file uploaded', 'error')
|
| 133 |
+
return redirect(url_for('index'))
|
| 134 |
+
|
| 135 |
+
file = request.files['file']
|
| 136 |
+
if file.filename == '':
|
| 137 |
+
flash('No file selected', 'error')
|
| 138 |
+
return redirect(url_for('index'))
|
| 139 |
+
|
| 140 |
+
if not allowed_file(file.filename):
|
| 141 |
+
flash('Invalid file type. Please upload CSV, Excel, or JSON.', 'error')
|
| 142 |
+
return redirect(url_for('index'))
|
| 143 |
+
|
| 144 |
+
filename = secure_filename(file.filename)
|
| 145 |
+
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
|
| 146 |
+
filename = f"{timestamp}_{filename}"
|
| 147 |
+
filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
| 148 |
+
file.save(filepath)
|
| 149 |
+
|
| 150 |
+
ext = filename.rsplit('.', 1)[1].lower()
|
| 151 |
+
file_type = 'excel' if ext in ('xlsx', 'xls') else ext
|
| 152 |
+
|
| 153 |
+
current_pipeline = AutoMLPipeline()
|
| 154 |
+
data = current_pipeline.load_data(filepath, file_type)
|
| 155 |
+
analysis = current_pipeline.analyze_data(data)
|
| 156 |
+
viz_plots = current_pipeline.generate_visualizations(data, analysis['numeric_columns'], analysis['categorical_columns'])
|
| 157 |
+
|
| 158 |
+
session_data = {
|
| 159 |
+
'filepath': filepath,
|
| 160 |
+
'file_type': file_type,
|
| 161 |
+
'filename': file.filename,
|
| 162 |
+
'viz_plots': viz_plots,
|
| 163 |
+
'analysis': {
|
| 164 |
+
'shape': analysis['shape'],
|
| 165 |
+
'columns': analysis['columns'],
|
| 166 |
+
'numeric_columns': analysis['numeric_columns'],
|
| 167 |
+
'categorical_columns': analysis['categorical_columns'],
|
| 168 |
+
# missing_values: only cols that actually have gaps
|
| 169 |
+
'missing_values': {k: int(v) for k, v in analysis['missing_values'].items() if v > 0},
|
| 170 |
+
'duplicates': int(analysis['duplicates']),
|
| 171 |
+
'col_stats': analysis['col_stats'],
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
return render_template('configure.html', data=session_data)
|
| 176 |
+
|
| 177 |
+
except Exception as e:
|
| 178 |
+
flash(f'Error processing file: {str(e)}', 'error')
|
| 179 |
+
return redirect(url_for('index'))
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 183 |
+
@app.route('/train', methods=['POST'])
|
| 184 |
+
def train_model():
|
| 185 |
+
global current_pipeline, current_results
|
| 186 |
+
|
| 187 |
+
try:
|
| 188 |
+
filepath = request.form.get('filepath')
|
| 189 |
+
file_type = request.form.get('file_type')
|
| 190 |
+
target_column = request.form.get('target_column') or None
|
| 191 |
+
problem_type = request.form.get('problem_type', 'auto')
|
| 192 |
+
split_type = request.form.get('split_type', 'train_test')
|
| 193 |
+
test_size = float(request.form.get('test_size', 0.2))
|
| 194 |
+
val_size = float(request.form.get('val_size', 0.2))
|
| 195 |
+
drop_columns = request.form.getlist('drop_columns')
|
| 196 |
+
|
| 197 |
+
# ββ FIX 1 & 2: per-column null strategies ββββββββββββββββββββββββββββ
|
| 198 |
+
null_strategies = {}
|
| 199 |
+
for key, value in request.form.items():
|
| 200 |
+
if key.startswith('null_') and not key.startswith('null_custom_'):
|
| 201 |
+
col = key[5:] # strip "null_"
|
| 202 |
+
if value == 'custom':
|
| 203 |
+
custom_val = request.form.get(f'null_custom_{col}', '')
|
| 204 |
+
null_strategies[col] = f"custom_{custom_val}"
|
| 205 |
+
else:
|
| 206 |
+
null_strategies[col] = value
|
| 207 |
+
|
| 208 |
+
# ββ FIX 6: per-column scaling config βββββββββββββββββββββββββββββββββ
|
| 209 |
+
scaling_config = {}
|
| 210 |
+
for key, value in request.form.items():
|
| 211 |
+
if key.startswith('scale_'):
|
| 212 |
+
col = key[6:] # strip "scale_"
|
| 213 |
+
scaling_config[col] = value
|
| 214 |
+
# If no per-column choices collected, fall back to standard
|
| 215 |
+
if not scaling_config:
|
| 216 |
+
scaling_config = 'standard'
|
| 217 |
+
|
| 218 |
+
# ββ FIX 7: per-column encoding config ββββββββββββββββββββββββββββββββ
|
| 219 |
+
encoding_config = {}
|
| 220 |
+
for key, value in request.form.items():
|
| 221 |
+
if key.startswith('encode_'):
|
| 222 |
+
col = key[7:] # strip "encode_"
|
| 223 |
+
encoding_config[col] = value
|
| 224 |
+
if not encoding_config:
|
| 225 |
+
encoding_config = 'auto'
|
| 226 |
+
|
| 227 |
+
# ββ FIX 8: categorical overrides βββββββββββββββββββββββββββββββββββββ
|
| 228 |
+
categorical_overrides = request.form.getlist('cat_override')
|
| 229 |
+
|
| 230 |
+
# Validate target column for supervised
|
| 231 |
+
UNSUPERVISED = ('clustering', 'dimensionality_reduction', 'association')
|
| 232 |
+
if problem_type not in UNSUPERVISED and not target_column:
|
| 233 |
+
flash('Please select a target column for supervised learning.', 'error')
|
| 234 |
+
return redirect(url_for('index'))
|
| 235 |
+
|
| 236 |
+
if current_pipeline is None:
|
| 237 |
+
current_pipeline = AutoMLPipeline()
|
| 238 |
+
|
| 239 |
+
results = current_pipeline.run_complete_pipeline(
|
| 240 |
+
file_path=filepath,
|
| 241 |
+
target_column=target_column,
|
| 242 |
+
file_type=file_type,
|
| 243 |
+
problem_type=problem_type,
|
| 244 |
+
split_type=split_type,
|
| 245 |
+
test_size=test_size,
|
| 246 |
+
val_size=val_size,
|
| 247 |
+
null_strategies=null_strategies or None,
|
| 248 |
+
scaling_config=scaling_config,
|
| 249 |
+
encoding_config=encoding_config,
|
| 250 |
+
categorical_overrides=categorical_overrides or None,
|
| 251 |
+
drop_columns=drop_columns or None,
|
| 252 |
+
)
|
| 253 |
+
|
| 254 |
+
current_results = results
|
| 255 |
+
|
| 256 |
+
# ββ Clean up: delete the uploaded dataset (no longer needed) ββββββββββ
|
| 257 |
+
cleanup_file(filepath)
|
| 258 |
+
|
| 259 |
+
# ββ FIX 9: update model_state β unlock predict only for 3-way split ββ
|
| 260 |
+
model_state['trained'] = True
|
| 261 |
+
model_state['split_type'] = split_type
|
| 262 |
+
model_state['split_info'] = results.get('split_info')
|
| 263 |
+
model_state['model_name'] = results.get('model_name')
|
| 264 |
+
model_state['problem_type'] = results.get('problem_type')
|
| 265 |
+
model_state['scaler_path'] = results.get('scaler_path')
|
| 266 |
+
model_state['encoder_path'] = results.get('encoder_path')
|
| 267 |
+
model_state['deployable_app_path'] = results.get('deployable_app_path')
|
| 268 |
+
model_state['scaling_applied'] = results.get('scaling_applied', False)
|
| 269 |
+
model_state['encoding_applied'] = results.get('encoding_applied', False)
|
| 270 |
+
|
| 271 |
+
return render_template('result.html',
|
| 272 |
+
results=results,
|
| 273 |
+
pipeline=current_pipeline,
|
| 274 |
+
predict_unlocked=predict_unlocked())
|
| 275 |
+
|
| 276 |
+
except Exception as e:
|
| 277 |
+
import traceback
|
| 278 |
+
traceback.print_exc()
|
| 279 |
+
flash(f'Error during training: {str(e)}', 'error')
|
| 280 |
+
return redirect(url_for('index'))
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 284 |
+
@app.route('/download_model')
|
| 285 |
+
def download_model():
|
| 286 |
+
try:
|
| 287 |
+
if current_results and 'model_path' in current_results:
|
| 288 |
+
return send_file(current_results['model_path'], as_attachment=True)
|
| 289 |
+
flash('No model available for download.', 'error')
|
| 290 |
+
return redirect(url_for('index'))
|
| 291 |
+
except Exception as e:
|
| 292 |
+
flash(f'Download error: {str(e)}', 'error')
|
| 293 |
+
return redirect(url_for('index'))
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 297 |
+
@app.route('/download_scaler')
|
| 298 |
+
def download_scaler():
|
| 299 |
+
try:
|
| 300 |
+
path = model_state.get('scaler_path')
|
| 301 |
+
if path and os.path.exists(path):
|
| 302 |
+
return send_file(path, as_attachment=True)
|
| 303 |
+
flash('No scaler artifact available for download.', 'error')
|
| 304 |
+
return redirect(url_for('index'))
|
| 305 |
+
except Exception as e:
|
| 306 |
+
flash(f'Download error: {str(e)}', 'error')
|
| 307 |
+
return redirect(url_for('index'))
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 311 |
+
@app.route('/download_encoder')
|
| 312 |
+
def download_encoder():
|
| 313 |
+
try:
|
| 314 |
+
path = model_state.get('encoder_path')
|
| 315 |
+
if path and os.path.exists(path):
|
| 316 |
+
return send_file(path, as_attachment=True)
|
| 317 |
+
flash('No encoder artifact available for download.', 'error')
|
| 318 |
+
return redirect(url_for('index'))
|
| 319 |
+
except Exception as e:
|
| 320 |
+
flash(f'Download error: {str(e)}', 'error')
|
| 321 |
+
return redirect(url_for('index'))
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 325 |
+
@app.route('/download_app')
|
| 326 |
+
def download_app():
|
| 327 |
+
try:
|
| 328 |
+
path = model_state.get('deployable_app_path')
|
| 329 |
+
if path and os.path.exists(path):
|
| 330 |
+
return send_file(path, as_attachment=True,
|
| 331 |
+
download_name='prediction_app.zip',
|
| 332 |
+
mimetype='application/zip')
|
| 333 |
+
flash('No deployable app available for download. Please train a model first.', 'error')
|
| 334 |
+
return redirect(url_for('index'))
|
| 335 |
+
except Exception as e:
|
| 336 |
+
flash(f'Error generating deployable app: {str(e)}', 'error')
|
| 337 |
+
return redirect(url_for('index'))
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 341 |
+
@app.route('/predict', methods=['GET', 'POST'])
|
| 342 |
+
def predict():
|
| 343 |
+
# Gate β predict only when a model is trained
|
| 344 |
+
if request.method == 'GET':
|
| 345 |
+
if not predict_unlocked():
|
| 346 |
+
return render_template('predict_locked.html',
|
| 347 |
+
model_trained=model_state['trained'],
|
| 348 |
+
split_type=model_state['split_type'])
|
| 349 |
+
return render_template('predict.html', model_state=model_state)
|
| 350 |
+
|
| 351 |
+
try:
|
| 352 |
+
# Also block POST if not trained
|
| 353 |
+
if not predict_unlocked():
|
| 354 |
+
flash('Predictions are only available after training a model.', 'warning')
|
| 355 |
+
return redirect(url_for('predict'))
|
| 356 |
+
|
| 357 |
+
if current_pipeline is None or current_pipeline.model is None:
|
| 358 |
+
flash('No trained model found. Please train a model first.', 'error')
|
| 359 |
+
return redirect(url_for('index'))
|
| 360 |
+
|
| 361 |
+
if 'file' not in request.files:
|
| 362 |
+
flash('No file uploaded', 'error')
|
| 363 |
+
return redirect(url_for('predict'))
|
| 364 |
+
|
| 365 |
+
file = request.files['file']
|
| 366 |
+
if file.filename == '':
|
| 367 |
+
flash('No file selected', 'error')
|
| 368 |
+
return redirect(url_for('predict'))
|
| 369 |
+
|
| 370 |
+
filename = secure_filename(file.filename)
|
| 371 |
+
filepath = os.path.join(app.config['UPLOAD_FOLDER'], f"pred_{filename}")
|
| 372 |
+
file.save(filepath)
|
| 373 |
+
|
| 374 |
+
ext = filename.rsplit('.', 1)[1].lower()
|
| 375 |
+
if ext == 'csv':
|
| 376 |
+
pred_data = pd.read_csv(filepath)
|
| 377 |
+
elif ext in ('xlsx', 'xls'):
|
| 378 |
+
pred_data = pd.read_excel(filepath)
|
| 379 |
+
else:
|
| 380 |
+
pred_data = pd.read_json(filepath)
|
| 381 |
+
|
| 382 |
+
predictions = current_pipeline.predict(pred_data)
|
| 383 |
+
pred_data['Predictions'] = predictions
|
| 384 |
+
|
| 385 |
+
out_path = os.path.join(app.config['UPLOAD_FOLDER'], f"predictions_{filename.rsplit('.',1)[0]}.csv")
|
| 386 |
+
pred_data.to_csv(out_path, index=False)
|
| 387 |
+
|
| 388 |
+
# Clean up the prediction input file (output CSV kept for download)
|
| 389 |
+
cleanup_file(filepath)
|
| 390 |
+
|
| 391 |
+
return render_template('predict.html',
|
| 392 |
+
predictions=predictions.tolist()[:100],
|
| 393 |
+
total=len(predictions),
|
| 394 |
+
download_path=out_path)
|
| 395 |
+
|
| 396 |
+
except Exception as e:
|
| 397 |
+
flash(f'Prediction error: {str(e)}', 'error')
|
| 398 |
+
return redirect(url_for('predict'))
|
| 399 |
+
|
| 400 |
+
|
| 401 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 402 |
+
@app.route('/feedback', methods=['GET', 'POST'])
|
| 403 |
+
def feedback():
|
| 404 |
+
if request.method == 'GET':
|
| 405 |
+
return render_template('feedback.html')
|
| 406 |
+
|
| 407 |
+
try:
|
| 408 |
+
fb = {
|
| 409 |
+
'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
| 410 |
+
'name': request.form.get('name'),
|
| 411 |
+
'email': request.form.get('email'),
|
| 412 |
+
'rating': request.form.get('rating'),
|
| 413 |
+
'message': request.form.get('message'),
|
| 414 |
+
}
|
| 415 |
+
fb_file = 'feedback.json'
|
| 416 |
+
existing = []
|
| 417 |
+
if os.path.exists(fb_file):
|
| 418 |
+
with open(fb_file) as f:
|
| 419 |
+
existing = json.load(f)
|
| 420 |
+
existing.append(fb)
|
| 421 |
+
with open(fb_file, 'w') as f:
|
| 422 |
+
json.dump(existing, f, indent=2)
|
| 423 |
+
flash('Thank you for your feedback!', 'success')
|
| 424 |
+
return redirect(url_for('feedback'))
|
| 425 |
+
except Exception as e:
|
| 426 |
+
flash(f'Error submitting feedback: {str(e)}', 'error')
|
| 427 |
+
return redirect(url_for('feedback'))
|
| 428 |
+
|
| 429 |
+
|
| 430 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 431 |
+
@app.route('/about')
|
| 432 |
+
def about():
|
| 433 |
+
return render_template('about.html')
|
| 434 |
+
|
| 435 |
+
|
| 436 |
+
@app.route('/documentation')
|
| 437 |
+
def documentation():
|
| 438 |
+
return render_template('documentation.html')
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
@app.errorhandler(404)
|
| 442 |
+
def not_found(e):
|
| 443 |
+
return render_template('404.html'), 404
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
@app.errorhandler(500)
|
| 447 |
+
def server_error(e):
|
| 448 |
+
return render_template('500.html'), 500
|
| 449 |
+
|
| 450 |
+
|
| 451 |
+
if __name__ == '__main__':
|
| 452 |
+
# use_reloader=False prevents the server from restarting mid-training
|
| 453 |
+
# when the pipeline saves .pkl files or the deployable app zip.
|
| 454 |
+
port = int(os.environ.get('PORT', 5000))
|
| 455 |
+
app.run(debug=True, use_reloader=False, host='0.0.0.0', port=port)
|
feedback.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"timestamp": "2026-02-15 17:45:58",
|
| 4 |
+
"name": "deepu",
|
| 5 |
+
"email": "lundai.1@gmail.com",
|
| 6 |
+
"rating": "2",
|
| 7 |
+
"message": "gg"
|
| 8 |
+
},
|
| 9 |
+
{
|
| 10 |
+
"timestamp": "2026-02-15 20:42:01",
|
| 11 |
+
"name": "Nausad Ali",
|
| 12 |
+
"email": "Nausad@gmail.com",
|
| 13 |
+
"rating": "1",
|
| 14 |
+
"message": "niceeeee"
|
| 15 |
+
}
|
| 16 |
+
]
|
gitignore
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
*.so
|
| 6 |
+
.Python
|
| 7 |
+
env/
|
| 8 |
+
venv/
|
| 9 |
+
ENV/
|
| 10 |
+
build/
|
| 11 |
+
develop-eggs/
|
| 12 |
+
dist/
|
| 13 |
+
downloads/
|
| 14 |
+
eggs/
|
| 15 |
+
.eggs/
|
| 16 |
+
lib/
|
| 17 |
+
lib64/
|
| 18 |
+
parts/
|
| 19 |
+
sdist/
|
| 20 |
+
var/
|
| 21 |
+
wheels/
|
| 22 |
+
*.egg-info/
|
| 23 |
+
.installed.cfg
|
| 24 |
+
*.egg
|
| 25 |
+
|
| 26 |
+
# Flask
|
| 27 |
+
instance/
|
| 28 |
+
.webassets-cache
|
| 29 |
+
|
| 30 |
+
# Project specific
|
| 31 |
+
uploads/*
|
| 32 |
+
!uploads/.gitkeep
|
| 33 |
+
saved_models/*
|
| 34 |
+
!saved_models/.gitkeep
|
| 35 |
+
feedback.json
|
| 36 |
+
|
| 37 |
+
# Environment
|
| 38 |
+
.env
|
| 39 |
+
.venv
|
| 40 |
+
.env.local
|
| 41 |
+
|
| 42 |
+
# IDE
|
| 43 |
+
.vscode/
|
| 44 |
+
.idea/
|
| 45 |
+
*.swp
|
| 46 |
+
*.swo
|
| 47 |
+
*~
|
| 48 |
+
.DS_Store
|
| 49 |
+
|
| 50 |
+
# Testing
|
| 51 |
+
.pytest_cache/
|
| 52 |
+
.coverage
|
| 53 |
+
htmlcov/
|
| 54 |
+
|
| 55 |
+
#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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Data2Model - Automated Machine Learning Pipeline
|
| 3 |
+
Fully updated with all fixes:
|
| 4 |
+
1. Imputation instead of deletion for null values
|
| 5 |
+
2. Per-column null strategy support
|
| 6 |
+
3. Optional target column for unsupervised
|
| 7 |
+
4. Flexible train-test and train-test-validation splits
|
| 8 |
+
5. Dynamic encoding (only when categorical columns exist)
|
| 9 |
+
6. Per-column scaling
|
| 10 |
+
7. Per-column encoding
|
| 11 |
+
8. Proper data type detection (numeric vs categorical)
|
| 12 |
+
9. Dashboard with visualizations
|
| 13 |
+
10. Target column excluded from preprocessing
|
| 14 |
+
11. Download preprocessing components
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
import numpy as np
|
| 18 |
+
import pandas as pd
|
| 19 |
+
import pickle
|
| 20 |
+
import os
|
| 21 |
+
import json
|
| 22 |
+
import base64
|
| 23 |
+
from io import BytesIO
|
| 24 |
+
from datetime import datetime
|
| 25 |
+
import matplotlib
|
| 26 |
+
matplotlib.use('Agg') # Non-interactive backend
|
| 27 |
+
import matplotlib.pyplot as plt
|
| 28 |
+
import seaborn as sns
|
| 29 |
+
from sklearn.model_selection import train_test_split
|
| 30 |
+
from sklearn.preprocessing import (
|
| 31 |
+
StandardScaler, MinMaxScaler, RobustScaler, Normalizer,
|
| 32 |
+
LabelEncoder, OneHotEncoder, OrdinalEncoder, LabelBinarizer
|
| 33 |
+
)
|
| 34 |
+
from sklearn.impute import SimpleImputer
|
| 35 |
+
from sklearn.metrics import (
|
| 36 |
+
accuracy_score, precision_score, recall_score, f1_score,
|
| 37 |
+
mean_squared_error, r2_score, mean_absolute_error,
|
| 38 |
+
classification_report, confusion_matrix
|
| 39 |
+
)
|
| 40 |
+
import warnings
|
| 41 |
+
warnings.filterwarnings('ignore')
|
| 42 |
+
|
| 43 |
+
import sys, io
|
| 44 |
+
if sys.stdout.encoding != 'utf-8':
|
| 45 |
+
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
| 46 |
+
if sys.stderr.encoding != 'utf-8':
|
| 47 |
+
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace')
|
| 48 |
+
|
| 49 |
+
# Supervised - Classification
|
| 50 |
+
from sklearn.linear_model import LogisticRegression
|
| 51 |
+
from sklearn.tree import DecisionTreeClassifier
|
| 52 |
+
from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier, AdaBoostClassifier
|
| 53 |
+
from sklearn.svm import SVC
|
| 54 |
+
from sklearn.neighbors import KNeighborsClassifier
|
| 55 |
+
from sklearn.naive_bayes import GaussianNB
|
| 56 |
+
|
| 57 |
+
# Supervised - Regression
|
| 58 |
+
from sklearn.linear_model import LinearRegression
|
| 59 |
+
from sklearn.tree import DecisionTreeRegressor
|
| 60 |
+
from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor, AdaBoostRegressor
|
| 61 |
+
from sklearn.svm import SVR
|
| 62 |
+
from sklearn.neighbors import KNeighborsRegressor
|
| 63 |
+
|
| 64 |
+
# Unsupervised
|
| 65 |
+
from sklearn.cluster import KMeans, DBSCAN, AgglomerativeClustering
|
| 66 |
+
from sklearn.decomposition import PCA
|
| 67 |
+
|
| 68 |
+
# Advanced Models
|
| 69 |
+
try:
|
| 70 |
+
import xgboost as xgb
|
| 71 |
+
XGBOOST_AVAILABLE = True
|
| 72 |
+
except ImportError:
|
| 73 |
+
XGBOOST_AVAILABLE = False
|
| 74 |
+
|
| 75 |
+
try:
|
| 76 |
+
import lightgbm as lgb
|
| 77 |
+
LIGHTGBM_AVAILABLE = True
|
| 78 |
+
except ImportError:
|
| 79 |
+
LIGHTGBM_AVAILABLE = False
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 83 |
+
# FIX 8: Strict data-type detector
|
| 84 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 85 |
+
def detect_column_types(data, categorical_overrides=None):
|
| 86 |
+
"""
|
| 87 |
+
Detect numeric vs categorical columns relying purely on dataframe dtypes,
|
| 88 |
+
not heuristics like low cardinality or unique value count, unless explicitly overridden.
|
| 89 |
+
"""
|
| 90 |
+
if categorical_overrides is None:
|
| 91 |
+
categorical_overrides = []
|
| 92 |
+
|
| 93 |
+
numeric_cols = []
|
| 94 |
+
categorical_cols = []
|
| 95 |
+
|
| 96 |
+
for col in data.columns:
|
| 97 |
+
if col in categorical_overrides:
|
| 98 |
+
categorical_cols.append(col)
|
| 99 |
+
continue
|
| 100 |
+
|
| 101 |
+
dtype_str = str(data[col].dtype).lower()
|
| 102 |
+
|
| 103 |
+
# Check for numeric types (int, float, double, etc.)
|
| 104 |
+
if 'int' in dtype_str or 'float' in dtype_str or 'double' in dtype_str or 'number' in dtype_str:
|
| 105 |
+
numeric_cols.append(col)
|
| 106 |
+
# Check for object, category, boolean, string
|
| 107 |
+
elif 'object' in dtype_str or 'category' in dtype_str or 'bool' in dtype_str or 'str' in dtype_str:
|
| 108 |
+
categorical_cols.append(col)
|
| 109 |
+
else:
|
| 110 |
+
# default fallback
|
| 111 |
+
categorical_cols.append(col)
|
| 112 |
+
|
| 113 |
+
return numeric_cols, categorical_cols
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
class AutoMLPipeline:
|
| 119 |
+
"""
|
| 120 |
+
Automated Machine Learning Pipeline
|
| 121 |
+
All 8 system limitations addressed.
|
| 122 |
+
"""
|
| 123 |
+
|
| 124 |
+
def __init__(self):
|
| 125 |
+
self.model = None
|
| 126 |
+
self.scalers = {} # per-column scalers
|
| 127 |
+
self.encoders = {} # per-column encoders
|
| 128 |
+
self.imputers = {} # per-column imputers
|
| 129 |
+
self.feature_names = None
|
| 130 |
+
self.target_name = None
|
| 131 |
+
self.problem_type = None
|
| 132 |
+
self.model_name = None
|
| 133 |
+
self.preprocessing_steps = []
|
| 134 |
+
self.results = {}
|
| 135 |
+
self.numeric_cols = []
|
| 136 |
+
self.categorical_cols = []
|
| 137 |
+
|
| 138 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 139 |
+
# Data Loading
|
| 140 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 141 |
+
def load_data(self, file_path, file_type='csv'):
|
| 142 |
+
try:
|
| 143 |
+
if file_type.lower() == 'csv':
|
| 144 |
+
data = pd.read_csv(file_path)
|
| 145 |
+
elif file_type.lower() in ['xlsx', 'excel', 'xls']:
|
| 146 |
+
data = pd.read_excel(file_path)
|
| 147 |
+
elif file_type.lower() == 'json':
|
| 148 |
+
data = pd.read_json(file_path)
|
| 149 |
+
else:
|
| 150 |
+
raise ValueError(f"Unsupported file type: {file_type}")
|
| 151 |
+
|
| 152 |
+
# Strip leading/trailing whitespaces from string columns
|
| 153 |
+
for col in data.columns:
|
| 154 |
+
if str(data[col].dtype) in ('object', 'string'):
|
| 155 |
+
data[col] = data[col].apply(lambda x: str(x).strip() if pd.notnull(x) else x)
|
| 156 |
+
|
| 157 |
+
# Standardize and replace common string null placeholders with actual np.nan
|
| 158 |
+
placeholders = ['null', 'NULL', 'Null', 'n/a', 'N/A', 'na', 'NA', 'nan', 'NaN', 'NAN', '-', '?', '']
|
| 159 |
+
data = data.replace(placeholders, np.nan)
|
| 160 |
+
|
| 161 |
+
print(f"β Dataset loaded: {data.shape[0]} rows Γ {data.shape[1]} columns")
|
| 162 |
+
return data
|
| 163 |
+
except Exception as e:
|
| 164 |
+
raise Exception(f"Error loading data: {str(e)}")
|
| 165 |
+
|
| 166 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 167 |
+
# Data Analysis
|
| 168 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 169 |
+
def analyze_data(self, data, categorical_overrides=None, target_column=None):
|
| 170 |
+
"""Analyze dataset and return summary including smart type detection."""
|
| 171 |
+
# Ensure numeric-looking columns accidentally read as strings are safely converted before detection
|
| 172 |
+
data = data.copy()
|
| 173 |
+
for col in data.columns:
|
| 174 |
+
if col == target_column:
|
| 175 |
+
continue
|
| 176 |
+
if str(data[col].dtype) in ('object', 'string'):
|
| 177 |
+
# Try to convert to numeric
|
| 178 |
+
converted = pd.to_numeric(data[col], errors='coerce')
|
| 179 |
+
non_null_original = data[col].dropna().shape[0]
|
| 180 |
+
non_null_converted = converted.dropna().shape[0]
|
| 181 |
+
if non_null_original > 0 and non_null_converted >= 0.9 * non_null_original:
|
| 182 |
+
data[col] = converted
|
| 183 |
+
|
| 184 |
+
numeric_cols, categorical_cols = detect_column_types(data, categorical_overrides)
|
| 185 |
+
|
| 186 |
+
# FIX 3: Exclude target column from preprocessing lists
|
| 187 |
+
if target_column and target_column in numeric_cols:
|
| 188 |
+
numeric_cols.remove(target_column)
|
| 189 |
+
if target_column and target_column in categorical_cols:
|
| 190 |
+
categorical_cols.remove(target_column)
|
| 191 |
+
|
| 192 |
+
# Column-level stats
|
| 193 |
+
col_stats = {}
|
| 194 |
+
for col in data.columns:
|
| 195 |
+
col_stats[col] = {
|
| 196 |
+
'dtype': str(data[col].dtype),
|
| 197 |
+
'missing': int(data[col].isnull().sum()),
|
| 198 |
+
'unique': int(data[col].nunique()),
|
| 199 |
+
'detected_type': 'categorical' if col in categorical_cols else 'numeric'
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
# Visualization data
|
| 203 |
+
viz_data = self._generate_visualization_data(data, numeric_cols, categorical_cols)
|
| 204 |
+
|
| 205 |
+
return {
|
| 206 |
+
'shape': data.shape,
|
| 207 |
+
'columns': list(data.columns),
|
| 208 |
+
'dtypes': {c: str(t) for c, t in data.dtypes.items()},
|
| 209 |
+
'missing_values': data.isnull().sum().to_dict(),
|
| 210 |
+
'numeric_columns': numeric_cols,
|
| 211 |
+
'categorical_columns': categorical_cols,
|
| 212 |
+
'statistics': data.describe().to_dict(),
|
| 213 |
+
'duplicates': int(data.duplicated().sum()),
|
| 214 |
+
'col_stats': col_stats,
|
| 215 |
+
'viz_data': viz_data
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
def _generate_visualization_data(self, data, numeric_cols, categorical_cols):
|
| 219 |
+
"""Generate data for charts"""
|
| 220 |
+
viz = {}
|
| 221 |
+
|
| 222 |
+
# Missing values chart
|
| 223 |
+
missing = data.isnull().sum()
|
| 224 |
+
missing = missing[missing > 0].sort_values(ascending=False)
|
| 225 |
+
viz['missing_labels'] = missing.index.tolist()
|
| 226 |
+
viz['missing_values'] = missing.values.tolist()
|
| 227 |
+
|
| 228 |
+
# Data types distribution
|
| 229 |
+
type_counts = {'Numeric': len(numeric_cols), 'Categorical': len(categorical_cols)}
|
| 230 |
+
viz['type_labels'] = list(type_counts.keys())
|
| 231 |
+
viz['type_counts'] = list(type_counts.values())
|
| 232 |
+
|
| 233 |
+
# Numeric distributions (first 6 only)
|
| 234 |
+
viz['numeric_distributions'] = []
|
| 235 |
+
for col in numeric_cols[:6]:
|
| 236 |
+
try:
|
| 237 |
+
hist, bins = np.histogram(data[col].dropna(), bins=20)
|
| 238 |
+
viz['numeric_distributions'].append({
|
| 239 |
+
'column': col,
|
| 240 |
+
'bins': bins[:-1].tolist(),
|
| 241 |
+
'counts': hist.tolist()
|
| 242 |
+
})
|
| 243 |
+
except:
|
| 244 |
+
pass
|
| 245 |
+
|
| 246 |
+
# Categorical value counts (top 5 columns, top 10 values each)
|
| 247 |
+
viz['categorical_distributions'] = []
|
| 248 |
+
for col in categorical_cols[:5]:
|
| 249 |
+
try:
|
| 250 |
+
vc = data[col].value_counts().head(10)
|
| 251 |
+
viz['categorical_distributions'].append({
|
| 252 |
+
'column': col,
|
| 253 |
+
'labels': vc.index.astype(str).tolist(),
|
| 254 |
+
'counts': vc.values.tolist()
|
| 255 |
+
})
|
| 256 |
+
except:
|
| 257 |
+
pass
|
| 258 |
+
|
| 259 |
+
# Correlation matrix (numeric only, max 10 cols)
|
| 260 |
+
if len(numeric_cols) > 1:
|
| 261 |
+
corr_cols = numeric_cols[:10]
|
| 262 |
+
try:
|
| 263 |
+
corr = data[corr_cols].corr()
|
| 264 |
+
viz['correlation'] = {
|
| 265 |
+
'columns': corr_cols,
|
| 266 |
+
'matrix': corr.values.tolist()
|
| 267 |
+
}
|
| 268 |
+
except:
|
| 269 |
+
viz['correlation'] = None
|
| 270 |
+
else:
|
| 271 |
+
viz['correlation'] = None
|
| 272 |
+
|
| 273 |
+
return viz
|
| 274 |
+
|
| 275 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 276 |
+
# ENHANCEMENT 1: Dashboard Visualizations
|
| 277 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 278 |
+
def generate_visualizations(self, data, numeric_cols, categorical_cols, max_plots=6):
|
| 279 |
+
"""
|
| 280 |
+
Generate dashboard visualizations and return as base64 encoded images.
|
| 281 |
+
Returns dict with encoded plot images.
|
| 282 |
+
"""
|
| 283 |
+
plots = {}
|
| 284 |
+
|
| 285 |
+
# Set style
|
| 286 |
+
sns.set_style("whitegrid")
|
| 287 |
+
plt.rcParams['figure.facecolor'] = 'white'
|
| 288 |
+
|
| 289 |
+
# 1. Missing Values Heatmap
|
| 290 |
+
if data.isnull().sum().sum() > 0:
|
| 291 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
| 292 |
+
missing_data = data.isnull().sum()
|
| 293 |
+
missing_data = missing_data[missing_data > 0].sort_values(ascending=False)
|
| 294 |
+
|
| 295 |
+
if len(missing_data) > 0:
|
| 296 |
+
ax.barh(range(len(missing_data)), missing_data.values, color='#e74c3c')
|
| 297 |
+
ax.set_yticks(range(len(missing_data)))
|
| 298 |
+
ax.set_yticklabels(missing_data.index)
|
| 299 |
+
ax.set_xlabel('Missing Values Count', fontsize=12)
|
| 300 |
+
ax.set_title('Missing Values by Column', fontsize=14, fontweight='bold')
|
| 301 |
+
ax.grid(axis='x', alpha=0.3)
|
| 302 |
+
|
| 303 |
+
for i, v in enumerate(missing_data.values):
|
| 304 |
+
ax.text(v + 0.5, i, str(int(v)), va='center', fontsize=10)
|
| 305 |
+
|
| 306 |
+
plt.tight_layout()
|
| 307 |
+
plots['missing_values'] = self._fig_to_base64(fig)
|
| 308 |
+
plt.close(fig)
|
| 309 |
+
|
| 310 |
+
# 2. Numeric Features - Histograms (first 6)
|
| 311 |
+
if numeric_cols:
|
| 312 |
+
num_to_plot = min(len(numeric_cols), max_plots)
|
| 313 |
+
fig, axes = plt.subplots(2, 3, figsize=(15, 8))
|
| 314 |
+
axes = axes.flatten()
|
| 315 |
+
|
| 316 |
+
for idx, col in enumerate(numeric_cols[:num_to_plot]):
|
| 317 |
+
data[col].dropna().hist(bins=30, ax=axes[idx], color='#3498db', edgecolor='black')
|
| 318 |
+
axes[idx].set_title(f'{col}', fontsize=11, fontweight='bold')
|
| 319 |
+
axes[idx].set_xlabel('Value', fontsize=9)
|
| 320 |
+
axes[idx].set_ylabel('Frequency', fontsize=9)
|
| 321 |
+
axes[idx].grid(axis='y', alpha=0.3)
|
| 322 |
+
|
| 323 |
+
# Hide unused subplots
|
| 324 |
+
for idx in range(num_to_plot, 6):
|
| 325 |
+
axes[idx].axis('off')
|
| 326 |
+
|
| 327 |
+
plt.suptitle('Numeric Features Distribution', fontsize=14, fontweight='bold', y=1.00)
|
| 328 |
+
plt.tight_layout()
|
| 329 |
+
plots['numeric_histograms'] = self._fig_to_base64(fig)
|
| 330 |
+
plt.close(fig)
|
| 331 |
+
|
| 332 |
+
# 3. Numeric Features - Box Plots (first 6)
|
| 333 |
+
if numeric_cols:
|
| 334 |
+
num_to_plot = min(len(numeric_cols), max_plots)
|
| 335 |
+
fig, axes = plt.subplots(2, 3, figsize=(15, 8))
|
| 336 |
+
axes = axes.flatten()
|
| 337 |
+
|
| 338 |
+
for idx, col in enumerate(numeric_cols[:num_to_plot]):
|
| 339 |
+
axes[idx].boxplot(data[col].dropna(), vert=True, patch_artist=True,
|
| 340 |
+
boxprops=dict(facecolor='#2ecc71', alpha=0.7),
|
| 341 |
+
medianprops=dict(color='red', linewidth=2))
|
| 342 |
+
axes[idx].set_title(f'{col}', fontsize=11, fontweight='bold')
|
| 343 |
+
axes[idx].set_ylabel('Value', fontsize=9)
|
| 344 |
+
axes[idx].grid(axis='y', alpha=0.3)
|
| 345 |
+
|
| 346 |
+
for idx in range(num_to_plot, 6):
|
| 347 |
+
axes[idx].axis('off')
|
| 348 |
+
|
| 349 |
+
plt.suptitle('Numeric Features - Outlier Detection', fontsize=14, fontweight='bold', y=1.00)
|
| 350 |
+
plt.tight_layout()
|
| 351 |
+
plots['numeric_boxplots'] = self._fig_to_base64(fig)
|
| 352 |
+
plt.close(fig)
|
| 353 |
+
|
| 354 |
+
# 4. Correlation Heatmap (if more than 2 numeric columns)
|
| 355 |
+
if len(numeric_cols) >= 2:
|
| 356 |
+
fig, ax = plt.subplots(figsize=(10, 8))
|
| 357 |
+
numeric_data = data[numeric_cols].dropna()
|
| 358 |
+
|
| 359 |
+
if len(numeric_data) > 0:
|
| 360 |
+
corr = numeric_data.corr()
|
| 361 |
+
mask = np.triu(np.ones_like(corr, dtype=bool))
|
| 362 |
+
|
| 363 |
+
sns.heatmap(corr, mask=mask, annot=True, fmt='.2f', cmap='coolwarm',
|
| 364 |
+
center=0, square=True, linewidths=1, cbar_kws={"shrink": 0.8},
|
| 365 |
+
ax=ax, vmin=-1, vmax=1)
|
| 366 |
+
ax.set_title('Correlation Matrix - Numeric Features', fontsize=14, fontweight='bold')
|
| 367 |
+
plt.tight_layout()
|
| 368 |
+
plots['correlation_heatmap'] = self._fig_to_base64(fig)
|
| 369 |
+
plt.close(fig)
|
| 370 |
+
|
| 371 |
+
# 5. Categorical Features - Bar Charts (first 6, top 10 values each)
|
| 372 |
+
if categorical_cols:
|
| 373 |
+
cat_to_plot = min(len(categorical_cols), max_plots)
|
| 374 |
+
fig, axes = plt.subplots(2, 3, figsize=(15, 8))
|
| 375 |
+
axes = axes.flatten()
|
| 376 |
+
|
| 377 |
+
for idx, col in enumerate(categorical_cols[:cat_to_plot]):
|
| 378 |
+
value_counts = data[col].value_counts().head(10)
|
| 379 |
+
axes[idx].barh(range(len(value_counts)), value_counts.values, color='#9b59b6')
|
| 380 |
+
axes[idx].set_yticks(range(len(value_counts)))
|
| 381 |
+
axes[idx].set_yticklabels(value_counts.index, fontsize=9)
|
| 382 |
+
axes[idx].set_xlabel('Count', fontsize=9)
|
| 383 |
+
axes[idx].set_title(f'{col} (Top 10)', fontsize=11, fontweight='bold')
|
| 384 |
+
axes[idx].grid(axis='x', alpha=0.3)
|
| 385 |
+
|
| 386 |
+
for i, v in enumerate(value_counts.values):
|
| 387 |
+
axes[idx].text(v + 0.5, i, str(int(v)), va='center', fontsize=8)
|
| 388 |
+
|
| 389 |
+
for idx in range(cat_to_plot, 6):
|
| 390 |
+
axes[idx].axis('off')
|
| 391 |
+
|
| 392 |
+
plt.suptitle('Categorical Features Distribution', fontsize=14, fontweight='bold', y=1.00)
|
| 393 |
+
plt.tight_layout()
|
| 394 |
+
plots['categorical_distributions'] = self._fig_to_base64(fig)
|
| 395 |
+
plt.close(fig)
|
| 396 |
+
|
| 397 |
+
# 6. Data Quality Overview
|
| 398 |
+
fig, axes = plt.subplots(1, 2, figsize=(12, 5))
|
| 399 |
+
|
| 400 |
+
# Column types pie chart
|
| 401 |
+
type_counts = pd.Series({
|
| 402 |
+
'Numeric': len(numeric_cols),
|
| 403 |
+
'Categorical': len(categorical_cols)
|
| 404 |
+
})
|
| 405 |
+
axes[0].pie(type_counts.values, labels=type_counts.index, autopct='%1.1f%%',
|
| 406 |
+
colors=['#3498db', '#e67e22'], startangle=90)
|
| 407 |
+
axes[0].set_title('Column Types', fontsize=12, fontweight='bold')
|
| 408 |
+
|
| 409 |
+
# Missing vs Complete data
|
| 410 |
+
total_cells = data.shape[0] * data.shape[1]
|
| 411 |
+
missing_cells = data.isnull().sum().sum()
|
| 412 |
+
complete_cells = total_cells - missing_cells
|
| 413 |
+
|
| 414 |
+
completeness = pd.Series({
|
| 415 |
+
'Complete': complete_cells,
|
| 416 |
+
'Missing': missing_cells
|
| 417 |
+
})
|
| 418 |
+
axes[1].pie(completeness.values, labels=completeness.index, autopct='%1.1f%%',
|
| 419 |
+
colors=['#2ecc71', '#e74c3c'], startangle=90)
|
| 420 |
+
axes[1].set_title('Data Completeness', fontsize=12, fontweight='bold')
|
| 421 |
+
|
| 422 |
+
plt.suptitle('Dataset Quality Overview', fontsize=14, fontweight='bold', y=1.02)
|
| 423 |
+
plt.tight_layout()
|
| 424 |
+
plots['data_quality'] = self._fig_to_base64(fig)
|
| 425 |
+
plt.close(fig)
|
| 426 |
+
|
| 427 |
+
return plots
|
| 428 |
+
|
| 429 |
+
def _fig_to_base64(self, fig):
|
| 430 |
+
"""Convert matplotlib figure to base64 encoded string for HTML embedding."""
|
| 431 |
+
buffer = BytesIO()
|
| 432 |
+
fig.savefig(buffer, format='png', dpi=100, bbox_inches='tight')
|
| 433 |
+
buffer.seek(0)
|
| 434 |
+
image_base64 = base64.b64encode(buffer.read()).decode('utf-8')
|
| 435 |
+
buffer.close()
|
| 436 |
+
return f"data:image/png;base64,{image_base64}"
|
| 437 |
+
|
| 438 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 439 |
+
# FIX 1 & 2: Null value imputation per column (no auto-deletion)
|
| 440 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 441 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 442 |
+
# FIX 1 & 2: Null value imputation per column (no auto-deletion)
|
| 443 |
+
# βββββββββββββββββββββββοΏ½οΏ½βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 444 |
+
def handle_missing_values(self, data, null_strategies=None, target_column=None):
|
| 445 |
+
"""
|
| 446 |
+
Handle missing values using imputation.
|
| 447 |
+
null_strategies: dict {col_name: 'mean'|'median'|'mode'|'drop'|'zero'|'custom_[val]'}
|
| 448 |
+
or None (auto: median for numeric, mode for categorical)
|
| 449 |
+
"""
|
| 450 |
+
if null_strategies is None:
|
| 451 |
+
null_strategies = {}
|
| 452 |
+
|
| 453 |
+
# If it's a supervised problem and the target has missing values, drop those rows immediately to avoid training issues
|
| 454 |
+
if target_column and target_column in data.columns:
|
| 455 |
+
if data[target_column].isnull().any():
|
| 456 |
+
before = len(data)
|
| 457 |
+
data = data.dropna(subset=[target_column])
|
| 458 |
+
print(f" Dropped {before - len(data)} rows with missing target '{target_column}'")
|
| 459 |
+
self.preprocessing_steps.append(f"Null handling '{target_column}' (Target): drop rows")
|
| 460 |
+
|
| 461 |
+
# Set up a list to track zero-filled or custom-filled constant columns for predict
|
| 462 |
+
if not hasattr(self, 'custom_impute_values'):
|
| 463 |
+
self.custom_impute_values = {}
|
| 464 |
+
|
| 465 |
+
# Impute all columns (excluding target if present) so that if they have missing values in predict, we can impute them
|
| 466 |
+
cols_to_impute = [col for col in data.columns if col != target_column]
|
| 467 |
+
|
| 468 |
+
for col in cols_to_impute:
|
| 469 |
+
strategy = null_strategies.get(col, 'auto')
|
| 470 |
+
|
| 471 |
+
# If strategy is auto:
|
| 472 |
+
if strategy == 'auto':
|
| 473 |
+
# Determine fallback based on datatype
|
| 474 |
+
if data[col].dtype in ['object', 'category', 'bool']:
|
| 475 |
+
strategy = 'most_frequent'
|
| 476 |
+
else:
|
| 477 |
+
strategy = 'median'
|
| 478 |
+
|
| 479 |
+
if strategy == 'drop':
|
| 480 |
+
if data[col].isnull().any():
|
| 481 |
+
before = len(data)
|
| 482 |
+
data = data.dropna(subset=[col])
|
| 483 |
+
print(f" Dropped {before - len(data)} rows with missing '{col}'")
|
| 484 |
+
self.preprocessing_steps.append(f"Null handling '{col}': drop rows")
|
| 485 |
+
# Store drop strategy in imputers so predict can handle it
|
| 486 |
+
self.imputers[col] = 'drop'
|
| 487 |
+
continue
|
| 488 |
+
|
| 489 |
+
if strategy == 'mode':
|
| 490 |
+
strategy = 'most_frequent'
|
| 491 |
+
|
| 492 |
+
# Custom constant value replacement:
|
| 493 |
+
if strategy == 'zero':
|
| 494 |
+
val = 0 if data[col].dtype not in ['object', 'category', 'bool'] else '0'
|
| 495 |
+
self.custom_impute_values[col] = val
|
| 496 |
+
data[col] = data[col].fillna(val)
|
| 497 |
+
self.preprocessing_steps.append(f"Null handling '{col}': fill with custom constant (0)")
|
| 498 |
+
# Fit a constant imputer to be Scikit-learn native
|
| 499 |
+
imputer = SimpleImputer(strategy='constant', fill_value=val)
|
| 500 |
+
imputer.fit(data[[col]])
|
| 501 |
+
self.imputers[col] = imputer
|
| 502 |
+
continue
|
| 503 |
+
elif strategy.startswith('custom_'):
|
| 504 |
+
val = strategy[7:] # extract the value after "custom_"
|
| 505 |
+
# Try to convert to float/int if numeric
|
| 506 |
+
if data[col].dtype not in ['object', 'category', 'bool']:
|
| 507 |
+
try:
|
| 508 |
+
if '.' in val:
|
| 509 |
+
val = float(val)
|
| 510 |
+
else:
|
| 511 |
+
val = int(val)
|
| 512 |
+
except ValueError:
|
| 513 |
+
pass
|
| 514 |
+
self.custom_impute_values[col] = val
|
| 515 |
+
data[col] = data[col].fillna(val)
|
| 516 |
+
self.preprocessing_steps.append(f"Null handling '{col}': fill with custom constant ({val})")
|
| 517 |
+
imputer = SimpleImputer(strategy='constant', fill_value=val)
|
| 518 |
+
imputer.fit(data[[col]])
|
| 519 |
+
self.imputers[col] = imputer
|
| 520 |
+
continue
|
| 521 |
+
|
| 522 |
+
if strategy == 'mean':
|
| 523 |
+
if data[col].dtype in ['object', 'category', 'bool']:
|
| 524 |
+
strategy = 'most_frequent' # fallback for categorical
|
| 525 |
+
|
| 526 |
+
# Fit standard SimpleImputer (mean, median, most_frequent)
|
| 527 |
+
try:
|
| 528 |
+
imputer = SimpleImputer(strategy=strategy)
|
| 529 |
+
# Fit on data
|
| 530 |
+
data[[col]] = imputer.fit_transform(data[[col]])
|
| 531 |
+
self.imputers[col] = imputer
|
| 532 |
+
self.preprocessing_steps.append(f"Null handling '{col}': {strategy}")
|
| 533 |
+
except Exception as e:
|
| 534 |
+
print(f" β Could not impute '{col}' using {strategy}: {e}")
|
| 535 |
+
|
| 536 |
+
return data
|
| 537 |
+
|
| 538 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 539 |
+
# FIX 6 & 7: Per-column scaling and encoding
|
| 540 |
+
# βββββββββββββββββββοΏ½οΏ½οΏ½βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 541 |
+
def _get_scaler(self, method):
|
| 542 |
+
if method == 'standard':
|
| 543 |
+
return StandardScaler()
|
| 544 |
+
elif method == 'minmax':
|
| 545 |
+
return MinMaxScaler()
|
| 546 |
+
elif method == 'robust':
|
| 547 |
+
return RobustScaler()
|
| 548 |
+
elif method == 'normalizer':
|
| 549 |
+
return Normalizer()
|
| 550 |
+
return None
|
| 551 |
+
|
| 552 |
+
def scale_features(self, X_train, X_test, X_val=None, scaling_config=None, numeric_cols=None):
|
| 553 |
+
"""
|
| 554 |
+
Per-column scaling.
|
| 555 |
+
scaling_config: dict {col: method} e.g. {'age': 'standard', 'income': 'minmax'}
|
| 556 |
+
or single string 'standard' applied to all numeric cols.
|
| 557 |
+
"""
|
| 558 |
+
if numeric_cols is None:
|
| 559 |
+
numeric_cols = list(X_train.select_dtypes(include=['int64', 'float64']).columns)
|
| 560 |
+
|
| 561 |
+
if not numeric_cols:
|
| 562 |
+
print(" No numeric columns to scale")
|
| 563 |
+
return (X_train, X_test, X_val) if X_val is not None else (X_train, X_test)
|
| 564 |
+
|
| 565 |
+
# Normalise config to dict
|
| 566 |
+
if scaling_config is None or scaling_config == 'none' or scaling_config == 'auto':
|
| 567 |
+
# FIX 2: auto defaults to standard
|
| 568 |
+
default_method = 'standard' if scaling_config == 'auto' else 'none'
|
| 569 |
+
if default_method == 'none':
|
| 570 |
+
if X_val is not None:
|
| 571 |
+
return X_train, X_test, X_val
|
| 572 |
+
return X_train, X_test
|
| 573 |
+
scaling_config = {col: default_method for col in numeric_cols}
|
| 574 |
+
|
| 575 |
+
if isinstance(scaling_config, str):
|
| 576 |
+
scaling_config = {col: scaling_config for col in numeric_cols}
|
| 577 |
+
|
| 578 |
+
for col in numeric_cols:
|
| 579 |
+
method = scaling_config.get(col, 'standard')
|
| 580 |
+
# FIX 2: handle auto per-column
|
| 581 |
+
if method == 'auto':
|
| 582 |
+
method = 'standard'
|
| 583 |
+
if method == 'none':
|
| 584 |
+
continue
|
| 585 |
+
scaler = self._get_scaler(method)
|
| 586 |
+
if scaler is None:
|
| 587 |
+
continue
|
| 588 |
+
X_train[col] = scaler.fit_transform(X_train[[col]])
|
| 589 |
+
X_test[col] = scaler.transform(X_test[[col]])
|
| 590 |
+
if X_val is not None:
|
| 591 |
+
X_val[col] = scaler.transform(X_val[[col]])
|
| 592 |
+
self.scalers[col] = scaler
|
| 593 |
+
self.preprocessing_steps.append(f"Scale '{col}': {method}")
|
| 594 |
+
|
| 595 |
+
print(f"β Scaling applied to {len(self.scalers)} columns")
|
| 596 |
+
|
| 597 |
+
if X_val is not None:
|
| 598 |
+
return X_train, X_test, X_val
|
| 599 |
+
return X_train, X_test
|
| 600 |
+
|
| 601 |
+
def encode_features(self, X_train, X_test, X_val=None, encoding_config=None, categorical_cols=None):
|
| 602 |
+
"""
|
| 603 |
+
Per-column categorical encoding.
|
| 604 |
+
encoding_config: dict {col: method} e.g. {'color': 'onehot', 'grade': 'label'}
|
| 605 |
+
or single string applied to all categorical cols.
|
| 606 |
+
"""
|
| 607 |
+
if categorical_cols is None:
|
| 608 |
+
categorical_cols = list(X_train.select_dtypes(include=['object', 'category']).columns)
|
| 609 |
+
|
| 610 |
+
if not categorical_cols:
|
| 611 |
+
print(" No categorical columns to encode")
|
| 612 |
+
if X_val is not None:
|
| 613 |
+
return X_train, X_test, X_val
|
| 614 |
+
return X_train, X_test
|
| 615 |
+
|
| 616 |
+
# FIX 5: Only encode if categorical cols actually exist
|
| 617 |
+
if isinstance(encoding_config, str):
|
| 618 |
+
encoding_config = {col: encoding_config for col in categorical_cols}
|
| 619 |
+
if encoding_config is None:
|
| 620 |
+
encoding_config = {}
|
| 621 |
+
|
| 622 |
+
onehot_cols = []
|
| 623 |
+
|
| 624 |
+
for col in categorical_cols:
|
| 625 |
+
if col not in X_train.columns:
|
| 626 |
+
continue
|
| 627 |
+
method = encoding_config.get(col, 'auto')
|
| 628 |
+
|
| 629 |
+
# Auto: one-hot for β€10 unique, label for higher
|
| 630 |
+
if method == 'auto':
|
| 631 |
+
method = 'onehot' if X_train[col].nunique() <= 10 else 'label'
|
| 632 |
+
|
| 633 |
+
if method == 'onehot':
|
| 634 |
+
onehot_cols.append(col)
|
| 635 |
+
|
| 636 |
+
elif method == 'label':
|
| 637 |
+
le = LabelEncoder()
|
| 638 |
+
X_train[col] = le.fit_transform(X_train[col].astype(str))
|
| 639 |
+
X_test[col] = le.transform(X_test[col].astype(str))
|
| 640 |
+
if X_val is not None:
|
| 641 |
+
X_val[col] = le.transform(X_val[col].astype(str))
|
| 642 |
+
self.encoders[col] = le
|
| 643 |
+
self.preprocessing_steps.append(f"Encode '{col}': Label")
|
| 644 |
+
|
| 645 |
+
elif method == 'ordinal':
|
| 646 |
+
oe = OrdinalEncoder(handle_unknown='use_encoded_value', unknown_value=-1)
|
| 647 |
+
X_train[col] = oe.fit_transform(X_train[[col]])
|
| 648 |
+
X_test[col] = oe.transform(X_test[[col]])
|
| 649 |
+
if X_val is not None:
|
| 650 |
+
X_val[col] = oe.transform(X_val[[col]])
|
| 651 |
+
self.encoders[col] = oe
|
| 652 |
+
self.preprocessing_steps.append(f"Encode '{col}': Ordinal")
|
| 653 |
+
|
| 654 |
+
elif method == 'binary':
|
| 655 |
+
lb = LabelBinarizer()
|
| 656 |
+
encoded_train = lb.fit_transform(X_train[col].astype(str))
|
| 657 |
+
if encoded_train.shape[1] == 1:
|
| 658 |
+
X_train[col] = encoded_train.ravel()
|
| 659 |
+
X_test[col] = lb.transform(X_test[col].astype(str)).ravel()
|
| 660 |
+
if X_val is not None:
|
| 661 |
+
X_val[col] = lb.transform(X_val[col].astype(str)).ravel()
|
| 662 |
+
else:
|
| 663 |
+
new_cols = [f"{col}_{c}" for c in lb.classes_]
|
| 664 |
+
X_train[new_cols] = encoded_train
|
| 665 |
+
X_test[new_cols] = lb.transform(X_test[col].astype(str))
|
| 666 |
+
if X_val is not None:
|
| 667 |
+
X_val[new_cols] = lb.transform(X_val[col].astype(str))
|
| 668 |
+
X_train.drop(columns=[col], inplace=True)
|
| 669 |
+
X_test.drop(columns=[col], inplace=True)
|
| 670 |
+
if X_val is not None:
|
| 671 |
+
X_val.drop(columns=[col], inplace=True)
|
| 672 |
+
self.encoders[col] = lb
|
| 673 |
+
self.preprocessing_steps.append(f"Encode '{col}': Binary")
|
| 674 |
+
|
| 675 |
+
elif method == 'target':
|
| 676 |
+
le = LabelEncoder()
|
| 677 |
+
X_train[col] = le.fit_transform(X_train[col].astype(str))
|
| 678 |
+
X_test[col] = le.transform(X_test[col].astype(str))
|
| 679 |
+
if X_val is not None:
|
| 680 |
+
X_val[col] = le.transform(X_val[col].astype(str))
|
| 681 |
+
self.encoders[col] = le
|
| 682 |
+
self.preprocessing_steps.append(f"Encode '{col}': Target (Label)")
|
| 683 |
+
|
| 684 |
+
# Batch one-hot encoding
|
| 685 |
+
self.onehot_cols = onehot_cols
|
| 686 |
+
if onehot_cols:
|
| 687 |
+
X_train = pd.get_dummies(X_train, columns=onehot_cols, drop_first=True)
|
| 688 |
+
X_test = pd.get_dummies(X_test, columns=onehot_cols, drop_first=True)
|
| 689 |
+
if X_val is not None:
|
| 690 |
+
X_val = pd.get_dummies(X_val, columns=onehot_cols, drop_first=True)
|
| 691 |
+
|
| 692 |
+
# Align columns
|
| 693 |
+
X_test = X_test.reindex(columns=X_train.columns, fill_value=0)
|
| 694 |
+
if X_val is not None:
|
| 695 |
+
X_val = X_val.reindex(columns=X_train.columns, fill_value=0)
|
| 696 |
+
|
| 697 |
+
for col in onehot_cols:
|
| 698 |
+
self.preprocessing_steps.append(f"Encode '{col}': One-Hot")
|
| 699 |
+
|
| 700 |
+
print(f"β Encoding applied to {len(categorical_cols)} categorical columns")
|
| 701 |
+
|
| 702 |
+
if X_val is not None:
|
| 703 |
+
return X_train, X_test, X_val
|
| 704 |
+
return X_train, X_test
|
| 705 |
+
|
| 706 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 707 |
+
# Model Definitions
|
| 708 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 709 |
+
def _classification_models(self):
|
| 710 |
+
models = {
|
| 711 |
+
'Logistic Regression': LogisticRegression(max_iter=1000, random_state=42),
|
| 712 |
+
'Random Forest': RandomForestClassifier(n_estimators=100, random_state=42),
|
| 713 |
+
'Gradient Boosting': GradientBoostingClassifier(n_estimators=100, random_state=42),
|
| 714 |
+
'Decision Tree': DecisionTreeClassifier(random_state=42),
|
| 715 |
+
'KNN': KNeighborsClassifier(),
|
| 716 |
+
'Naive Bayes': GaussianNB(),
|
| 717 |
+
'SVM': SVC(random_state=42),
|
| 718 |
+
'AdaBoost': AdaBoostClassifier(random_state=42),
|
| 719 |
+
}
|
| 720 |
+
if XGBOOST_AVAILABLE:
|
| 721 |
+
models['XGBoost'] = xgb.XGBClassifier(n_estimators=100, random_state=42,
|
| 722 |
+
use_label_encoder=False, verbosity=0, eval_metric='logloss')
|
| 723 |
+
if LIGHTGBM_AVAILABLE:
|
| 724 |
+
models['LightGBM'] = lgb.LGBMClassifier(n_estimators=100, random_state=42, verbosity=-1)
|
| 725 |
+
return models
|
| 726 |
+
|
| 727 |
+
def _regression_models(self):
|
| 728 |
+
models = {
|
| 729 |
+
'Linear Regression': LinearRegression(),
|
| 730 |
+
'Random Forest': RandomForestRegressor(n_estimators=100, random_state=42),
|
| 731 |
+
'Gradient Boosting': GradientBoostingRegressor(n_estimators=100, random_state=42),
|
| 732 |
+
'Decision Tree': DecisionTreeRegressor(random_state=42),
|
| 733 |
+
'KNN': KNeighborsRegressor(),
|
| 734 |
+
'SVR': SVR(),
|
| 735 |
+
'AdaBoost': AdaBoostRegressor(random_state=42),
|
| 736 |
+
}
|
| 737 |
+
if XGBOOST_AVAILABLE:
|
| 738 |
+
models['XGBoost'] = xgb.XGBRegressor(n_estimators=100, random_state=42, verbosity=0)
|
| 739 |
+
if LIGHTGBM_AVAILABLE:
|
| 740 |
+
models['LightGBM'] = lgb.LGBMRegressor(n_estimators=100, random_state=42, verbosity=-1)
|
| 741 |
+
return models
|
| 742 |
+
|
| 743 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 744 |
+
# Train Models
|
| 745 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββοΏ½οΏ½οΏ½ββββββ
|
| 746 |
+
def train_model(self, X_train, y_train, X_test, y_test, problem_type='auto'):
|
| 747 |
+
if problem_type == 'auto':
|
| 748 |
+
problem_type = 'classification' if (
|
| 749 |
+
y_train.dtype == 'object' or y_train.nunique() < 20
|
| 750 |
+
) else 'regression'
|
| 751 |
+
|
| 752 |
+
self.problem_type = problem_type
|
| 753 |
+
models = (self._classification_models() if problem_type == 'classification'
|
| 754 |
+
else self._regression_models())
|
| 755 |
+
|
| 756 |
+
print(f"\n{'='*55}")
|
| 757 |
+
print(f"π€ Training {problem_type.upper()} models...")
|
| 758 |
+
print(f"{'='*55}\n")
|
| 759 |
+
|
| 760 |
+
best_model = None
|
| 761 |
+
best_score = -np.inf if problem_type == 'classification' else np.inf
|
| 762 |
+
best_name = None
|
| 763 |
+
rows = []
|
| 764 |
+
|
| 765 |
+
for name, model in models.items():
|
| 766 |
+
try:
|
| 767 |
+
print(f" Training {name}...", end=" ")
|
| 768 |
+
model.fit(X_train, y_train)
|
| 769 |
+
y_pred = model.predict(X_test)
|
| 770 |
+
|
| 771 |
+
if problem_type == 'classification':
|
| 772 |
+
score = accuracy_score(y_test, y_pred)
|
| 773 |
+
rows.append({'Model': name,
|
| 774 |
+
'Accuracy': round(score, 4),
|
| 775 |
+
'Precision': round(precision_score(y_test, y_pred, average='weighted', zero_division=0), 4),
|
| 776 |
+
'Recall': round(recall_score(y_test, y_pred, average='weighted', zero_division=0), 4),
|
| 777 |
+
'F1': round(f1_score(y_test, y_pred, average='weighted', zero_division=0), 4)})
|
| 778 |
+
print(f"Accuracy: {score:.4f}")
|
| 779 |
+
if score > best_score:
|
| 780 |
+
best_score, best_model, best_name = score, model, name
|
| 781 |
+
else:
|
| 782 |
+
rmse = np.sqrt(mean_squared_error(y_test, y_pred))
|
| 783 |
+
r2 = r2_score(y_test, y_pred)
|
| 784 |
+
rows.append({'Model': name,
|
| 785 |
+
'RMSE': round(rmse, 4),
|
| 786 |
+
'MAE': round(mean_absolute_error(y_test, y_pred), 4),
|
| 787 |
+
'R2': round(r2, 4)})
|
| 788 |
+
print(f"RMSE: {rmse:.4f} RΒ²: {r2:.4f}")
|
| 789 |
+
if rmse < best_score:
|
| 790 |
+
best_score, best_model, best_name = rmse, model, name
|
| 791 |
+
except Exception as e:
|
| 792 |
+
print(f"β {e}")
|
| 793 |
+
|
| 794 |
+
self.model = best_model
|
| 795 |
+
self.model_name = best_name
|
| 796 |
+
self.comparison_table = pd.DataFrame(rows)
|
| 797 |
+
|
| 798 |
+
print(f"\nπ Best: {best_name}")
|
| 799 |
+
|
| 800 |
+
# Final evaluation metrics
|
| 801 |
+
y_pred = best_model.predict(X_test)
|
| 802 |
+
if problem_type == 'classification':
|
| 803 |
+
self.results = {
|
| 804 |
+
'model_name': best_name,
|
| 805 |
+
'problem_type': problem_type,
|
| 806 |
+
'accuracy': accuracy_score(y_test, y_pred),
|
| 807 |
+
'precision': precision_score(y_test, y_pred, average='weighted', zero_division=0),
|
| 808 |
+
'recall': recall_score(y_test, y_pred, average='weighted', zero_division=0),
|
| 809 |
+
'f1_score': f1_score(y_test, y_pred, average='weighted', zero_division=0),
|
| 810 |
+
'preprocessing_steps': self.preprocessing_steps,
|
| 811 |
+
}
|
| 812 |
+
else:
|
| 813 |
+
mse = mean_squared_error(y_test, y_pred)
|
| 814 |
+
self.results = {
|
| 815 |
+
'model_name': best_name,
|
| 816 |
+
'problem_type': problem_type,
|
| 817 |
+
'mse': mse,
|
| 818 |
+
'rmse': np.sqrt(mse),
|
| 819 |
+
'mae': mean_absolute_error(y_test, y_pred),
|
| 820 |
+
'r2_score': r2_score(y_test, y_pred),
|
| 821 |
+
'preprocessing_steps': self.preprocessing_steps,
|
| 822 |
+
}
|
| 823 |
+
|
| 824 |
+
def train_unsupervised(self, X, problem_type='clustering'):
|
| 825 |
+
"""Train unsupervised model (no target needed)."""
|
| 826 |
+
print(f"\n{'='*55}")
|
| 827 |
+
print(f"π€ Training UNSUPERVISED model: {problem_type}")
|
| 828 |
+
print(f"{'='*55}\n")
|
| 829 |
+
|
| 830 |
+
self.problem_type = problem_type
|
| 831 |
+
|
| 832 |
+
if problem_type == 'clustering':
|
| 833 |
+
model = KMeans(n_clusters=3, random_state=42)
|
| 834 |
+
model.fit(X)
|
| 835 |
+
labels = model.labels_
|
| 836 |
+
self.model = model
|
| 837 |
+
self.model_name = 'K-Means (k=3)'
|
| 838 |
+
self.results = {
|
| 839 |
+
'model_name': 'K-Means (k=3)',
|
| 840 |
+
'problem_type': 'clustering',
|
| 841 |
+
'inertia': float(model.inertia_),
|
| 842 |
+
'n_clusters': 3,
|
| 843 |
+
'preprocessing_steps': self.preprocessing_steps,
|
| 844 |
+
}
|
| 845 |
+
print(f"β KMeans trained. Inertia: {model.inertia_:.2f}")
|
| 846 |
+
|
| 847 |
+
elif problem_type == 'dimensionality_reduction':
|
| 848 |
+
model = PCA(n_components=2)
|
| 849 |
+
model.fit(X)
|
| 850 |
+
self.model = model
|
| 851 |
+
self.model_name = 'PCA (2 components)'
|
| 852 |
+
self.results = {
|
| 853 |
+
'model_name': 'PCA (2 components)',
|
| 854 |
+
'problem_type': 'dimensionality_reduction',
|
| 855 |
+
'explained_variance': float(model.explained_variance_ratio_.sum()),
|
| 856 |
+
'preprocessing_steps': self.preprocessing_steps,
|
| 857 |
+
}
|
| 858 |
+
print(f"β PCA trained. Explained variance: {model.explained_variance_ratio_.sum():.2%}")
|
| 859 |
+
|
| 860 |
+
else:
|
| 861 |
+
print(f"βΉ Association rule learning β pass through")
|
| 862 |
+
self.model = None
|
| 863 |
+
self.model_name = 'Association Analysis'
|
| 864 |
+
self.results = {
|
| 865 |
+
'model_name': 'Association Analysis',
|
| 866 |
+
'problem_type': 'association',
|
| 867 |
+
'preprocessing_steps': self.preprocessing_steps,
|
| 868 |
+
}
|
| 869 |
+
|
| 870 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 871 |
+
# Save / Load
|
| 872 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 873 |
+
def save_model(self, save_dir='saved_models', filename=None):
|
| 874 |
+
os.makedirs(save_dir, exist_ok=True)
|
| 875 |
+
if filename is None:
|
| 876 |
+
ts = datetime.now().strftime('%Y%m%d_%H%M%S')
|
| 877 |
+
filename = f"model_{self.problem_type}_{ts}.pkl"
|
| 878 |
+
|
| 879 |
+
path = os.path.join(save_dir, filename)
|
| 880 |
+
payload = {
|
| 881 |
+
'model': self.model,
|
| 882 |
+
'scalers': self.scalers,
|
| 883 |
+
'encoders': self.encoders,
|
| 884 |
+
'imputers': self.imputers,
|
| 885 |
+
'feature_names': self.feature_names,
|
| 886 |
+
'trained_features': getattr(self, 'trained_features', None),
|
| 887 |
+
'onehot_cols': getattr(self, 'onehot_cols', None),
|
| 888 |
+
'custom_impute_values': getattr(self, 'custom_impute_values', {}),
|
| 889 |
+
'drop_columns': getattr(self, 'drop_columns', []),
|
| 890 |
+
'model_name': self.model_name,
|
| 891 |
+
'problem_type': self.problem_type,
|
| 892 |
+
'preprocessing_steps': self.preprocessing_steps,
|
| 893 |
+
'results': self.results,
|
| 894 |
+
}
|
| 895 |
+
with open(path, 'wb') as f:
|
| 896 |
+
pickle.dump(payload, f)
|
| 897 |
+
print(f"β Model saved: {path}")
|
| 898 |
+
return path
|
| 899 |
+
|
| 900 |
+
def load_model(self, path):
|
| 901 |
+
with open(path, 'rb') as f:
|
| 902 |
+
d = pickle.load(f)
|
| 903 |
+
self.model = d['model']
|
| 904 |
+
self.scalers = d.get('scalers', {})
|
| 905 |
+
self.encoders = d.get('encoders', {})
|
| 906 |
+
self.imputers = d.get('imputers', {})
|
| 907 |
+
self.feature_names = d.get('feature_names')
|
| 908 |
+
self.trained_features = d.get('trained_features', None)
|
| 909 |
+
self.onehot_cols = d.get('onehot_cols', None)
|
| 910 |
+
self.custom_impute_values = d.get('custom_impute_values', {})
|
| 911 |
+
self.drop_columns = d.get('drop_columns', [])
|
| 912 |
+
self.model_name = d.get('model_name')
|
| 913 |
+
self.problem_type = d.get('problem_type')
|
| 914 |
+
self.preprocessing_steps = d.get('preprocessing_steps', [])
|
| 915 |
+
self.results = d.get('results', {})
|
| 916 |
+
return self
|
| 917 |
+
|
| 918 |
+
def predict(self, X):
|
| 919 |
+
if self.model is None:
|
| 920 |
+
raise Exception("No model trained yet.")
|
| 921 |
+
|
| 922 |
+
# Copy to avoid side effects
|
| 923 |
+
X = X.copy()
|
| 924 |
+
|
| 925 |
+
# Strip whitespaces from string columns
|
| 926 |
+
for col in X.columns:
|
| 927 |
+
if str(X[col].dtype) in ('object', 'string'):
|
| 928 |
+
X[col] = X[col].apply(lambda x: str(x).strip() if pd.notnull(x) else x)
|
| 929 |
+
|
| 930 |
+
# Standardize and replace common string null placeholders with actual np.nan
|
| 931 |
+
placeholders = ['null', 'NULL', 'Null', 'n/a', 'N/A', 'na', 'NA', 'nan', 'NaN', 'NAN', '-', '?', '']
|
| 932 |
+
X = X.replace(placeholders, np.nan)
|
| 933 |
+
|
| 934 |
+
# Drop columns that were excluded during training
|
| 935 |
+
if hasattr(self, 'drop_columns') and self.drop_columns:
|
| 936 |
+
cols_to_drop = [c for c in self.drop_columns if c in X.columns]
|
| 937 |
+
if cols_to_drop:
|
| 938 |
+
X = X.drop(columns=cols_to_drop)
|
| 939 |
+
|
| 940 |
+
# Safely convert numeric-looking columns read as strings
|
| 941 |
+
for col in X.columns:
|
| 942 |
+
if str(X[col].dtype) in ('object', 'string'):
|
| 943 |
+
converted = pd.to_numeric(X[col], errors='coerce')
|
| 944 |
+
non_null_original = X[col].dropna().shape[0]
|
| 945 |
+
non_null_converted = converted.dropna().shape[0]
|
| 946 |
+
if non_null_original > 0 and non_null_converted >= 0.9 * non_null_original:
|
| 947 |
+
X[col] = converted
|
| 948 |
+
|
| 949 |
+
# 1. Apply Imputers / Null strategies
|
| 950 |
+
for col in X.columns:
|
| 951 |
+
# Handle drop strategy in predict (dropping rows with missing values for that col)
|
| 952 |
+
if col in self.imputers:
|
| 953 |
+
imputer = self.imputers[col]
|
| 954 |
+
if imputer == 'drop':
|
| 955 |
+
X = X.dropna(subset=[col])
|
| 956 |
+
elif hasattr(imputer, 'transform'):
|
| 957 |
+
try:
|
| 958 |
+
X[[col]] = imputer.transform(X[[col]])
|
| 959 |
+
except Exception as e:
|
| 960 |
+
print(f" Warning: Imputer transform failed for '{col}': {e}")
|
| 961 |
+
|
| 962 |
+
# Fallback custom imputations registered
|
| 963 |
+
if hasattr(self, 'custom_impute_values') and self.custom_impute_values and col in self.custom_impute_values:
|
| 964 |
+
val = self.custom_impute_values[col]
|
| 965 |
+
X[col] = X[col].fillna(val)
|
| 966 |
+
|
| 967 |
+
# 2. Apply Encoders
|
| 968 |
+
for col, encoder in self.encoders.items():
|
| 969 |
+
if col in X.columns:
|
| 970 |
+
try:
|
| 971 |
+
if isinstance(encoder, LabelEncoder):
|
| 972 |
+
# Handle unseen categories gracefully
|
| 973 |
+
classes = set(encoder.classes_)
|
| 974 |
+
X[col] = X[col].astype(str).map(lambda s: s if s in classes else encoder.classes_[0])
|
| 975 |
+
X[col] = encoder.transform(X[col])
|
| 976 |
+
elif isinstance(encoder, OrdinalEncoder):
|
| 977 |
+
X[[col]] = encoder.transform(X[[col]])
|
| 978 |
+
elif isinstance(encoder, LabelBinarizer):
|
| 979 |
+
encoded = encoder.transform(X[col].astype(str))
|
| 980 |
+
if encoded.shape[1] == 1:
|
| 981 |
+
X[col] = encoded.ravel()
|
| 982 |
+
else:
|
| 983 |
+
new_cols = [f"{col}_{c}" for c in encoder.classes_]
|
| 984 |
+
X[new_cols] = encoded
|
| 985 |
+
X.drop(columns=[col], inplace=True)
|
| 986 |
+
except Exception as e:
|
| 987 |
+
print(f" Warning: Encoding failed for '{col}': {e}")
|
| 988 |
+
|
| 989 |
+
# 3. Apply One-Hot dummy encoding
|
| 990 |
+
if hasattr(self, 'onehot_cols') and self.onehot_cols:
|
| 991 |
+
existing_onehot_cols = [col for col in self.onehot_cols if col in X.columns]
|
| 992 |
+
if existing_onehot_cols:
|
| 993 |
+
X = pd.get_dummies(X, columns=existing_onehot_cols, drop_first=True)
|
| 994 |
+
|
| 995 |
+
# 4. Apply Scalers
|
| 996 |
+
for col, scaler in self.scalers.items():
|
| 997 |
+
if col in X.columns:
|
| 998 |
+
try:
|
| 999 |
+
X[[col]] = scaler.transform(X[[col]])
|
| 1000 |
+
except Exception as e:
|
| 1001 |
+
print(f" Warning: Scaler transform failed for '{col}': {e}")
|
| 1002 |
+
|
| 1003 |
+
# 5. Column Alignment with Model Structure
|
| 1004 |
+
if hasattr(self, 'trained_features') and self.trained_features:
|
| 1005 |
+
# Reindex to match trained features exactly (fills missing dummy columns with 0, discards extra ones)
|
| 1006 |
+
X = X.reindex(columns=self.trained_features, fill_value=0)
|
| 1007 |
+
|
| 1008 |
+
return self.model.predict(X)
|
| 1009 |
+
|
| 1010 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1011 |
+
# ENHANCEMENT 3: Save Preprocessing Components Separately
|
| 1012 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1013 |
+
def save_encoders(self, save_dir='saved_models', filename=None):
|
| 1014 |
+
"""Save encoders as a separate file."""
|
| 1015 |
+
os.makedirs(save_dir, exist_ok=True)
|
| 1016 |
+
if filename is None:
|
| 1017 |
+
ts = datetime.now().strftime('%Y%m%d_%H%M%S')
|
| 1018 |
+
filename = f"encoders_{self.problem_type}_{ts}.pkl"
|
| 1019 |
+
|
| 1020 |
+
path = os.path.join(save_dir, filename)
|
| 1021 |
+
payload = {
|
| 1022 |
+
'encoders': self.encoders,
|
| 1023 |
+
'categorical_columns': [col for col in self.feature_names if col in self.encoders] if self.feature_names else [],
|
| 1024 |
+
'timestamp': datetime.now().isoformat(),
|
| 1025 |
+
'problem_type': self.problem_type,
|
| 1026 |
+
}
|
| 1027 |
+
with open(path, 'wb') as f:
|
| 1028 |
+
pickle.dump(payload, f)
|
| 1029 |
+
print(f"β Encoders saved: {path}")
|
| 1030 |
+
return path
|
| 1031 |
+
|
| 1032 |
+
def save_scalers(self, save_dir='saved_models', filename=None):
|
| 1033 |
+
"""Save scalers as a separate file."""
|
| 1034 |
+
os.makedirs(save_dir, exist_ok=True)
|
| 1035 |
+
if filename is None:
|
| 1036 |
+
ts = datetime.now().strftime('%Y%m%d_%H%M%S')
|
| 1037 |
+
filename = f"scalers_{self.problem_type}_{ts}.pkl"
|
| 1038 |
+
|
| 1039 |
+
path = os.path.join(save_dir, filename)
|
| 1040 |
+
payload = {
|
| 1041 |
+
'scalers': self.scalers,
|
| 1042 |
+
'numeric_columns': [col for col in self.feature_names if col in self.scalers] if self.feature_names else [],
|
| 1043 |
+
'timestamp': datetime.now().isoformat(),
|
| 1044 |
+
'problem_type': self.problem_type,
|
| 1045 |
+
}
|
| 1046 |
+
with open(path, 'wb') as f:
|
| 1047 |
+
pickle.dump(payload, f)
|
| 1048 |
+
print(f"β Scalers saved: {path}")
|
| 1049 |
+
return path
|
| 1050 |
+
|
| 1051 |
+
def save_preprocessing_bundle(self, save_dir='saved_models', filename=None):
|
| 1052 |
+
"""Save all preprocessing components as a bundle with metadata."""
|
| 1053 |
+
os.makedirs(save_dir, exist_ok=True)
|
| 1054 |
+
if filename is None:
|
| 1055 |
+
ts = datetime.now().strftime('%Y%m%d_%H%M%S')
|
| 1056 |
+
filename = f"preprocessing_bundle_{self.problem_type}_{ts}.pkl"
|
| 1057 |
+
|
| 1058 |
+
path = os.path.join(save_dir, filename)
|
| 1059 |
+
payload = {
|
| 1060 |
+
'scalers': self.scalers,
|
| 1061 |
+
'encoders': self.encoders,
|
| 1062 |
+
'imputers': self.imputers,
|
| 1063 |
+
'metadata': {
|
| 1064 |
+
'feature_names': self.feature_names,
|
| 1065 |
+
'trained_features': getattr(self, 'trained_features', None),
|
| 1066 |
+
'onehot_cols': getattr(self, 'onehot_cols', None),
|
| 1067 |
+
'custom_impute_values': getattr(self, 'custom_impute_values', {}),
|
| 1068 |
+
'drop_columns': getattr(self, 'drop_columns', []),
|
| 1069 |
+
'numeric_columns': [col for col in self.feature_names if col in self.scalers] if self.feature_names else [],
|
| 1070 |
+
'categorical_columns': [col for col in self.feature_names if col in self.encoders] if self.feature_names else [],
|
| 1071 |
+
'preprocessing_steps': self.preprocessing_steps,
|
| 1072 |
+
'problem_type': self.problem_type,
|
| 1073 |
+
'model_name': self.model_name,
|
| 1074 |
+
'timestamp': datetime.now().isoformat(),
|
| 1075 |
+
}
|
| 1076 |
+
}
|
| 1077 |
+
with open(path, 'wb') as f:
|
| 1078 |
+
pickle.dump(payload, f)
|
| 1079 |
+
print(f"β Preprocessing bundle saved: {path}")
|
| 1080 |
+
return path
|
| 1081 |
+
|
| 1082 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1083 |
+
# ENHANCEMENT: Generate Deployable Web Application
|
| 1084 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1085 |
+
def generate_deployable_app(self, model_path, scaler_path=None, encoder_path=None, save_dir='saved_models'):
|
| 1086 |
+
"""
|
| 1087 |
+
Generate a complete, self-contained Flask web application as a ZIP file.
|
| 1088 |
+
The ZIP contains app.py, templates/index.html, model artifacts, requirements.txt, and README.md.
|
| 1089 |
+
"""
|
| 1090 |
+
import zipfile
|
| 1091 |
+
|
| 1092 |
+
os.makedirs(save_dir, exist_ok=True)
|
| 1093 |
+
ts = datetime.now().strftime('%Y%m%d_%H%M%S')
|
| 1094 |
+
zip_filename = f"deployable_app_{ts}.zip"
|
| 1095 |
+
zip_path = os.path.join(save_dir, zip_filename)
|
| 1096 |
+
|
| 1097 |
+
feature_names = self.feature_names or []
|
| 1098 |
+
numeric_cols = self.numeric_cols or []
|
| 1099 |
+
categorical_cols = self.categorical_cols or []
|
| 1100 |
+
categorical_values = getattr(self, 'categorical_values', {})
|
| 1101 |
+
target_name = self.target_name or 'target'
|
| 1102 |
+
model_name = self.model_name or 'Unknown'
|
| 1103 |
+
problem_type = self.problem_type or 'Unknown'
|
| 1104 |
+
|
| 1105 |
+
# ββ Generate app.py ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1106 |
+
app_py = self._gen_app_py(feature_names, numeric_cols, categorical_cols, target_name, model_name, problem_type)
|
| 1107 |
+
|
| 1108 |
+
# ββ Generate index.html ββββββββββββββββββββββββββββββββββββββββββ
|
| 1109 |
+
index_html = self._gen_index_html(feature_names, numeric_cols, categorical_cols, categorical_values, target_name, model_name, problem_type)
|
| 1110 |
+
|
| 1111 |
+
# ββ Generate requirements.txt ββββββββββββββββββββββββββββββββββββ
|
| 1112 |
+
requirements_txt = "flask>=2.3.0\npandas>=1.5.0\nnumpy>=1.23.0\nscikit-learn>=1.2.0\n"
|
| 1113 |
+
|
| 1114 |
+
# ββ Generate README.md βββββββββββββββββββββββββββββββββββββββββββ
|
| 1115 |
+
readme_md = f"""# {model_name} β Prediction Web App
|
| 1116 |
+
|
| 1117 |
+
This is an auto-generated, self-contained Flask web application for making predictions
|
| 1118 |
+
using the **{model_name}** model trained by Data2Model.
|
| 1119 |
+
|
| 1120 |
+
## Quick Start
|
| 1121 |
+
|
| 1122 |
+
```bash
|
| 1123 |
+
pip install -r requirements.txt
|
| 1124 |
+
python app.py
|
| 1125 |
+
```
|
| 1126 |
+
|
| 1127 |
+
Then open **http://localhost:5000** in your browser.
|
| 1128 |
+
|
| 1129 |
+
## Model Details
|
| 1130 |
+
|
| 1131 |
+
| Property | Value |
|
| 1132 |
+
|----------------|----------------------|
|
| 1133 |
+
| Algorithm | {model_name} |
|
| 1134 |
+
| Problem Type | {problem_type.title()} |
|
| 1135 |
+
| Target Column | {target_name} |
|
| 1136 |
+
| Features Used | {len(feature_names)} |
|
| 1137 |
+
|
| 1138 |
+
## Project Structure
|
| 1139 |
+
|
| 1140 |
+
```
|
| 1141 |
+
βββ app.py # Flask application
|
| 1142 |
+
βββ templates/
|
| 1143 |
+
β βββ index.html # Web interface
|
| 1144 |
+
βββ model/
|
| 1145 |
+
β βββ model.pkl # Trained model
|
| 1146 |
+
β βββ scaler.pkl # Fitted scaler (if applicable)
|
| 1147 |
+
β βββ encoder.pkl # Fitted encoder (if applicable)
|
| 1148 |
+
βββ requirements.txt # Python dependencies
|
| 1149 |
+
βββ README.md # This file
|
| 1150 |
+
```
|
| 1151 |
+
|
| 1152 |
+
---
|
| 1153 |
+
*Generated by Data2Model β Automated Machine Learning Platform*
|
| 1154 |
+
"""
|
| 1155 |
+
|
| 1156 |
+
# ββ Bundle into ZIP ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1157 |
+
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zf:
|
| 1158 |
+
zf.writestr('app.py', app_py)
|
| 1159 |
+
zf.writestr('templates/index.html', index_html)
|
| 1160 |
+
zf.writestr('requirements.txt', requirements_txt)
|
| 1161 |
+
zf.writestr('README.md', readme_md)
|
| 1162 |
+
|
| 1163 |
+
# Add model pickle
|
| 1164 |
+
if model_path and os.path.exists(model_path):
|
| 1165 |
+
zf.write(model_path, 'model/model.pkl')
|
| 1166 |
+
# Add scaler pickle
|
| 1167 |
+
if scaler_path and os.path.exists(scaler_path):
|
| 1168 |
+
zf.write(scaler_path, 'model/scaler.pkl')
|
| 1169 |
+
# Add encoder pickle
|
| 1170 |
+
if encoder_path and os.path.exists(encoder_path):
|
| 1171 |
+
zf.write(encoder_path, 'model/encoder.pkl')
|
| 1172 |
+
|
| 1173 |
+
print(f"β Deployable app saved: {zip_path}")
|
| 1174 |
+
return zip_path
|
| 1175 |
+
|
| 1176 |
+
def _gen_app_py(self, feature_names, numeric_cols, categorical_cols, target_name, model_name, problem_type):
|
| 1177 |
+
"""Generate the app.py source code string."""
|
| 1178 |
+
return '''"""
|
| 1179 |
+
Auto-generated Prediction Web App β ''' + model_name + '''
|
| 1180 |
+
Generated by Data2Model
|
| 1181 |
+
"""
|
| 1182 |
+
from flask import Flask, render_template, request, jsonify
|
| 1183 |
+
import pandas as pd
|
| 1184 |
+
import numpy as np
|
| 1185 |
+
import pickle
|
| 1186 |
+
import os
|
| 1187 |
+
|
| 1188 |
+
app = Flask(__name__)
|
| 1189 |
+
|
| 1190 |
+
# ββ Load model & artifacts βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1191 |
+
MODEL_DIR = os.path.join(os.path.dirname(__file__), 'model')
|
| 1192 |
+
MODEL_PATH = os.path.join(MODEL_DIR, 'model.pkl')
|
| 1193 |
+
SCALER_PATH = os.path.join(MODEL_DIR, 'scaler.pkl')
|
| 1194 |
+
ENCODER_PATH = os.path.join(MODEL_DIR, 'encoder.pkl')
|
| 1195 |
+
|
| 1196 |
+
with open(MODEL_PATH, 'rb') as f:
|
| 1197 |
+
bundle = pickle.load(f)
|
| 1198 |
+
|
| 1199 |
+
model = bundle['model']
|
| 1200 |
+
imputers = bundle.get('imputers', {})
|
| 1201 |
+
feature_names = bundle.get('feature_names', [])
|
| 1202 |
+
trained_features = bundle.get('trained_features', [])
|
| 1203 |
+
onehot_cols = bundle.get('onehot_cols', [])
|
| 1204 |
+
custom_impute = bundle.get('custom_impute_values', {})
|
| 1205 |
+
drop_columns = bundle.get('drop_columns', [])
|
| 1206 |
+
model_name = bundle.get('model_name', 'Unknown')
|
| 1207 |
+
problem_type = bundle.get('problem_type', 'Unknown')
|
| 1208 |
+
|
| 1209 |
+
# Explicitly load separate scaler and encoder files if they exist
|
| 1210 |
+
scalers = {}
|
| 1211 |
+
if os.path.exists(SCALER_PATH):
|
| 1212 |
+
with open(SCALER_PATH, 'rb') as f:
|
| 1213 |
+
scaler_payload = pickle.load(f)
|
| 1214 |
+
scalers = scaler_payload.get('scalers', {})
|
| 1215 |
+
|
| 1216 |
+
encoders = {}
|
| 1217 |
+
if os.path.exists(ENCODER_PATH):
|
| 1218 |
+
with open(ENCODER_PATH, 'rb') as f:
|
| 1219 |
+
encoder_payload = pickle.load(f)
|
| 1220 |
+
encoders = encoder_payload.get('encoders', {})
|
| 1221 |
+
|
| 1222 |
+
from sklearn.preprocessing import LabelEncoder, OrdinalEncoder, LabelBinarizer
|
| 1223 |
+
|
| 1224 |
+
|
| 1225 |
+
@app.route('/')
|
| 1226 |
+
def index():
|
| 1227 |
+
return render_template('index.html')
|
| 1228 |
+
|
| 1229 |
+
|
| 1230 |
+
@app.route('/predict', methods=['POST'])
|
| 1231 |
+
def predict():
|
| 1232 |
+
try:
|
| 1233 |
+
data = {}
|
| 1234 |
+
for feat in feature_names:
|
| 1235 |
+
val = request.form.get(feat, '')
|
| 1236 |
+
if val.strip() == '':
|
| 1237 |
+
data[feat] = np.nan
|
| 1238 |
+
else:
|
| 1239 |
+
try:
|
| 1240 |
+
data[feat] = float(val)
|
| 1241 |
+
except ValueError:
|
| 1242 |
+
data[feat] = val
|
| 1243 |
+
|
| 1244 |
+
df = pd.DataFrame([data])
|
| 1245 |
+
|
| 1246 |
+
# Drop excluded columns
|
| 1247 |
+
if drop_columns:
|
| 1248 |
+
cols_to_drop = [c for c in drop_columns if c in df.columns]
|
| 1249 |
+
if cols_to_drop:
|
| 1250 |
+
df = df.drop(columns=cols_to_drop)
|
| 1251 |
+
|
| 1252 |
+
# 1. Imputation
|
| 1253 |
+
for col in df.columns:
|
| 1254 |
+
if col in imputers:
|
| 1255 |
+
imp = imputers[col]
|
| 1256 |
+
if imp == 'drop':
|
| 1257 |
+
pass
|
| 1258 |
+
elif hasattr(imp, 'transform'):
|
| 1259 |
+
try:
|
| 1260 |
+
df[[col]] = imp.transform(df[[col]])
|
| 1261 |
+
except:
|
| 1262 |
+
pass
|
| 1263 |
+
if col in custom_impute:
|
| 1264 |
+
df[col] = df[col].fillna(custom_impute[col])
|
| 1265 |
+
|
| 1266 |
+
# 2. Encoding
|
| 1267 |
+
for col, encoder in encoders.items():
|
| 1268 |
+
if col in df.columns:
|
| 1269 |
+
try:
|
| 1270 |
+
if isinstance(encoder, LabelEncoder):
|
| 1271 |
+
classes = set(encoder.classes_)
|
| 1272 |
+
df[col] = df[col].astype(str).map(lambda s: s if s in classes else encoder.classes_[0])
|
| 1273 |
+
df[col] = encoder.transform(df[col])
|
| 1274 |
+
elif isinstance(encoder, OrdinalEncoder):
|
| 1275 |
+
df[[col]] = encoder.transform(df[[col]])
|
| 1276 |
+
elif isinstance(encoder, LabelBinarizer):
|
| 1277 |
+
encoded = encoder.transform(df[col].astype(str))
|
| 1278 |
+
if encoded.shape[1] == 1:
|
| 1279 |
+
df[col] = encoded.ravel()
|
| 1280 |
+
else:
|
| 1281 |
+
new_cols = [f"{col}_{c}" for c in encoder.classes_]
|
| 1282 |
+
df[new_cols] = encoded
|
| 1283 |
+
df.drop(columns=[col], inplace=True)
|
| 1284 |
+
except:
|
| 1285 |
+
pass
|
| 1286 |
+
|
| 1287 |
+
# 3. One-hot
|
| 1288 |
+
if onehot_cols:
|
| 1289 |
+
existing = [c for c in onehot_cols if c in df.columns]
|
| 1290 |
+
if existing:
|
| 1291 |
+
df = pd.get_dummies(df, columns=existing, drop_first=True)
|
| 1292 |
+
|
| 1293 |
+
# 4. Scaling
|
| 1294 |
+
for col, scaler in scalers.items():
|
| 1295 |
+
if col in df.columns:
|
| 1296 |
+
try:
|
| 1297 |
+
df[[col]] = scaler.transform(df[[col]])
|
| 1298 |
+
except:
|
| 1299 |
+
pass
|
| 1300 |
+
|
| 1301 |
+
# 5. Align columns
|
| 1302 |
+
if trained_features:
|
| 1303 |
+
df = df.reindex(columns=trained_features, fill_value=0)
|
| 1304 |
+
|
| 1305 |
+
prediction = model.predict(df)
|
| 1306 |
+
result = str(prediction[0])
|
| 1307 |
+
|
| 1308 |
+
return jsonify({'prediction': result, 'success': True})
|
| 1309 |
+
|
| 1310 |
+
except Exception as e:
|
| 1311 |
+
return jsonify({'error': str(e), 'success': False})
|
| 1312 |
+
|
| 1313 |
+
|
| 1314 |
+
if __name__ == '__main__':
|
| 1315 |
+
print(f"\\n Model: {model_name}")
|
| 1316 |
+
print(f" Type: {problem_type}")
|
| 1317 |
+
print(f" Open http://localhost:5000 in your browser\\n")
|
| 1318 |
+
app.run(debug=True, host='0.0.0.0', port=5000)
|
| 1319 |
+
'''
|
| 1320 |
+
|
| 1321 |
+
def _gen_index_html(self, feature_names, numeric_cols, categorical_cols, categorical_values, target_name, model_name, problem_type):
|
| 1322 |
+
"""Generate a beautiful, self-contained index.html."""
|
| 1323 |
+
|
| 1324 |
+
# Build form fields HTML
|
| 1325 |
+
form_fields = ''
|
| 1326 |
+
for feat in feature_names:
|
| 1327 |
+
if feat in categorical_cols and feat in categorical_values:
|
| 1328 |
+
options = categorical_values[feat]
|
| 1329 |
+
opts_html = ''.join([f'<option value="{v}">{v}</option>' for v in sorted(str(o) for o in options)])
|
| 1330 |
+
form_fields += f'''
|
| 1331 |
+
<div class="col-md-6 mb-4">
|
| 1332 |
+
<label class="form-label" for="field_{feat}">{feat}</label>
|
| 1333 |
+
<select class="form-select" id="field_{feat}" name="{feat}">
|
| 1334 |
+
<option value="" selected>Select {feat}...</option>
|
| 1335 |
+
{opts_html}
|
| 1336 |
+
</select>
|
| 1337 |
+
<div class="form-text">Categorical</div>
|
| 1338 |
+
</div>'''
|
| 1339 |
+
else:
|
| 1340 |
+
form_fields += f'''
|
| 1341 |
+
<div class="col-md-6 mb-4">
|
| 1342 |
+
<label class="form-label" for="field_{feat}">{feat}</label>
|
| 1343 |
+
<input type="number" step="any" class="form-control" id="field_{feat}" name="{feat}" placeholder="Enter {feat}">
|
| 1344 |
+
<div class="form-text">Numeric</div>
|
| 1345 |
+
</div>'''
|
| 1346 |
+
|
| 1347 |
+
return '''<!DOCTYPE html>
|
| 1348 |
+
<html lang="en">
|
| 1349 |
+
<head>
|
| 1350 |
+
<meta charset="UTF-8">
|
| 1351 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 1352 |
+
<title>''' + model_name + ''' β Prediction App</title>
|
| 1353 |
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
| 1354 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 1355 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
|
| 1356 |
+
<style>
|
| 1357 |
+
:root {
|
| 1358 |
+
--primary: #6366f1;
|
| 1359 |
+
--primary-dark: #4f46e5;
|
| 1360 |
+
--accent: #06b6d4;
|
| 1361 |
+
--bg-dark: #0f172a;
|
| 1362 |
+
--bg-card: #1e293b;
|
| 1363 |
+
--bg-input: #334155;
|
| 1364 |
+
--text-primary: #f1f5f9;
|
| 1365 |
+
--text-muted: #94a3b8;
|
| 1366 |
+
--border: #475569;
|
| 1367 |
+
--success: #22c55e;
|
| 1368 |
+
--danger: #ef4444;
|
| 1369 |
+
}
|
| 1370 |
+
|
| 1371 |
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
| 1372 |
+
body {
|
| 1373 |
+
font-family: 'Inter', sans-serif;
|
| 1374 |
+
background: var(--bg-dark);
|
| 1375 |
+
color: var(--text-primary);
|
| 1376 |
+
min-height: 100vh;
|
| 1377 |
+
}
|
| 1378 |
+
|
| 1379 |
+
/* ββ Background animation βββββββββββββββββββββββββββ */
|
| 1380 |
+
body::before {
|
| 1381 |
+
content: '';
|
| 1382 |
+
position: fixed;
|
| 1383 |
+
top: 0; left: 0; right: 0; bottom: 0;
|
| 1384 |
+
background:
|
| 1385 |
+
radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.12) 0%, transparent 50%),
|
| 1386 |
+
radial-gradient(ellipse at 80% 20%, rgba(6, 182, 212, 0.1) 0%, transparent 50%),
|
| 1387 |
+
radial-gradient(ellipse at 50% 80%, rgba(168, 85, 247, 0.08) 0%, transparent 50%);
|
| 1388 |
+
z-index: -1;
|
| 1389 |
+
animation: bgPulse 8s ease-in-out infinite alternate;
|
| 1390 |
+
}
|
| 1391 |
+
@keyframes bgPulse {
|
| 1392 |
+
0% { opacity: 0.7; }
|
| 1393 |
+
100% { opacity: 1; }
|
| 1394 |
+
}
|
| 1395 |
+
|
| 1396 |
+
/* ββ Navbar βββββββββββββββββββββββββββββββββββββββββ */
|
| 1397 |
+
.navbar-custom {
|
| 1398 |
+
background: rgba(15, 23, 42, 0.85);
|
| 1399 |
+
backdrop-filter: blur(20px);
|
| 1400 |
+
border-bottom: 1px solid rgba(99, 102, 241, 0.2);
|
| 1401 |
+
padding: 1rem 0;
|
| 1402 |
+
}
|
| 1403 |
+
.navbar-custom .brand {
|
| 1404 |
+
font-weight: 800;
|
| 1405 |
+
font-size: 1.4rem;
|
| 1406 |
+
color: var(--text-primary);
|
| 1407 |
+
text-decoration: none;
|
| 1408 |
+
display: flex;
|
| 1409 |
+
align-items: center;
|
| 1410 |
+
gap: 0.6rem;
|
| 1411 |
+
}
|
| 1412 |
+
.navbar-custom .brand i {
|
| 1413 |
+
background: linear-gradient(135deg, var(--primary), var(--accent));
|
| 1414 |
+
-webkit-background-clip: text;
|
| 1415 |
+
-webkit-text-fill-color: transparent;
|
| 1416 |
+
font-size: 1.6rem;
|
| 1417 |
+
}
|
| 1418 |
+
.badge-model {
|
| 1419 |
+
background: linear-gradient(135deg, var(--primary), var(--accent));
|
| 1420 |
+
color: white;
|
| 1421 |
+
padding: 6px 14px;
|
| 1422 |
+
border-radius: 20px;
|
| 1423 |
+
font-size: 0.75rem;
|
| 1424 |
+
font-weight: 600;
|
| 1425 |
+
letter-spacing: 0.5px;
|
| 1426 |
+
}
|
| 1427 |
+
|
| 1428 |
+
/* ββ Hero βββββββββββββββββββββββββββββββββββββββββββ */
|
| 1429 |
+
.hero {
|
| 1430 |
+
text-align: center;
|
| 1431 |
+
padding: 3rem 0 2rem;
|
| 1432 |
+
}
|
| 1433 |
+
.hero h1 {
|
| 1434 |
+
font-size: 2.6rem;
|
| 1435 |
+
font-weight: 800;
|
| 1436 |
+
margin-bottom: 0.6rem;
|
| 1437 |
+
background: linear-gradient(135deg, #f1f5f9, #cbd5e1);
|
| 1438 |
+
-webkit-background-clip: text;
|
| 1439 |
+
-webkit-text-fill-color: transparent;
|
| 1440 |
+
}
|
| 1441 |
+
.hero p {
|
| 1442 |
+
color: var(--text-muted);
|
| 1443 |
+
font-size: 1.1rem;
|
| 1444 |
+
max-width: 520px;
|
| 1445 |
+
margin: 0 auto;
|
| 1446 |
+
}
|
| 1447 |
+
.hero-badge {
|
| 1448 |
+
display: inline-flex;
|
| 1449 |
+
align-items: center;
|
| 1450 |
+
gap: 0.5rem;
|
| 1451 |
+
background: rgba(99, 102, 241, 0.15);
|
| 1452 |
+
border: 1px solid rgba(99, 102, 241, 0.3);
|
| 1453 |
+
padding: 8px 18px;
|
| 1454 |
+
border-radius: 30px;
|
| 1455 |
+
font-size: 0.85rem;
|
| 1456 |
+
color: var(--accent);
|
| 1457 |
+
margin-top: 1rem;
|
| 1458 |
+
}
|
| 1459 |
+
|
| 1460 |
+
/* ββ Glass Card βββββββββββββββββββββββββββββββββββββ */
|
| 1461 |
+
.glass-card {
|
| 1462 |
+
background: rgba(30, 41, 59, 0.7);
|
| 1463 |
+
backdrop-filter: blur(16px);
|
| 1464 |
+
border: 1px solid rgba(71, 85, 105, 0.4);
|
| 1465 |
+
border-radius: 20px;
|
| 1466 |
+
padding: 2.5rem;
|
| 1467 |
+
margin-bottom: 2rem;
|
| 1468 |
+
box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
|
| 1469 |
+
transition: border-color 0.3s;
|
| 1470 |
+
}
|
| 1471 |
+
.glass-card:hover {
|
| 1472 |
+
border-color: rgba(99, 102, 241, 0.4);
|
| 1473 |
+
}
|
| 1474 |
+
|
| 1475 |
+
.card-title {
|
| 1476 |
+
font-weight: 700;
|
| 1477 |
+
font-size: 1.3rem;
|
| 1478 |
+
margin-bottom: 1.5rem;
|
| 1479 |
+
display: flex;
|
| 1480 |
+
align-items: center;
|
| 1481 |
+
gap: 0.6rem;
|
| 1482 |
+
}
|
| 1483 |
+
.card-title i {
|
| 1484 |
+
color: var(--accent);
|
| 1485 |
+
}
|
| 1486 |
+
|
| 1487 |
+
/* ββ Form βββββββββββββββββββββββββββββββββββββββββββ */
|
| 1488 |
+
.form-label {
|
| 1489 |
+
font-weight: 600;
|
| 1490 |
+
font-size: 0.85rem;
|
| 1491 |
+
color: var(--text-muted);
|
| 1492 |
+
text-transform: uppercase;
|
| 1493 |
+
letter-spacing: 0.7px;
|
| 1494 |
+
margin-bottom: 0.4rem;
|
| 1495 |
+
}
|
| 1496 |
+
.form-control, .form-select {
|
| 1497 |
+
background: var(--bg-input);
|
| 1498 |
+
border: 1px solid var(--border);
|
| 1499 |
+
color: var(--text-primary);
|
| 1500 |
+
border-radius: 12px;
|
| 1501 |
+
padding: 12px 16px;
|
| 1502 |
+
font-size: 0.95rem;
|
| 1503 |
+
transition: all 0.3s;
|
| 1504 |
+
}
|
| 1505 |
+
.form-control:focus, .form-select:focus {
|
| 1506 |
+
background: rgba(51, 65, 85, 0.9);
|
| 1507 |
+
border-color: var(--primary);
|
| 1508 |
+
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
|
| 1509 |
+
color: var(--text-primary);
|
| 1510 |
+
}
|
| 1511 |
+
.form-control::placeholder { color: var(--text-muted); opacity: 0.6; }
|
| 1512 |
+
.form-text { color: var(--text-muted); font-size: 0.75rem; margin-top: 4px; }
|
| 1513 |
+
.form-select option { background: var(--bg-card); color: var(--text-primary); }
|
| 1514 |
+
|
| 1515 |
+
/* ββ Buttons ββββββββββββββββββββββββββββββββββββββββ */
|
| 1516 |
+
.btn-predict {
|
| 1517 |
+
background: linear-gradient(135deg, var(--primary), var(--primary-dark));
|
| 1518 |
+
border: none;
|
| 1519 |
+
color: white;
|
| 1520 |
+
padding: 14px 40px;
|
| 1521 |
+
border-radius: 14px;
|
| 1522 |
+
font-weight: 700;
|
| 1523 |
+
font-size: 1.05rem;
|
| 1524 |
+
transition: all 0.3s;
|
| 1525 |
+
width: 100%;
|
| 1526 |
+
position: relative;
|
| 1527 |
+
overflow: hidden;
|
| 1528 |
+
}
|
| 1529 |
+
.btn-predict:hover {
|
| 1530 |
+
transform: translateY(-2px);
|
| 1531 |
+
box-shadow: 0 12px 30px rgba(99, 102, 241, 0.35);
|
| 1532 |
+
color: white;
|
| 1533 |
+
}
|
| 1534 |
+
.btn-predict:active { transform: translateY(0); }
|
| 1535 |
+
|
| 1536 |
+
.btn-reset {
|
| 1537 |
+
background: transparent;
|
| 1538 |
+
border: 1px solid var(--border);
|
| 1539 |
+
color: var(--text-muted);
|
| 1540 |
+
padding: 14px 40px;
|
| 1541 |
+
border-radius: 14px;
|
| 1542 |
+
font-weight: 600;
|
| 1543 |
+
font-size: 1rem;
|
| 1544 |
+
transition: all 0.3s;
|
| 1545 |
+
width: 100%;
|
| 1546 |
+
}
|
| 1547 |
+
.btn-reset:hover {
|
| 1548 |
+
border-color: var(--danger);
|
| 1549 |
+
color: var(--danger);
|
| 1550 |
+
}
|
| 1551 |
+
|
| 1552 |
+
/* ββ Result βββββββββββββββββββββββββββββββββββββββββ */
|
| 1553 |
+
#resultSection {
|
| 1554 |
+
display: none;
|
| 1555 |
+
animation: slideUp 0.5s ease;
|
| 1556 |
+
}
|
| 1557 |
+
@keyframes slideUp {
|
| 1558 |
+
from { opacity: 0; transform: translateY(20px); }
|
| 1559 |
+
to { opacity: 1; transform: translateY(0); }
|
| 1560 |
+
}
|
| 1561 |
+
.result-value {
|
| 1562 |
+
font-size: 3rem;
|
| 1563 |
+
font-weight: 800;
|
| 1564 |
+
background: linear-gradient(135deg, var(--success), var(--accent));
|
| 1565 |
+
-webkit-background-clip: text;
|
| 1566 |
+
-webkit-text-fill-color: transparent;
|
| 1567 |
+
word-break: break-all;
|
| 1568 |
+
}
|
| 1569 |
+
.result-label {
|
| 1570 |
+
color: var(--text-muted);
|
| 1571 |
+
font-size: 0.9rem;
|
| 1572 |
+
font-weight: 500;
|
| 1573 |
+
text-transform: uppercase;
|
| 1574 |
+
letter-spacing: 1px;
|
| 1575 |
+
}
|
| 1576 |
+
.error-value {
|
| 1577 |
+
background: linear-gradient(135deg, var(--danger), #f97316);
|
| 1578 |
+
-webkit-background-clip: text;
|
| 1579 |
+
-webkit-text-fill-color: transparent;
|
| 1580 |
+
}
|
| 1581 |
+
|
| 1582 |
+
/* ββ Loading Spinner ββββββββββββββββββββββββββββββββ */
|
| 1583 |
+
.spinner-overlay {
|
| 1584 |
+
display: none;
|
| 1585 |
+
position: fixed;
|
| 1586 |
+
top: 0; left: 0; right: 0; bottom: 0;
|
| 1587 |
+
background: rgba(15, 23, 42, 0.85);
|
| 1588 |
+
backdrop-filter: blur(8px);
|
| 1589 |
+
z-index: 9999;
|
| 1590 |
+
justify-content: center;
|
| 1591 |
+
align-items: center;
|
| 1592 |
+
flex-direction: column;
|
| 1593 |
+
gap: 1rem;
|
| 1594 |
+
}
|
| 1595 |
+
.spinner-ring {
|
| 1596 |
+
width: 50px; height: 50px;
|
| 1597 |
+
border: 4px solid rgba(99, 102, 241, 0.2);
|
| 1598 |
+
border-top-color: var(--primary);
|
| 1599 |
+
border-radius: 50%;
|
| 1600 |
+
animation: spin 0.8s linear infinite;
|
| 1601 |
+
}
|
| 1602 |
+
@keyframes spin { to { transform: rotate(360deg); } }
|
| 1603 |
+
|
| 1604 |
+
/* ββ Footer βββββββββββββββββββββββββββββββββββββββββ */
|
| 1605 |
+
.footer {
|
| 1606 |
+
text-align: center;
|
| 1607 |
+
padding: 2rem 0;
|
| 1608 |
+
color: var(--text-muted);
|
| 1609 |
+
font-size: 0.8rem;
|
| 1610 |
+
border-top: 1px solid rgba(71, 85, 105, 0.3);
|
| 1611 |
+
margin-top: 3rem;
|
| 1612 |
+
}
|
| 1613 |
+
|
| 1614 |
+
/* ββ Stats Bar ββββββββββββββββββββββββββββββββββββββ */
|
| 1615 |
+
.stats-bar {
|
| 1616 |
+
display: flex;
|
| 1617 |
+
gap: 2rem;
|
| 1618 |
+
justify-content: center;
|
| 1619 |
+
flex-wrap: wrap;
|
| 1620 |
+
margin: 1.5rem 0;
|
| 1621 |
+
}
|
| 1622 |
+
.stat-item {
|
| 1623 |
+
text-align: center;
|
| 1624 |
+
}
|
| 1625 |
+
.stat-item .stat-val {
|
| 1626 |
+
font-size: 1.6rem;
|
| 1627 |
+
font-weight: 700;
|
| 1628 |
+
color: var(--accent);
|
| 1629 |
+
}
|
| 1630 |
+
.stat-item .stat-lbl {
|
| 1631 |
+
font-size: 0.75rem;
|
| 1632 |
+
color: var(--text-muted);
|
| 1633 |
+
text-transform: uppercase;
|
| 1634 |
+
letter-spacing: 0.5px;
|
| 1635 |
+
}
|
| 1636 |
+
</style>
|
| 1637 |
+
</head>
|
| 1638 |
+
<body>
|
| 1639 |
+
|
| 1640 |
+
<!-- Navbar -->
|
| 1641 |
+
<nav class="navbar-custom">
|
| 1642 |
+
<div class="container d-flex justify-content-between align-items-center">
|
| 1643 |
+
<a class="brand" href="#">
|
| 1644 |
+
<i class="fas fa-brain"></i> ''' + model_name + '''
|
| 1645 |
+
</a>
|
| 1646 |
+
<span class="badge-model">
|
| 1647 |
+
<i class="fas fa-microchip"></i> ''' + problem_type.title() + '''
|
| 1648 |
+
</span>
|
| 1649 |
+
</div>
|
| 1650 |
+
</nav>
|
| 1651 |
+
|
| 1652 |
+
<!-- Hero -->
|
| 1653 |
+
<div class="container">
|
| 1654 |
+
<div class="hero">
|
| 1655 |
+
<h1><i class="fas fa-wand-magic-sparkles"></i> Prediction Engine</h1>
|
| 1656 |
+
<p>Enter your data below and get instant predictions powered by machine learning</p>
|
| 1657 |
+
<div class="hero-badge">
|
| 1658 |
+
<i class="fas fa-bullseye"></i> Predicting: <strong>''' + target_name + '''</strong>
|
| 1659 |
+
</div>
|
| 1660 |
+
</div>
|
| 1661 |
+
|
| 1662 |
+
<!-- Stats -->
|
| 1663 |
+
<div class="stats-bar">
|
| 1664 |
+
<div class="stat-item">
|
| 1665 |
+
<div class="stat-val">''' + str(len(feature_names)) + '''</div>
|
| 1666 |
+
<div class="stat-lbl">Features</div>
|
| 1667 |
+
</div>
|
| 1668 |
+
<div class="stat-item">
|
| 1669 |
+
<div class="stat-val">''' + str(len(numeric_cols)) + '''</div>
|
| 1670 |
+
<div class="stat-lbl">Numeric</div>
|
| 1671 |
+
</div>
|
| 1672 |
+
<div class="stat-item">
|
| 1673 |
+
<div class="stat-val">''' + str(len(categorical_cols)) + '''</div>
|
| 1674 |
+
<div class="stat-lbl">Categorical</div>
|
| 1675 |
+
</div>
|
| 1676 |
+
</div>
|
| 1677 |
+
|
| 1678 |
+
<!-- Form Card -->
|
| 1679 |
+
<div class="row justify-content-center">
|
| 1680 |
+
<div class="col-lg-10">
|
| 1681 |
+
<form id="predictForm" class="glass-card">
|
| 1682 |
+
<div class="card-title">
|
| 1683 |
+
<i class="fas fa-sliders"></i> Input Features
|
| 1684 |
+
</div>
|
| 1685 |
+
<div class="row">''' + form_fields + '''
|
| 1686 |
+
</div>
|
| 1687 |
+
<div class="row mt-3">
|
| 1688 |
+
<div class="col-md-8 mb-2">
|
| 1689 |
+
<button type="submit" class="btn-predict" id="predictBtn">
|
| 1690 |
+
<i class="fas fa-bolt"></i> Get Prediction
|
| 1691 |
+
</button>
|
| 1692 |
+
</div>
|
| 1693 |
+
<div class="col-md-4 mb-2">
|
| 1694 |
+
<button type="reset" class="btn-reset" id="resetBtn">
|
| 1695 |
+
<i class="fas fa-rotate-left"></i> Reset
|
| 1696 |
+
</button>
|
| 1697 |
+
</div>
|
| 1698 |
+
</div>
|
| 1699 |
+
</form>
|
| 1700 |
+
|
| 1701 |
+
<!-- Result -->
|
| 1702 |
+
<div id="resultSection" class="glass-card text-center">
|
| 1703 |
+
<div class="card-title justify-content-center">
|
| 1704 |
+
<i class="fas fa-sparkles"></i> Prediction Result
|
| 1705 |
+
</div>
|
| 1706 |
+
<div class="result-label mb-2">''' + target_name + '''</div>
|
| 1707 |
+
<div id="resultValue" class="result-value">β</div>
|
| 1708 |
+
</div>
|
| 1709 |
+
</div>
|
| 1710 |
+
</div>
|
| 1711 |
+
</div>
|
| 1712 |
+
|
| 1713 |
+
<!-- Loading -->
|
| 1714 |
+
<div class="spinner-overlay" id="spinner">
|
| 1715 |
+
<div class="spinner-ring"></div>
|
| 1716 |
+
<div style="color: var(--text-muted);">Analyzing...</div>
|
| 1717 |
+
</div>
|
| 1718 |
+
|
| 1719 |
+
<!-- Footer -->
|
| 1720 |
+
<div class="footer">
|
| 1721 |
+
<i class="fas fa-robot"></i> Powered by Data2Model β Automated Machine Learning Platform
|
| 1722 |
+
</div>
|
| 1723 |
+
|
| 1724 |
+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
| 1725 |
+
<script>
|
| 1726 |
+
const form = document.getElementById('predictForm');
|
| 1727 |
+
const resultSection = document.getElementById('resultSection');
|
| 1728 |
+
const resultValue = document.getElementById('resultValue');
|
| 1729 |
+
const spinner = document.getElementById('spinner');
|
| 1730 |
+
|
| 1731 |
+
form.addEventListener('submit', async (e) => {
|
| 1732 |
+
e.preventDefault();
|
| 1733 |
+
spinner.style.display = 'flex';
|
| 1734 |
+
resultSection.style.display = 'none';
|
| 1735 |
+
|
| 1736 |
+
const formData = new FormData(form);
|
| 1737 |
+
|
| 1738 |
+
try {
|
| 1739 |
+
const resp = await fetch('/predict', { method: 'POST', body: formData });
|
| 1740 |
+
const data = await resp.json();
|
| 1741 |
+
|
| 1742 |
+
spinner.style.display = 'none';
|
| 1743 |
+
resultSection.style.display = 'block';
|
| 1744 |
+
resultSection.style.animation = 'none';
|
| 1745 |
+
void resultSection.offsetHeight; // trigger reflow
|
| 1746 |
+
resultSection.style.animation = 'slideUp 0.5s ease';
|
| 1747 |
+
|
| 1748 |
+
if (data.success) {
|
| 1749 |
+
resultValue.textContent = data.prediction;
|
| 1750 |
+
resultValue.className = 'result-value';
|
| 1751 |
+
} else {
|
| 1752 |
+
resultValue.textContent = data.error || 'Prediction failed';
|
| 1753 |
+
resultValue.className = 'result-value error-value';
|
| 1754 |
+
}
|
| 1755 |
+
} catch (err) {
|
| 1756 |
+
spinner.style.display = 'none';
|
| 1757 |
+
resultSection.style.display = 'block';
|
| 1758 |
+
resultValue.textContent = 'Connection error';
|
| 1759 |
+
resultValue.className = 'result-value error-value';
|
| 1760 |
+
}
|
| 1761 |
+
});
|
| 1762 |
+
|
| 1763 |
+
document.getElementById('resetBtn').addEventListener('click', () => {
|
| 1764 |
+
resultSection.style.display = 'none';
|
| 1765 |
+
});
|
| 1766 |
+
</script>
|
| 1767 |
+
</body>
|
| 1768 |
+
</html>'''
|
| 1769 |
+
|
| 1770 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1771 |
+
# Main Pipeline
|
| 1772 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1773 |
+
def run_complete_pipeline(self,
|
| 1774 |
+
file_path,
|
| 1775 |
+
target_column=None,
|
| 1776 |
+
file_type='csv',
|
| 1777 |
+
problem_type='auto',
|
| 1778 |
+
split_type='train_test', # FIX 4
|
| 1779 |
+
test_size=0.2,
|
| 1780 |
+
val_size=0.2,
|
| 1781 |
+
null_strategies=None, # FIX 1 & 2
|
| 1782 |
+
scaling_config='standard', # FIX 6
|
| 1783 |
+
encoding_config='auto', # FIX 7
|
| 1784 |
+
categorical_overrides=None, # FIX 8
|
| 1785 |
+
drop_columns=None): # NEW: Delete Columns feature
|
| 1786 |
+
print("\n" + "="*55)
|
| 1787 |
+
print("π DATA2MODEL - AUTOMATED ML PIPELINE")
|
| 1788 |
+
print("="*55 + "\n")
|
| 1789 |
+
|
| 1790 |
+
# 1. Load
|
| 1791 |
+
data = self.load_data(file_path, file_type)
|
| 1792 |
+
|
| 1793 |
+
# Apply column dropping
|
| 1794 |
+
self.drop_columns = drop_columns or []
|
| 1795 |
+
if self.drop_columns:
|
| 1796 |
+
# Ensure target column is not dropped
|
| 1797 |
+
if target_column in self.drop_columns:
|
| 1798 |
+
self.drop_columns.remove(target_column)
|
| 1799 |
+
print(f" Warning: Target column '{target_column}' cannot be dropped. It was removed from drop list.")
|
| 1800 |
+
|
| 1801 |
+
existing_to_drop = [c for c in self.drop_columns if c in data.columns]
|
| 1802 |
+
if existing_to_drop:
|
| 1803 |
+
data = data.drop(columns=existing_to_drop)
|
| 1804 |
+
self.preprocessing_steps.append(f"Dropped columns: {', '.join(existing_to_drop)}")
|
| 1805 |
+
print(f" Dropped {len(existing_to_drop)} columns specified by user.")
|
| 1806 |
+
|
| 1807 |
+
# Ensure numeric-looking columns accidentally read as strings are safely converted before detection/training
|
| 1808 |
+
for col in data.columns:
|
| 1809 |
+
if col == target_column:
|
| 1810 |
+
continue
|
| 1811 |
+
if str(data[col].dtype) in ('object', 'string'):
|
| 1812 |
+
converted = pd.to_numeric(data[col], errors='coerce')
|
| 1813 |
+
non_null_original = data[col].dropna().shape[0]
|
| 1814 |
+
non_null_converted = converted.dropna().shape[0]
|
| 1815 |
+
if non_null_original > 0 and non_null_converted >= 0.9 * non_null_original:
|
| 1816 |
+
data[col] = converted
|
| 1817 |
+
print(f" Safely converted numeric-looking column '{col}' to numeric.")
|
| 1818 |
+
|
| 1819 |
+
# 2. Analyse with smart type detection (FIX 8)
|
| 1820 |
+
analysis = self.analyze_data(data, categorical_overrides, target_column=target_column)
|
| 1821 |
+
self.numeric_cols = analysis['numeric_columns']
|
| 1822 |
+
self.categorical_cols = analysis['categorical_columns']
|
| 1823 |
+
print(f" Numeric cols: {len(self.numeric_cols)} | Categorical cols: {len(self.categorical_cols)}")
|
| 1824 |
+
|
| 1825 |
+
# 3. Null handling with imputation (FIX 1 & 2)
|
| 1826 |
+
print("\nπ§ Handling missing values...")
|
| 1827 |
+
data = self.handle_missing_values(data, null_strategies, target_column=target_column)
|
| 1828 |
+
|
| 1829 |
+
# 4. Remove duplicates
|
| 1830 |
+
before = len(data)
|
| 1831 |
+
data = data.drop_duplicates()
|
| 1832 |
+
if len(data) < before:
|
| 1833 |
+
print(f" Removed {before - len(data)} duplicate rows")
|
| 1834 |
+
|
| 1835 |
+
# ββ Unsupervised path (FIX 3: target column not needed) ββββββββββββββ
|
| 1836 |
+
is_unsupervised = problem_type in ('clustering', 'dimensionality_reduction', 'association')
|
| 1837 |
+
|
| 1838 |
+
if is_unsupervised:
|
| 1839 |
+
X = data.copy()
|
| 1840 |
+
self.feature_names = list(X.columns)
|
| 1841 |
+
|
| 1842 |
+
# Encode + Scale
|
| 1843 |
+
dummy_test = X.copy()
|
| 1844 |
+
X, dummy_test = self.encode_features(X, dummy_test,
|
| 1845 |
+
encoding_config=encoding_config,
|
| 1846 |
+
categorical_cols=self.categorical_cols)
|
| 1847 |
+
X, dummy_test = self.scale_features(X, dummy_test,
|
| 1848 |
+
scaling_config=scaling_config,
|
| 1849 |
+
numeric_cols=self.numeric_cols)
|
| 1850 |
+
|
| 1851 |
+
self.trained_features = list(X.columns)
|
| 1852 |
+
self.train_unsupervised(X, problem_type)
|
| 1853 |
+
model_path = self.save_model()
|
| 1854 |
+
return {
|
| 1855 |
+
'model_path': model_path,
|
| 1856 |
+
'results': self.results,
|
| 1857 |
+
'analysis': analysis,
|
| 1858 |
+
'model_name': self.model_name,
|
| 1859 |
+
'problem_type': self.problem_type,
|
| 1860 |
+
'split_info': 'No split (unsupervised)',
|
| 1861 |
+
}
|
| 1862 |
+
|
| 1863 |
+
# ββ Supervised path ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1864 |
+
if target_column is None or target_column not in data.columns:
|
| 1865 |
+
raise ValueError(f"Target column '{target_column}' not found.")
|
| 1866 |
+
|
| 1867 |
+
X = data.drop(columns=[target_column])
|
| 1868 |
+
y = data[target_column]
|
| 1869 |
+
self.feature_names = list(X.columns)
|
| 1870 |
+
self.target_name = target_column
|
| 1871 |
+
|
| 1872 |
+
# Remove target from col lists if it was included
|
| 1873 |
+
num_cols = [c for c in self.numeric_cols if c != target_column]
|
| 1874 |
+
cat_cols = [c for c in self.categorical_cols if c != target_column]
|
| 1875 |
+
|
| 1876 |
+
# Store categorical unique values for deployable app generation
|
| 1877 |
+
self.categorical_values = {}
|
| 1878 |
+
for col in cat_cols:
|
| 1879 |
+
if col in X.columns:
|
| 1880 |
+
self.categorical_values[col] = X[col].dropna().unique().tolist()[:50]
|
| 1881 |
+
|
| 1882 |
+
# 5. Split (FIX 4)
|
| 1883 |
+
use_val = (split_type == 'train_test_val')
|
| 1884 |
+
if use_val:
|
| 1885 |
+
X_tr, X_tmp, y_tr, y_tmp = train_test_split(X, y, test_size=(test_size + val_size), random_state=42)
|
| 1886 |
+
ratio = val_size / (test_size + val_size)
|
| 1887 |
+
X_te, X_val, y_te, y_val = train_test_split(X_tmp, y_tmp, test_size=ratio, random_state=42)
|
| 1888 |
+
split_info = f"Train {int((1-test_size-val_size)*100)}% / Test {int(test_size*100)}% / Val {int(val_size*100)}%"
|
| 1889 |
+
print(f"\nβ Split: {split_info}")
|
| 1890 |
+
print(f" Train: {len(X_tr)} | Test: {len(X_te)} | Val: {len(X_val)}")
|
| 1891 |
+
else:
|
| 1892 |
+
X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=test_size, random_state=42)
|
| 1893 |
+
X_val, y_val = None, None
|
| 1894 |
+
split_info = f"Train {int((1-test_size)*100)}% / Test {int(test_size*100)}%"
|
| 1895 |
+
print(f"\nβ Split: {split_info}")
|
| 1896 |
+
print(f" Train: {len(X_tr)} | Test: {len(X_te)}")
|
| 1897 |
+
|
| 1898 |
+
# 6. Encode categorical (FIX 5 & 7: only if cat cols exist, per-column)
|
| 1899 |
+
print("\nπ€ Encoding categorical features...")
|
| 1900 |
+
if use_val:
|
| 1901 |
+
X_tr, X_te, X_val = self.encode_features(
|
| 1902 |
+
X_tr, X_te, X_val, encoding_config=encoding_config, categorical_cols=cat_cols)
|
| 1903 |
+
else:
|
| 1904 |
+
X_tr, X_te = self.encode_features(
|
| 1905 |
+
X_tr, X_te, encoding_config=encoding_config, categorical_cols=cat_cols)
|
| 1906 |
+
|
| 1907 |
+
# 7. Scale numeric (FIX 6: per-column)
|
| 1908 |
+
print("β Scaling numeric features...")
|
| 1909 |
+
# Update numeric_cols after encoding (some may have been one-hot expanded)
|
| 1910 |
+
current_num_cols = [c for c in X_tr.columns if c in num_cols]
|
| 1911 |
+
if use_val:
|
| 1912 |
+
X_tr, X_te, X_val = self.scale_features(
|
| 1913 |
+
X_tr, X_te, X_val, scaling_config=scaling_config, numeric_cols=current_num_cols)
|
| 1914 |
+
else:
|
| 1915 |
+
X_tr, X_te = self.scale_features(
|
| 1916 |
+
X_tr, X_te, scaling_config=scaling_config, numeric_cols=current_num_cols)
|
| 1917 |
+
|
| 1918 |
+
# 8. Train
|
| 1919 |
+
print("\nπ€ Training models...")
|
| 1920 |
+
self.trained_features = list(X_tr.columns)
|
| 1921 |
+
self.train_model(X_tr, y_tr, X_te, y_te, problem_type=problem_type)
|
| 1922 |
+
|
| 1923 |
+
# 9. Validation metrics (if val split used)
|
| 1924 |
+
if use_val and self.model:
|
| 1925 |
+
y_val_pred = self.model.predict(X_val)
|
| 1926 |
+
if self.problem_type == 'classification':
|
| 1927 |
+
val_acc = accuracy_score(y_val, y_val_pred)
|
| 1928 |
+
self.results['validation_accuracy'] = val_acc
|
| 1929 |
+
print(f" Validation Accuracy: {val_acc:.4f}")
|
| 1930 |
+
else:
|
| 1931 |
+
self.results['validation_rmse'] = np.sqrt(mean_squared_error(y_val, y_val_pred))
|
| 1932 |
+
self.results['validation_r2'] = r2_score(y_val, y_val_pred)
|
| 1933 |
+
print(f" Validation RΒ²: {self.results['validation_r2']:.4f}")
|
| 1934 |
+
|
| 1935 |
+
# 10. Save
|
| 1936 |
+
model_path = self.save_model()
|
| 1937 |
+
|
| 1938 |
+
# Save preprocessing artifacts only when they were applied
|
| 1939 |
+
scaler_path = None
|
| 1940 |
+
encoder_path = None
|
| 1941 |
+
if self.scalers:
|
| 1942 |
+
scaler_path = self.save_scalers()
|
| 1943 |
+
if self.encoders or (hasattr(self, 'onehot_cols') and self.onehot_cols):
|
| 1944 |
+
encoder_path = self.save_encoders()
|
| 1945 |
+
|
| 1946 |
+
# Generate the deployable app bundle
|
| 1947 |
+
deployable_app_path = self.generate_deployable_app(model_path, scaler_path, encoder_path)
|
| 1948 |
+
|
| 1949 |
+
print("\n" + "="*55)
|
| 1950 |
+
print("β
PIPELINE COMPLETED!")
|
| 1951 |
+
print("="*55 + "\n")
|
| 1952 |
+
|
| 1953 |
+
return {
|
| 1954 |
+
'model_path': model_path,
|
| 1955 |
+
'scaler_path': scaler_path,
|
| 1956 |
+
'encoder_path': encoder_path,
|
| 1957 |
+
'deployable_app_path': deployable_app_path,
|
| 1958 |
+
'scaling_applied': bool(self.scalers),
|
| 1959 |
+
'encoding_applied': bool(self.encoders) or (hasattr(self, 'onehot_cols') and bool(self.onehot_cols)),
|
| 1960 |
+
'results': self.results,
|
| 1961 |
+
'analysis': analysis,
|
| 1962 |
+
'model_name': self.model_name,
|
| 1963 |
+
'problem_type': self.problem_type,
|
| 1964 |
+
'split_info': split_info,
|
| 1965 |
+
'use_val': use_val,
|
| 1966 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 2 |
+
# Data2Model β Requirements
|
| 3 |
+
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 4 |
+
|
| 5 |
+
# Core Framework
|
| 6 |
+
Flask>=3.0.0
|
| 7 |
+
Werkzeug>=3.0.0
|
| 8 |
+
|
| 9 |
+
# Machine Learning
|
| 10 |
+
scikit-learn>=1.3.0
|
| 11 |
+
numpy>=1.24.0
|
| 12 |
+
pandas>=2.1.0
|
| 13 |
+
|
| 14 |
+
# Visualization (used in data dashboard)
|
| 15 |
+
matplotlib>=3.7.0
|
| 16 |
+
seaborn>=0.12.0
|
| 17 |
+
|
| 18 |
+
# Excel File Support
|
| 19 |
+
openpyxl>=3.1.0
|
| 20 |
+
xlrd>=2.0.0
|
| 21 |
+
|
| 22 |
+
# Boosting Models (optional β auto-detected at runtime)
|
| 23 |
+
xgboost>=2.0.0
|
| 24 |
+
lightgbm>=4.1.0
|
| 25 |
+
|
| 26 |
+
# Scientific Computing
|
| 27 |
+
scipy>=1.11.0
|
| 28 |
+
joblib>=1.3.0
|
| 29 |
+
|
| 30 |
+
gunicorn
|
run.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Data2Model Run Script
|
| 4 |
+
Easy way to start the application
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
import sys
|
| 9 |
+
|
| 10 |
+
def main():
|
| 11 |
+
print("=" * 60)
|
| 12 |
+
print(" π Starting Data2Model Server")
|
| 13 |
+
print("=" * 60)
|
| 14 |
+
print()
|
| 15 |
+
print("Server will start at: http://localhost:5000")
|
| 16 |
+
print("Press Ctrl+C to stop the server")
|
| 17 |
+
print()
|
| 18 |
+
print("=" * 60)
|
| 19 |
+
print()
|
| 20 |
+
|
| 21 |
+
# Set environment variables
|
| 22 |
+
os.environ['FLASK_APP'] = 'app.py'
|
| 23 |
+
os.environ['FLASK_ENV'] = 'development'
|
| 24 |
+
|
| 25 |
+
# Import and run the app
|
| 26 |
+
try:
|
| 27 |
+
from app import app
|
| 28 |
+
app.run(debug=True, host='0.0.0.0', port=5000)
|
| 29 |
+
except ImportError:
|
| 30 |
+
print("β Error: Could not import app.py")
|
| 31 |
+
print(" Make sure you're in the Data2Model directory")
|
| 32 |
+
sys.exit(1)
|
| 33 |
+
except KeyboardInterrupt:
|
| 34 |
+
print("\n\nβ
Server stopped")
|
| 35 |
+
sys.exit(0)
|
| 36 |
+
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
main()
|
setup.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Data2Model Setup Script
|
| 4 |
+
Quick installation and setup utility
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
import sys
|
| 9 |
+
import subprocess
|
| 10 |
+
|
| 11 |
+
def check_python_version():
|
| 12 |
+
"""Check if Python version is 3.8 or higher"""
|
| 13 |
+
if sys.version_info < (3, 8):
|
| 14 |
+
print("β Python 3.8 or higher is required!")
|
| 15 |
+
print(f" Current version: {sys.version}")
|
| 16 |
+
sys.exit(1)
|
| 17 |
+
print(f"β
Python version: {sys.version.split()[0]}")
|
| 18 |
+
|
| 19 |
+
def create_directories():
|
| 20 |
+
"""Create necessary directories"""
|
| 21 |
+
directories = ['uploads', 'saved_models', 'templates', 'static/css', 'static/js']
|
| 22 |
+
for directory in directories:
|
| 23 |
+
os.makedirs(directory, exist_ok=True)
|
| 24 |
+
print(f"β
Created directory: {directory}")
|
| 25 |
+
|
| 26 |
+
def install_dependencies():
|
| 27 |
+
"""Install required Python packages"""
|
| 28 |
+
print("\nπ¦ Installing dependencies...")
|
| 29 |
+
try:
|
| 30 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
|
| 31 |
+
print("β
Dependencies installed successfully!")
|
| 32 |
+
except subprocess.CalledProcessError:
|
| 33 |
+
print("β Failed to install dependencies")
|
| 34 |
+
sys.exit(1)
|
| 35 |
+
|
| 36 |
+
def create_placeholder_files():
|
| 37 |
+
"""Create .gitkeep files to preserve empty directories"""
|
| 38 |
+
for directory in ['uploads', 'saved_models']:
|
| 39 |
+
gitkeep = os.path.join(directory, '.gitkeep')
|
| 40 |
+
with open(gitkeep, 'w') as f:
|
| 41 |
+
f.write('')
|
| 42 |
+
print(f"β
Created {gitkeep}")
|
| 43 |
+
|
| 44 |
+
def main():
|
| 45 |
+
"""Main setup function"""
|
| 46 |
+
print("=" * 60)
|
| 47 |
+
print(" Data2Model - Setup Script")
|
| 48 |
+
print(" Automated ML Platform")
|
| 49 |
+
print("=" * 60)
|
| 50 |
+
print()
|
| 51 |
+
|
| 52 |
+
# Check Python version
|
| 53 |
+
check_python_version()
|
| 54 |
+
|
| 55 |
+
# Create directories
|
| 56 |
+
print("\nπ Creating directories...")
|
| 57 |
+
create_directories()
|
| 58 |
+
create_placeholder_files()
|
| 59 |
+
|
| 60 |
+
# Install dependencies
|
| 61 |
+
install_dependencies()
|
| 62 |
+
|
| 63 |
+
print("\n" + "=" * 60)
|
| 64 |
+
print("β
Setup completed successfully!")
|
| 65 |
+
print("=" * 60)
|
| 66 |
+
print("\nTo start the application:")
|
| 67 |
+
print(" python app.py")
|
| 68 |
+
print("\nThen open your browser and navigate to:")
|
| 69 |
+
print(" http://localhost:5000")
|
| 70 |
+
print()
|
| 71 |
+
|
| 72 |
+
if __name__ == "__main__":
|
| 73 |
+
main()
|
static/css/style.css
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Data2Model Custom Styles */
|
| 2 |
+
|
| 3 |
+
:root {
|
| 4 |
+
--primary-color: #667eea;
|
| 5 |
+
--secondary-color: #764ba2;
|
| 6 |
+
--success-color: #10b981;
|
| 7 |
+
--danger-color: #ef4444;
|
| 8 |
+
--warning-color: #f59e0b;
|
| 9 |
+
--info-color: #3b82f6;
|
| 10 |
+
--dark-color: #1f2937;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
body {
|
| 14 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 15 |
+
min-height: 100vh;
|
| 16 |
+
display: flex;
|
| 17 |
+
flex-direction: column;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
main {
|
| 21 |
+
flex: 1;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
/* Navbar Styles */
|
| 25 |
+
.navbar-brand {
|
| 26 |
+
font-weight: bold;
|
| 27 |
+
font-size: 1.5rem;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.navbar-brand i {
|
| 31 |
+
margin-right: 8px;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
.nav-link {
|
| 35 |
+
transition: all 0.3s ease;
|
| 36 |
+
margin: 0 5px;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
.nav-link:hover {
|
| 40 |
+
transform: translateY(-2px);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/* Card Styles */
|
| 44 |
+
.card {
|
| 45 |
+
border: none;
|
| 46 |
+
border-radius: 10px;
|
| 47 |
+
overflow: hidden;
|
| 48 |
+
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.card:hover {
|
| 52 |
+
transform: translateY(-5px);
|
| 53 |
+
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15) !important;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
.card-header {
|
| 57 |
+
border-bottom: none;
|
| 58 |
+
padding: 1.25rem 1.5rem;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
/* Button Styles */
|
| 62 |
+
.btn {
|
| 63 |
+
border-radius: 8px;
|
| 64 |
+
padding: 10px 20px;
|
| 65 |
+
font-weight: 500;
|
| 66 |
+
transition: all 0.3s ease;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
.btn-lg {
|
| 70 |
+
padding: 12px 30px;
|
| 71 |
+
font-size: 1.1rem;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
.btn:hover {
|
| 75 |
+
transform: translateY(-2px);
|
| 76 |
+
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/* Alert Styles */
|
| 80 |
+
.alert {
|
| 81 |
+
border-radius: 8px;
|
| 82 |
+
border: none;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
/* Form Styles */
|
| 86 |
+
.form-control,
|
| 87 |
+
.form-select {
|
| 88 |
+
border-radius: 8px;
|
| 89 |
+
padding: 10px 15px;
|
| 90 |
+
border: 2px solid #e5e7eb;
|
| 91 |
+
transition: all 0.3s ease;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
.form-control:focus,
|
| 95 |
+
.form-select:focus {
|
| 96 |
+
border-color: var(--primary-color);
|
| 97 |
+
box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/* Hero Section */
|
| 101 |
+
.hero-section {
|
| 102 |
+
background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
|
| 103 |
+
border-radius: 0 0 50px 50px;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
/* Step Circle */
|
| 107 |
+
.step-circle {
|
| 108 |
+
width: 80px;
|
| 109 |
+
height: 80px;
|
| 110 |
+
line-height: 80px;
|
| 111 |
+
border-radius: 50%;
|
| 112 |
+
font-size: 2rem;
|
| 113 |
+
font-weight: bold;
|
| 114 |
+
display: inline-flex;
|
| 115 |
+
align-items: center;
|
| 116 |
+
justify-content: center;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
/* Metric Box */
|
| 120 |
+
.metric-box {
|
| 121 |
+
padding: 20px;
|
| 122 |
+
border-radius: 10px;
|
| 123 |
+
background-color: #f8f9fa;
|
| 124 |
+
transition: all 0.3s ease;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
.metric-box:hover {
|
| 128 |
+
background-color: #e9ecef;
|
| 129 |
+
transform: scale(1.05);
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.metric-box h3 {
|
| 133 |
+
font-size: 2.5rem;
|
| 134 |
+
font-weight: bold;
|
| 135 |
+
margin-bottom: 5px;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
.metric-box p {
|
| 139 |
+
margin-bottom: 0;
|
| 140 |
+
font-weight: 500;
|
| 141 |
+
text-transform: uppercase;
|
| 142 |
+
font-size: 0.9rem;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
/* Table Styles */
|
| 146 |
+
.table {
|
| 147 |
+
border-radius: 8px;
|
| 148 |
+
overflow: hidden;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
.table-hover tbody tr:hover {
|
| 152 |
+
background-color: rgba(102, 126, 234, 0.1);
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
/* Loading Animation */
|
| 156 |
+
.loading {
|
| 157 |
+
display: inline-block;
|
| 158 |
+
width: 20px;
|
| 159 |
+
height: 20px;
|
| 160 |
+
border: 3px solid rgba(255, 255, 255, 0.3);
|
| 161 |
+
border-radius: 50%;
|
| 162 |
+
border-top-color: #fff;
|
| 163 |
+
animation: spin 1s ease-in-out infinite;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
@keyframes spin {
|
| 167 |
+
to { transform: rotate(360deg); }
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
/* Footer */
|
| 171 |
+
footer {
|
| 172 |
+
margin-top: auto;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
/* Utility Classes */
|
| 176 |
+
.shadow-lg {
|
| 177 |
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1) !important;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
.rounded-lg {
|
| 181 |
+
border-radius: 15px !important;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
/* Badge Styles */
|
| 185 |
+
.badge {
|
| 186 |
+
padding: 6px 12px;
|
| 187 |
+
border-radius: 6px;
|
| 188 |
+
font-weight: 500;
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
/* File Upload */
|
| 192 |
+
.form-control[type="file"] {
|
| 193 |
+
padding: 10px;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
.form-control[type="file"]::file-selector-button {
|
| 197 |
+
padding: 8px 20px;
|
| 198 |
+
border-radius: 6px;
|
| 199 |
+
border: none;
|
| 200 |
+
background: var(--primary-color);
|
| 201 |
+
color: white;
|
| 202 |
+
cursor: pointer;
|
| 203 |
+
transition: all 0.3s ease;
|
| 204 |
+
margin-right: 15px;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
.form-control[type="file"]::file-selector-button:hover {
|
| 208 |
+
background: var(--secondary-color);
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
/* Responsive Design */
|
| 212 |
+
@media (max-width: 768px) {
|
| 213 |
+
.hero-section {
|
| 214 |
+
border-radius: 0 0 30px 30px;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
.display-4 {
|
| 218 |
+
font-size: 2rem;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
.step-circle {
|
| 222 |
+
width: 60px;
|
| 223 |
+
height: 60px;
|
| 224 |
+
line-height: 60px;
|
| 225 |
+
font-size: 1.5rem;
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
.metric-box h3 {
|
| 229 |
+
font-size: 2rem;
|
| 230 |
+
}
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
/* Animation Classes */
|
| 234 |
+
.fade-in {
|
| 235 |
+
animation: fadeIn 0.5s ease-in;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
@keyframes fadeIn {
|
| 239 |
+
from {
|
| 240 |
+
opacity: 0;
|
| 241 |
+
transform: translateY(20px);
|
| 242 |
+
}
|
| 243 |
+
to {
|
| 244 |
+
opacity: 1;
|
| 245 |
+
transform: translateY(0);
|
| 246 |
+
}
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
.slide-in {
|
| 250 |
+
animation: slideIn 0.5s ease-out;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
@keyframes slideIn {
|
| 254 |
+
from {
|
| 255 |
+
transform: translateX(-100%);
|
| 256 |
+
}
|
| 257 |
+
to {
|
| 258 |
+
transform: translateX(0);
|
| 259 |
+
}
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
/* Code Block Styles */
|
| 263 |
+
pre {
|
| 264 |
+
border-radius: 8px;
|
| 265 |
+
padding: 15px;
|
| 266 |
+
background-color: #f8f9fa;
|
| 267 |
+
border: 1px solid #e5e7eb;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
code {
|
| 271 |
+
color: #e83e8c;
|
| 272 |
+
font-family: 'Courier New', Courier, monospace;
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
/* Progress Bar */
|
| 276 |
+
.progress {
|
| 277 |
+
height: 25px;
|
| 278 |
+
border-radius: 8px;
|
| 279 |
+
overflow: hidden;
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
.progress-bar {
|
| 283 |
+
font-weight: 500;
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
/* Custom Scrollbar */
|
| 287 |
+
::-webkit-scrollbar {
|
| 288 |
+
width: 10px;
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
::-webkit-scrollbar-track {
|
| 292 |
+
background: #f1f1f1;
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
::-webkit-scrollbar-thumb {
|
| 296 |
+
background: var(--primary-color);
|
| 297 |
+
border-radius: 5px;
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
::-webkit-scrollbar-thumb:hover {
|
| 301 |
+
background: var(--secondary-color);
|
| 302 |
+
}
|
static/js/script.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Data2Model JavaScript
|
| 2 |
+
|
| 3 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 4 |
+
// Initialize tooltips
|
| 5 |
+
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
|
| 6 |
+
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
|
| 7 |
+
return new bootstrap.Tooltip(tooltipTriggerEl);
|
| 8 |
+
});
|
| 9 |
+
|
| 10 |
+
// File upload validation
|
| 11 |
+
const fileInput = document.getElementById('file');
|
| 12 |
+
if (fileInput) {
|
| 13 |
+
fileInput.addEventListener('change', function(e) {
|
| 14 |
+
const file = e.target.files[0];
|
| 15 |
+
if (file) {
|
| 16 |
+
// Check file extension
|
| 17 |
+
const allowedExtensions = ['csv', 'xlsx', 'xls', 'json'];
|
| 18 |
+
const fileName = file.name.toLowerCase();
|
| 19 |
+
const fileExtension = fileName.split('.').pop();
|
| 20 |
+
|
| 21 |
+
if (!allowedExtensions.includes(fileExtension)) {
|
| 22 |
+
alert('Invalid file type. Please upload CSV, Excel, or JSON files only.');
|
| 23 |
+
fileInput.value = '';
|
| 24 |
+
return;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
// Show file info
|
| 28 |
+
console.log('File selected:', file.name, 'Size:', (file.size / 1024 / 1024).toFixed(2) + ' MB');
|
| 29 |
+
}
|
| 30 |
+
});
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
// Form submission with loading indicator
|
| 34 |
+
const forms = document.querySelectorAll('form');
|
| 35 |
+
forms.forEach(form => {
|
| 36 |
+
form.addEventListener('submit', function(e) {
|
| 37 |
+
const submitBtn = form.querySelector('button[type="submit"]');
|
| 38 |
+
if (submitBtn) {
|
| 39 |
+
// Disable button and show loading
|
| 40 |
+
submitBtn.disabled = true;
|
| 41 |
+
const originalText = submitBtn.innerHTML;
|
| 42 |
+
submitBtn.innerHTML = '<span class="loading"></span> Processing...';
|
| 43 |
+
|
| 44 |
+
// Re-enable after 2 seconds if form doesn't submit
|
| 45 |
+
setTimeout(() => {
|
| 46 |
+
if (submitBtn.disabled) {
|
| 47 |
+
submitBtn.disabled = false;
|
| 48 |
+
submitBtn.innerHTML = originalText;
|
| 49 |
+
}
|
| 50 |
+
}, 60000); // 60 seconds timeout
|
| 51 |
+
}
|
| 52 |
+
});
|
| 53 |
+
});
|
| 54 |
+
|
| 55 |
+
// Auto-hide alerts after 5 seconds
|
| 56 |
+
const alerts = document.querySelectorAll('.alert');
|
| 57 |
+
alerts.forEach(alert => {
|
| 58 |
+
setTimeout(() => {
|
| 59 |
+
const bsAlert = new bootstrap.Alert(alert);
|
| 60 |
+
bsAlert.close();
|
| 61 |
+
}, 5000);
|
| 62 |
+
});
|
| 63 |
+
|
| 64 |
+
// Smooth scroll for anchor links
|
| 65 |
+
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
| 66 |
+
anchor.addEventListener('click', function (e) {
|
| 67 |
+
e.preventDefault();
|
| 68 |
+
const target = document.querySelector(this.getAttribute('href'));
|
| 69 |
+
if (target) {
|
| 70 |
+
target.scrollIntoView({
|
| 71 |
+
behavior: 'smooth',
|
| 72 |
+
block: 'start'
|
| 73 |
+
});
|
| 74 |
+
}
|
| 75 |
+
});
|
| 76 |
+
});
|
| 77 |
+
|
| 78 |
+
// Add fade-in animation to cards
|
| 79 |
+
const cards = document.querySelectorAll('.card');
|
| 80 |
+
const observerOptions = {
|
| 81 |
+
threshold: 0.1,
|
| 82 |
+
rootMargin: '0px 0px -50px 0px'
|
| 83 |
+
};
|
| 84 |
+
|
| 85 |
+
const observer = new IntersectionObserver(function(entries) {
|
| 86 |
+
entries.forEach(entry => {
|
| 87 |
+
if (entry.isIntersecting) {
|
| 88 |
+
entry.target.classList.add('fade-in');
|
| 89 |
+
observer.unobserve(entry.target);
|
| 90 |
+
}
|
| 91 |
+
});
|
| 92 |
+
}, observerOptions);
|
| 93 |
+
|
| 94 |
+
cards.forEach(card => {
|
| 95 |
+
observer.observe(card);
|
| 96 |
+
});
|
| 97 |
+
|
| 98 |
+
// Target column change handler
|
| 99 |
+
const targetColumnSelect = document.getElementById('target_column');
|
| 100 |
+
if (targetColumnSelect) {
|
| 101 |
+
targetColumnSelect.addEventListener('change', function() {
|
| 102 |
+
console.log('Target column selected:', this.value);
|
| 103 |
+
// You can add more logic here if needed
|
| 104 |
+
});
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
// Problem type auto-suggestion (placeholder for future enhancement)
|
| 108 |
+
const problemTypeSelect = document.getElementById('problem_type');
|
| 109 |
+
if (problemTypeSelect && targetColumnSelect) {
|
| 110 |
+
targetColumnSelect.addEventListener('change', function() {
|
| 111 |
+
// This would need backend integration to suggest problem type
|
| 112 |
+
// based on target column data type
|
| 113 |
+
});
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
// Rating selection animation
|
| 117 |
+
const ratingInputs = document.querySelectorAll('input[name="rating"]');
|
| 118 |
+
ratingInputs.forEach(input => {
|
| 119 |
+
input.addEventListener('change', function() {
|
| 120 |
+
const label = document.querySelector(`label[for="${this.id}"]`);
|
| 121 |
+
if (label) {
|
| 122 |
+
label.style.transform = 'scale(1.1)';
|
| 123 |
+
setTimeout(() => {
|
| 124 |
+
label.style.transform = 'scale(1)';
|
| 125 |
+
}, 200);
|
| 126 |
+
}
|
| 127 |
+
});
|
| 128 |
+
});
|
| 129 |
+
|
| 130 |
+
// Copy code functionality for documentation
|
| 131 |
+
const codeBlocks = document.querySelectorAll('pre code');
|
| 132 |
+
codeBlocks.forEach(block => {
|
| 133 |
+
const copyBtn = document.createElement('button');
|
| 134 |
+
copyBtn.className = 'btn btn-sm btn-outline-secondary position-absolute top-0 end-0 m-2';
|
| 135 |
+
copyBtn.innerHTML = '<i class="fas fa-copy"></i>';
|
| 136 |
+
copyBtn.title = 'Copy code';
|
| 137 |
+
|
| 138 |
+
const pre = block.parentElement;
|
| 139 |
+
pre.style.position = 'relative';
|
| 140 |
+
pre.appendChild(copyBtn);
|
| 141 |
+
|
| 142 |
+
copyBtn.addEventListener('click', function() {
|
| 143 |
+
navigator.clipboard.writeText(block.textContent).then(() => {
|
| 144 |
+
copyBtn.innerHTML = '<i class="fas fa-check"></i>';
|
| 145 |
+
setTimeout(() => {
|
| 146 |
+
copyBtn.innerHTML = '<i class="fas fa-copy"></i>';
|
| 147 |
+
}, 2000);
|
| 148 |
+
});
|
| 149 |
+
});
|
| 150 |
+
});
|
| 151 |
+
|
| 152 |
+
// Prediction table enhancement
|
| 153 |
+
const predictionTable = document.querySelector('table');
|
| 154 |
+
if (predictionTable && window.location.pathname.includes('/predict')) {
|
| 155 |
+
// Add search functionality
|
| 156 |
+
const searchInput = document.createElement('input');
|
| 157 |
+
searchInput.type = 'text';
|
| 158 |
+
searchInput.className = 'form-control mb-3';
|
| 159 |
+
searchInput.placeholder = 'Search predictions...';
|
| 160 |
+
|
| 161 |
+
predictionTable.parentElement.insertBefore(searchInput, predictionTable);
|
| 162 |
+
|
| 163 |
+
searchInput.addEventListener('input', function() {
|
| 164 |
+
const searchTerm = this.value.toLowerCase();
|
| 165 |
+
const rows = predictionTable.querySelectorAll('tbody tr');
|
| 166 |
+
|
| 167 |
+
rows.forEach(row => {
|
| 168 |
+
const text = row.textContent.toLowerCase();
|
| 169 |
+
row.style.display = text.includes(searchTerm) ? '' : 'none';
|
| 170 |
+
});
|
| 171 |
+
});
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
// Add confirmation dialog for important actions
|
| 175 |
+
const dangerButtons = document.querySelectorAll('.btn-danger');
|
| 176 |
+
dangerButtons.forEach(btn => {
|
| 177 |
+
if (btn.textContent.toLowerCase().includes('delete') ||
|
| 178 |
+
btn.textContent.toLowerCase().includes('remove')) {
|
| 179 |
+
btn.addEventListener('click', function(e) {
|
| 180 |
+
if (!confirm('Are you sure you want to proceed?')) {
|
| 181 |
+
e.preventDefault();
|
| 182 |
+
}
|
| 183 |
+
});
|
| 184 |
+
}
|
| 185 |
+
});
|
| 186 |
+
|
| 187 |
+
// Performance monitoring
|
| 188 |
+
if (window.performance) {
|
| 189 |
+
window.addEventListener('load', function() {
|
| 190 |
+
const loadTime = window.performance.timing.loadEventEnd -
|
| 191 |
+
window.performance.timing.navigationStart;
|
| 192 |
+
console.log('Page load time:', (loadTime / 1000).toFixed(2), 'seconds');
|
| 193 |
+
});
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
// Add active class to current nav item
|
| 197 |
+
const currentLocation = window.location.pathname;
|
| 198 |
+
const navLinks = document.querySelectorAll('.nav-link');
|
| 199 |
+
navLinks.forEach(link => {
|
| 200 |
+
if (link.getAttribute('href') === currentLocation) {
|
| 201 |
+
link.classList.add('active');
|
| 202 |
+
}
|
| 203 |
+
});
|
| 204 |
+
|
| 205 |
+
// File size formatter
|
| 206 |
+
window.formatFileSize = function(bytes) {
|
| 207 |
+
if (bytes === 0) return '0 Bytes';
|
| 208 |
+
const k = 1024;
|
| 209 |
+
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
| 210 |
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
| 211 |
+
return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + ' ' + sizes[i];
|
| 212 |
+
};
|
| 213 |
+
|
| 214 |
+
// Number formatter
|
| 215 |
+
window.formatNumber = function(num, decimals = 2) {
|
| 216 |
+
return parseFloat(num).toFixed(decimals);
|
| 217 |
+
};
|
| 218 |
+
|
| 219 |
+
console.log('Data2Model initialized successfully!');
|
| 220 |
+
});
|
| 221 |
+
|
| 222 |
+
// Export utility functions
|
| 223 |
+
window.Data2Model = {
|
| 224 |
+
showLoading: function(element, text = 'Loading...') {
|
| 225 |
+
element.innerHTML = `<span class="loading"></span> ${text}`;
|
| 226 |
+
element.disabled = true;
|
| 227 |
+
},
|
| 228 |
+
|
| 229 |
+
hideLoading: function(element, text) {
|
| 230 |
+
element.innerHTML = text;
|
| 231 |
+
element.disabled = false;
|
| 232 |
+
},
|
| 233 |
+
|
| 234 |
+
showAlert: function(message, type = 'info') {
|
| 235 |
+
const alertDiv = document.createElement('div');
|
| 236 |
+
alertDiv.className = `alert alert-${type} alert-dismissible fade show`;
|
| 237 |
+
alertDiv.innerHTML = `
|
| 238 |
+
${message}
|
| 239 |
+
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
| 240 |
+
`;
|
| 241 |
+
|
| 242 |
+
const container = document.querySelector('.container');
|
| 243 |
+
if (container) {
|
| 244 |
+
container.insertBefore(alertDiv, container.firstChild);
|
| 245 |
+
|
| 246 |
+
setTimeout(() => {
|
| 247 |
+
const bsAlert = new bootstrap.Alert(alertDiv);
|
| 248 |
+
bsAlert.close();
|
| 249 |
+
}, 5000);
|
| 250 |
+
}
|
| 251 |
+
}
|
| 252 |
+
};
|
templates/404.html
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
|
| 3 |
+
{% block title %}404 - Page Not Found{% endblock %}
|
| 4 |
+
|
| 5 |
+
{% block content %}
|
| 6 |
+
<div class="container my-5">
|
| 7 |
+
<div class="row">
|
| 8 |
+
<div class="col-lg-8 mx-auto text-center">
|
| 9 |
+
<div class="error-page">
|
| 10 |
+
<h1 class="display-1 text-primary">404</h1>
|
| 11 |
+
<h2 class="mb-4">Page Not Found</h2>
|
| 12 |
+
<p class="lead mb-4">
|
| 13 |
+
Oops! The page you're looking for doesn't exist.
|
| 14 |
+
</p>
|
| 15 |
+
<i class="fas fa-search fa-5x text-muted mb-4"></i>
|
| 16 |
+
<div class="d-grid gap-2 col-md-6 mx-auto">
|
| 17 |
+
<a href="{{ url_for('index') }}" class="btn btn-primary btn-lg">
|
| 18 |
+
<i class="fas fa-home"></i> Go to Home
|
| 19 |
+
</a>
|
| 20 |
+
<button onclick="history.back()" class="btn btn-outline-secondary">
|
| 21 |
+
<i class="fas fa-arrow-left"></i> Go Back
|
| 22 |
+
</button>
|
| 23 |
+
</div>
|
| 24 |
+
</div>
|
| 25 |
+
</div>
|
| 26 |
+
</div>
|
| 27 |
+
</div>
|
| 28 |
+
|
| 29 |
+
<style>
|
| 30 |
+
.error-page {
|
| 31 |
+
padding: 50px 0;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
.display-1 {
|
| 35 |
+
font-size: 10rem;
|
| 36 |
+
font-weight: 700;
|
| 37 |
+
}
|
| 38 |
+
</style>
|
| 39 |
+
{% endblock %}
|
templates/500.html
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
|
| 3 |
+
{% block title %}500 - Server Error{% endblock %}
|
| 4 |
+
|
| 5 |
+
{% block content %}
|
| 6 |
+
<div class="container my-5">
|
| 7 |
+
<div class="row">
|
| 8 |
+
<div class="col-lg-8 mx-auto text-center">
|
| 9 |
+
<div class="error-page">
|
| 10 |
+
<h1 class="display-1 text-danger">500</h1>
|
| 11 |
+
<h2 class="mb-4">Internal Server Error</h2>
|
| 12 |
+
<p class="lead mb-4">
|
| 13 |
+
Something went wrong on our end. We're working to fix it!
|
| 14 |
+
</p>
|
| 15 |
+
<i class="fas fa-exclamation-triangle fa-5x text-warning mb-4"></i>
|
| 16 |
+
<div class="d-grid gap-2 col-md-6 mx-auto">
|
| 17 |
+
<a href="{{ url_for('index') }}" class="btn btn-primary btn-lg">
|
| 18 |
+
<i class="fas fa-home"></i> Go to Home
|
| 19 |
+
</a>
|
| 20 |
+
<button onclick="location.reload()" class="btn btn-outline-secondary">
|
| 21 |
+
<i class="fas fa-redo"></i> Try Again
|
| 22 |
+
</button>
|
| 23 |
+
</div>
|
| 24 |
+
<div class="mt-4">
|
| 25 |
+
<p class="text-muted small">
|
| 26 |
+
If the problem persists, please
|
| 27 |
+
<a href="{{ url_for('feedback') }}">contact us</a>
|
| 28 |
+
</p>
|
| 29 |
+
</div>
|
| 30 |
+
</div>
|
| 31 |
+
</div>
|
| 32 |
+
</div>
|
| 33 |
+
</div>
|
| 34 |
+
|
| 35 |
+
<style>
|
| 36 |
+
.error-page {
|
| 37 |
+
padding: 50px 0;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
.display-1 {
|
| 41 |
+
font-size: 10rem;
|
| 42 |
+
font-weight: 700;
|
| 43 |
+
}
|
| 44 |
+
</style>
|
| 45 |
+
{% endblock %}
|
templates/about.html
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
|
| 3 |
+
{% block title %}About - Data2Model{% endblock %}
|
| 4 |
+
|
| 5 |
+
{% block content %}
|
| 6 |
+
<div class="container my-5">
|
| 7 |
+
<div class="row">
|
| 8 |
+
<div class="col-lg-10 mx-auto">
|
| 9 |
+
<div class="text-center mb-5">
|
| 10 |
+
<h1 class="display-4">
|
| 11 |
+
<i class="fas fa-info-circle"></i> About Data2Model
|
| 12 |
+
</h1>
|
| 13 |
+
<p class="lead">Democratizing Machine Learning Through Automation</p>
|
| 14 |
+
</div>
|
| 15 |
+
|
| 16 |
+
<!-- Project Overview -->
|
| 17 |
+
<div class="card shadow mb-4">
|
| 18 |
+
<div class="card-header bg-primary text-white">
|
| 19 |
+
<h4 class="mb-0">Project Overview</h4>
|
| 20 |
+
</div>
|
| 21 |
+
<div class="card-body">
|
| 22 |
+
<p>
|
| 23 |
+
<strong>Data2Model</strong> is a comprehensive web-based automated machine learning platform
|
| 24 |
+
designed to democratize AI and make machine learning accessible to everyone. The platform enables
|
| 25 |
+
users to transform raw data into powerful predictive models without requiring
|
| 26 |
+
extensive programming knowledge or data science expertise.
|
| 27 |
+
</p>
|
| 28 |
+
<p>
|
| 29 |
+
Our platform supports multiple ML paradigms including supervised learning (classification and regression),
|
| 30 |
+
unsupervised learning (clustering and dimensionality reduction), and association rule learning.
|
| 31 |
+
With advanced features like automatic encoding, intelligent scaling, and validation set handling for large datasets,
|
| 32 |
+
Data2Model ensures optimal performance across diverse use cases.
|
| 33 |
+
</p>
|
| 34 |
+
<p>
|
| 35 |
+
Built with cutting-edge technologies including XGBoost, LightGBM, and scikit-learn,
|
| 36 |
+
this platform demonstrates the practical application of software development,
|
| 37 |
+
machine learning, and cloud computing concepts in solving real-world problems.
|
| 38 |
+
</p>
|
| 39 |
+
</div>
|
| 40 |
+
</div>
|
| 41 |
+
|
| 42 |
+
<!-- Objectives -->
|
| 43 |
+
<div class="card shadow mb-4">
|
| 44 |
+
<div class="card-header bg-success text-white">
|
| 45 |
+
<h4 class="mb-0">Key Objectives</h4>
|
| 46 |
+
</div>
|
| 47 |
+
<div class="card-body">
|
| 48 |
+
<ul>
|
| 49 |
+
<li>Implement the complete machine learning lifecycle from data collection to deployment</li>
|
| 50 |
+
<li>Automate data validation, cleaning, scaling, and feature processing</li>
|
| 51 |
+
<li>Support multiple problem types: classification, regression, clustering, dimensionality reduction, and association</li>
|
| 52 |
+
<li>Provide advanced encoding methods: One-Hot, Label, Ordinal, Target, and Binary</li>
|
| 53 |
+
<li>Integrate state-of-the-art algorithms including XGBoost and LightGBM</li>
|
| 54 |
+
<li>Handle large datasets with intelligent train-test-validation splitting (60/20/20)</li>
|
| 55 |
+
<li>Provide a simple, user-friendly interface accessible without registration</li>
|
| 56 |
+
<li>Enable model download for future prediction tasks</li>
|
| 57 |
+
<li>Support unlimited file sizes for enterprise-scale datasets</li>
|
| 58 |
+
<li>Deploy on cloud platform for accessibility and scalability</li>
|
| 59 |
+
</ul>
|
| 60 |
+
</div>
|
| 61 |
+
</div>
|
| 62 |
+
|
| 63 |
+
<!-- Technical Stack -->
|
| 64 |
+
<div class="card shadow mb-4">
|
| 65 |
+
<div class="card-header bg-info text-white">
|
| 66 |
+
<h4 class="mb-0">Technical Stack</h4>
|
| 67 |
+
</div>
|
| 68 |
+
<div class="card-body">
|
| 69 |
+
<div class="row">
|
| 70 |
+
<div class="col-md-6">
|
| 71 |
+
<h5>Backend</h5>
|
| 72 |
+
<ul class="list-unstyled">
|
| 73 |
+
<li><i class="fab fa-python text-primary"></i> <strong>Python 3.8+</strong></li>
|
| 74 |
+
<li><i class="fas fa-flask text-dark"></i> <strong>Flask</strong> - Web Framework</li>
|
| 75 |
+
<li><i class="fas fa-robot text-success"></i> <strong>Scikit-learn</strong> - ML Library</li>
|
| 76 |
+
<li><i class="fas fa-table text-info"></i> <strong>Pandas</strong> - Data Processing</li>
|
| 77 |
+
<li><i class="fas fa-calculator text-warning"></i> <strong>NumPy</strong> - Numerical Computing</li>
|
| 78 |
+
</ul>
|
| 79 |
+
</div>
|
| 80 |
+
<div class="col-md-6">
|
| 81 |
+
<h5>Frontend</h5>
|
| 82 |
+
<ul class="list-unstyled">
|
| 83 |
+
<li><i class="fab fa-html5 text-danger"></i> <strong>HTML5</strong></li>
|
| 84 |
+
<li><i class="fab fa-css3-alt text-primary"></i> <strong>CSS3</strong></li>
|
| 85 |
+
<li><i class="fab fa-js text-warning"></i> <strong>JavaScript</strong></li>
|
| 86 |
+
<li><i class="fab fa-bootstrap text-purple"></i> <strong>Bootstrap 5</strong></li>
|
| 87 |
+
<li><i class="fas fa-icons text-info"></i> <strong>Font Awesome</strong></li>
|
| 88 |
+
</ul>
|
| 89 |
+
</div>
|
| 90 |
+
</div>
|
| 91 |
+
</div>
|
| 92 |
+
</div>
|
| 93 |
+
|
| 94 |
+
<!-- Features -->
|
| 95 |
+
<div class="card shadow mb-4">
|
| 96 |
+
<div class="card-header bg-warning text-dark">
|
| 97 |
+
<h4 class="mb-0">Core Features</h4>
|
| 98 |
+
</div>
|
| 99 |
+
<div class="card-body">
|
| 100 |
+
<div class="row">
|
| 101 |
+
<div class="col-md-6">
|
| 102 |
+
<h5>Data Processing</h5>
|
| 103 |
+
<ul>
|
| 104 |
+
<li>Automatic missing value handling</li>
|
| 105 |
+
<li>Duplicate detection and removal</li>
|
| 106 |
+
<li>Feature encoding (One-Hot, Label)</li>
|
| 107 |
+
<li>Feature scaling (Standard, MinMax, Robust)</li>
|
| 108 |
+
<li>Train-test split automation</li>
|
| 109 |
+
</ul>
|
| 110 |
+
</div>
|
| 111 |
+
<div class="col-md-6">
|
| 112 |
+
<h5>Model Training</h5>
|
| 113 |
+
<ul>
|
| 114 |
+
<li>Multiple algorithm support</li>
|
| 115 |
+
<li>Automatic algorithm comparison</li>
|
| 116 |
+
<li>Best model selection</li>
|
| 117 |
+
<li>Comprehensive evaluation metrics</li>
|
| 118 |
+
<li>Model persistence and download</li>
|
| 119 |
+
</ul>
|
| 120 |
+
</div>
|
| 121 |
+
</div>
|
| 122 |
+
</div>
|
| 123 |
+
</div>
|
| 124 |
+
|
| 125 |
+
<!-- Supported Algorithms -->
|
| 126 |
+
<div class="card shadow mb-4">
|
| 127 |
+
<div class="card-header bg-dark text-white">
|
| 128 |
+
<h4 class="mb-0">Supported Algorithms</h4>
|
| 129 |
+
</div>
|
| 130 |
+
<div class="card-body">
|
| 131 |
+
<div class="row">
|
| 132 |
+
<div class="col-md-6">
|
| 133 |
+
<h6 class="text-success">Classification</h6>
|
| 134 |
+
<ul class="small">
|
| 135 |
+
<li>Logistic Regression</li>
|
| 136 |
+
<li>Random Forest Classifier</li>
|
| 137 |
+
<li>Gradient Boosting Classifier</li>
|
| 138 |
+
<li>Decision Tree Classifier</li>
|
| 139 |
+
<li>K-Nearest Neighbors</li>
|
| 140 |
+
<li>Naive Bayes</li>
|
| 141 |
+
<li>Support Vector Machine</li>
|
| 142 |
+
<li>AdaBoost Classifier</li>
|
| 143 |
+
</ul>
|
| 144 |
+
</div>
|
| 145 |
+
<div class="col-md-6">
|
| 146 |
+
<h6 class="text-primary">Regression</h6>
|
| 147 |
+
<ul class="small">
|
| 148 |
+
<li>Linear Regression</li>
|
| 149 |
+
<li>Random Forest Regressor</li>
|
| 150 |
+
<li>Gradient Boosting Regressor</li>
|
| 151 |
+
<li>XGBoost Regressor</li>
|
| 152 |
+
<li>LightGBM Regressor</li>
|
| 153 |
+
<li>Decision Tree Regressor</li>
|
| 154 |
+
<li>K-Nearest Neighbors Regressor</li>
|
| 155 |
+
<li>Support Vector Regression (SVR)</li>
|
| 156 |
+
<li>AdaBoost Regressor</li>
|
| 157 |
+
</ul>
|
| 158 |
+
</div>
|
| 159 |
+
</div>
|
| 160 |
+
</div>
|
| 161 |
+
</div>
|
| 162 |
+
|
| 163 |
+
<!-- Use Cases -->
|
| 164 |
+
<div class="card shadow mb-4">
|
| 165 |
+
<div class="card-header bg-secondary text-white">
|
| 166 |
+
<h4 class="mb-0">Use Cases</h4>
|
| 167 |
+
</div>
|
| 168 |
+
<div class="card-body">
|
| 169 |
+
<div class="row">
|
| 170 |
+
<div class="col-md-4 mb-3">
|
| 171 |
+
<div class="text-center">
|
| 172 |
+
<i class="fas fa-graduation-cap fa-3x text-primary mb-2"></i>
|
| 173 |
+
<h6>Education</h6>
|
| 174 |
+
<p class="small text-muted">
|
| 175 |
+
Students learning ML concepts without complex coding
|
| 176 |
+
</p>
|
| 177 |
+
</div>
|
| 178 |
+
</div>
|
| 179 |
+
<div class="col-md-4 mb-3">
|
| 180 |
+
<div class="text-center">
|
| 181 |
+
<i class="fas fa-chart-bar fa-3x text-success mb-2"></i>
|
| 182 |
+
<h6>Business Analytics</h6>
|
| 183 |
+
<p class="small text-muted">
|
| 184 |
+
Quick predictive insights for decision making
|
| 185 |
+
</p>
|
| 186 |
+
</div>
|
| 187 |
+
</div>
|
| 188 |
+
<div class="col-md-4 mb-3">
|
| 189 |
+
<div class="text-center">
|
| 190 |
+
<i class="fas fa-flask fa-3x text-warning mb-2"></i>
|
| 191 |
+
<h6>Research</h6>
|
| 192 |
+
<p class="small text-muted">
|
| 193 |
+
Rapid prototyping and model testing
|
| 194 |
+
</p>
|
| 195 |
+
</div>
|
| 196 |
+
</div>
|
| 197 |
+
</div>
|
| 198 |
+
</div>
|
| 199 |
+
</div>
|
| 200 |
+
|
| 201 |
+
<!-- Contact -->
|
| 202 |
+
<div class="card shadow">
|
| 203 |
+
<div class="card-body text-center">
|
| 204 |
+
<h5>Get in Touch</h5>
|
| 205 |
+
<p style="color: #2d3748; font-size: 1.1rem;">
|
| 206 |
+
<i class="fas fa-envelope"></i> support@data2model.in |
|
| 207 |
+
<i class="fas fa-envelope"></i> info@data2model.in
|
| 208 |
+
</p>
|
| 209 |
+
<div class="mt-3">
|
| 210 |
+
<a href="{{ url_for('feedback') }}" class="btn btn-primary">
|
| 211 |
+
<i class="fas fa-comment"></i> Send Feedback
|
| 212 |
+
</a>
|
| 213 |
+
</div>
|
| 214 |
+
</div>
|
| 215 |
+
</div>
|
| 216 |
+
</div>
|
| 217 |
+
</div>
|
| 218 |
+
</div>
|
| 219 |
+
{% endblock %}
|
templates/base.html
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>{% block title %}Data2Model - Automated ML Platform{% endblock %}</title>
|
| 7 |
+
|
| 8 |
+
<!-- Bootstrap CSS -->
|
| 9 |
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
| 10 |
+
|
| 11 |
+
<!-- Font Awesome -->
|
| 12 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 13 |
+
|
| 14 |
+
<!-- Custom CSS -->
|
| 15 |
+
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
|
| 16 |
+
|
| 17 |
+
{% block extra_css %}{% endblock %}
|
| 18 |
+
</head>
|
| 19 |
+
<body>
|
| 20 |
+
<!-- Navigation -->
|
| 21 |
+
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
|
| 22 |
+
<div class="container">
|
| 23 |
+
<a class="navbar-brand" href="{{ url_for('index') }}">
|
| 24 |
+
<i class="fas fa-robot"></i> Data2Model
|
| 25 |
+
</a>
|
| 26 |
+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
| 27 |
+
<span class="navbar-toggler-icon"></span>
|
| 28 |
+
</button>
|
| 29 |
+
<div class="collapse navbar-collapse" id="navbarNav">
|
| 30 |
+
<ul class="navbar-nav ms-auto">
|
| 31 |
+
<li class="nav-item">
|
| 32 |
+
<a class="nav-link" href="{{ url_for('index') }}">
|
| 33 |
+
<i class="fas fa-home"></i> Home
|
| 34 |
+
</a>
|
| 35 |
+
</li>
|
| 36 |
+
<li class="nav-item">
|
| 37 |
+
{% if predict_unlocked %}
|
| 38 |
+
<a class="nav-link text-success fw-bold" href="{{ url_for('predict') }}">
|
| 39 |
+
<i class="fas fa-chart-line"></i> Predict
|
| 40 |
+
<span class="badge bg-success ms-1" style="font-size:0.65rem;">READY</span>
|
| 41 |
+
</a>
|
| 42 |
+
{% else %}
|
| 43 |
+
<a class="nav-link text-white-50" href="{{ url_for('predict') }}"
|
| 44 |
+
title="Train a model with Train/Test/Validation split to unlock">
|
| 45 |
+
<i class="fas fa-lock"></i> Predict
|
| 46 |
+
<span class="badge bg-secondary ms-1" style="font-size:0.65rem;">LOCKED</span>
|
| 47 |
+
</a>
|
| 48 |
+
{% endif %}
|
| 49 |
+
</li>
|
| 50 |
+
<li class="nav-item">
|
| 51 |
+
<a class="nav-link" href="{{ url_for('about') }}">
|
| 52 |
+
<i class="fas fa-info-circle"></i> About
|
| 53 |
+
</a>
|
| 54 |
+
</li>
|
| 55 |
+
<li class="nav-item">
|
| 56 |
+
<a class="nav-link" href="{{ url_for('documentation') }}">
|
| 57 |
+
<i class="fas fa-book"></i> Docs
|
| 58 |
+
</a>
|
| 59 |
+
</li>
|
| 60 |
+
<li class="nav-item">
|
| 61 |
+
<a class="nav-link" href="{{ url_for('feedback') }}">
|
| 62 |
+
<i class="fas fa-comment"></i> Feedback
|
| 63 |
+
</a>
|
| 64 |
+
</li>
|
| 65 |
+
</ul>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
</nav>
|
| 69 |
+
|
| 70 |
+
<!-- Flash Messages -->
|
| 71 |
+
{% with messages = get_flashed_messages(with_categories=true) %}
|
| 72 |
+
{% if messages %}
|
| 73 |
+
<div class="container mt-3">
|
| 74 |
+
{% for category, message in messages %}
|
| 75 |
+
<div class="alert alert-{{ 'danger' if category == 'error' else category }} alert-dismissible fade show" role="alert">
|
| 76 |
+
{{ message }}
|
| 77 |
+
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
| 78 |
+
</div>
|
| 79 |
+
{% endfor %}
|
| 80 |
+
</div>
|
| 81 |
+
{% endif %}
|
| 82 |
+
{% endwith %}
|
| 83 |
+
|
| 84 |
+
<!-- Main Content -->
|
| 85 |
+
<main>
|
| 86 |
+
{% block content %}{% endblock %}
|
| 87 |
+
</main>
|
| 88 |
+
|
| 89 |
+
<!-- Footer -->
|
| 90 |
+
<footer class="bg-dark text-white mt-5 py-4">
|
| 91 |
+
<div class="container text-center">
|
| 92 |
+
<p class="mb-0">
|
| 93 |
+
© 2026 Data2Model | Automated Machine Learning Platform
|
| 94 |
+
</p>
|
| 95 |
+
<p class="mb-0">
|
| 96 |
+
<small>Developed with <i class="fas fa-heart text-danger"></i> by Nausad & Deepak</small>
|
| 97 |
+
</p>
|
| 98 |
+
</div>
|
| 99 |
+
</footer>
|
| 100 |
+
|
| 101 |
+
<!-- Bootstrap JS -->
|
| 102 |
+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
| 103 |
+
|
| 104 |
+
<!-- Custom JS -->
|
| 105 |
+
<script src="{{ url_for('static', filename='js/script.js') }}"></script>
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
{% block title %}Configure Model - Data2Model{% endblock %}
|
| 3 |
+
|
| 4 |
+
{% block content %}
|
| 5 |
+
<div class="container my-5">
|
| 6 |
+
<div class="row">
|
| 7 |
+
<div class="col-lg-9 mx-auto">
|
| 8 |
+
|
| 9 |
+
<!-- Dataset Summary -->
|
| 10 |
+
<div class="card shadow mb-4">
|
| 11 |
+
<div class="card-header bg-info text-white">
|
| 12 |
+
<h5 class="mb-0"><i class="fas fa-database"></i> Dataset Summary β {{ data.filename }}</h5>
|
| 13 |
+
</div>
|
| 14 |
+
<div class="card-body">
|
| 15 |
+
<div class="row text-center">
|
| 16 |
+
<div class="col-6 col-md-3 mb-2">
|
| 17 |
+
<div class="stat-box"><span class="stat-num">{{ data.analysis.shape[0] }}</span><br><small>Rows</small></div>
|
| 18 |
+
</div>
|
| 19 |
+
<div class="col-6 col-md-3 mb-2">
|
| 20 |
+
<div class="stat-box"><span class="stat-num">{{ data.analysis.shape[1] }}</span><br><small>Columns</small></div>
|
| 21 |
+
</div>
|
| 22 |
+
<div class="col-6 col-md-3 mb-2">
|
| 23 |
+
<div class="stat-box text-primary"><span class="stat-num">{{ data.analysis.numeric_columns|length }}</span><br><small>Numeric</small></div>
|
| 24 |
+
</div>
|
| 25 |
+
<div class="col-6 col-md-3 mb-2">
|
| 26 |
+
<div class="stat-box text-warning"><span class="stat-num">{{ data.analysis.categorical_columns|length }}</span><br><small>Categorical</small></div>
|
| 27 |
+
</div>
|
| 28 |
+
</div>
|
| 29 |
+
|
| 30 |
+
<!-- Column Type Overview (FIX 8) -->
|
| 31 |
+
<div class="mt-3">
|
| 32 |
+
<strong>Detected Column Types:</strong>
|
| 33 |
+
<div class="mt-2 d-flex flex-wrap gap-2">
|
| 34 |
+
{% for col in data.analysis.columns %}
|
| 35 |
+
{% if col in data.analysis.categorical_columns %}
|
| 36 |
+
<span class="badge bg-warning text-dark"><i class="fas fa-tag"></i> {{ col }} (cat)</span>
|
| 37 |
+
{% else %}
|
| 38 |
+
<span class="badge bg-primary"><i class="fas fa-hashtag"></i> {{ col }} (num)</span>
|
| 39 |
+
{% endif %}
|
| 40 |
+
{% endfor %}
|
| 41 |
+
</div>
|
| 42 |
+
<small class="text-muted mt-1 d-block">
|
| 43 |
+
Blue = numeric, Yellow = categorical. You can override below.
|
| 44 |
+
</small>
|
| 45 |
+
</div>
|
| 46 |
+
|
| 47 |
+
{% if data.analysis.duplicates > 0 %}
|
| 48 |
+
<div class="alert alert-secondary mt-3 mb-0 py-2">
|
| 49 |
+
<i class="fas fa-copy"></i> {{ data.analysis.duplicates }} duplicate rows will be removed automatically.
|
| 50 |
+
</div>
|
| 51 |
+
{% endif %}
|
| 52 |
+
</div>
|
| 53 |
+
</div>
|
| 54 |
+
|
| 55 |
+
<!-- βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
|
| 56 |
+
<!-- DASHBOARD: DATA VISUALIZATIONS -->
|
| 57 |
+
<!-- βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
|
| 58 |
+
{% if data.viz_plots %}
|
| 59 |
+
<div class="card shadow mb-4 border-info">
|
| 60 |
+
<div class="card-header bg-info text-white d-flex justify-content-between align-items-center">
|
| 61 |
+
<h5 class="mb-0"><i class="fas fa-chart-bar"></i> Data Dashboard</h5>
|
| 62 |
+
<button class="btn btn-sm btn-light" type="button" data-bs-toggle="collapse" data-bs-target="#dashboardCollapse" aria-expanded="true" aria-controls="dashboardCollapse">
|
| 63 |
+
Toggle Dashboard
|
| 64 |
+
</button>
|
| 65 |
+
</div>
|
| 66 |
+
<div id="dashboardCollapse" class="collapse show">
|
| 67 |
+
<div class="card-body bg-light">
|
| 68 |
+
<!-- Overview & Correlation -->
|
| 69 |
+
<div class="row mb-4">
|
| 70 |
+
<div class="col-md-6 mb-3">
|
| 71 |
+
{% if data.viz_plots.data_quality %}
|
| 72 |
+
<img src="{{ data.viz_plots.data_quality }}" class="img-fluid rounded shadow-sm w-100" alt="Data Quality">
|
| 73 |
+
{% endif %}
|
| 74 |
+
</div>
|
| 75 |
+
<div class="col-md-6 mb-3">
|
| 76 |
+
{% if data.viz_plots.correlation_heatmap %}
|
| 77 |
+
<img src="{{ data.viz_plots.correlation_heatmap }}" class="img-fluid rounded shadow-sm w-100" alt="Correlation Heatmap">
|
| 78 |
+
{% else %}
|
| 79 |
+
<div class="alert alert-secondary h-100 d-flex align-items-center justify-content-center">
|
| 80 |
+
Not enough numeric columns for correlation heatmap.
|
| 81 |
+
</div>
|
| 82 |
+
{% endif %}
|
| 83 |
+
</div>
|
| 84 |
+
</div>
|
| 85 |
+
|
| 86 |
+
<!-- Distributions -->
|
| 87 |
+
<div class="row">
|
| 88 |
+
<div class="col-12 mb-4">
|
| 89 |
+
{% if data.viz_plots.numeric_histograms %}
|
| 90 |
+
<img src="{{ data.viz_plots.numeric_histograms }}" class="img-fluid rounded shadow-sm w-100" alt="Numeric Histograms">
|
| 91 |
+
{% endif %}
|
| 92 |
+
</div>
|
| 93 |
+
<div class="col-12 mb-4">
|
| 94 |
+
{% if data.viz_plots.categorical_distributions %}
|
| 95 |
+
<img src="{{ data.viz_plots.categorical_distributions }}" class="img-fluid rounded shadow-sm w-100" alt="Categorical Distributions">
|
| 96 |
+
{% endif %}
|
| 97 |
+
</div>
|
| 98 |
+
</div>
|
| 99 |
+
</div>
|
| 100 |
+
</div>
|
| 101 |
+
</div>
|
| 102 |
+
{% endif %}
|
| 103 |
+
|
| 104 |
+
<!-- Main Form -->
|
| 105 |
+
<form action="{{ url_for('train_model') }}" method="post" id="configForm">
|
| 106 |
+
<input type="hidden" name="filepath" value="{{ data.filepath }}">
|
| 107 |
+
<input type="hidden" name="file_type" value="{{ data.file_type }}">
|
| 108 |
+
|
| 109 |
+
<!-- βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
|
| 110 |
+
<!-- SECTION 1: NULL VALUE HANDLING (FIX 1 & 2) -->
|
| 111 |
+
<!-- βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
|
| 112 |
+
{% if data.analysis.missing_values %}
|
| 113 |
+
<div class="card shadow mb-4 border-warning">
|
| 114 |
+
<div class="card-header bg-warning text-dark">
|
| 115 |
+
<h5 class="mb-0"><i class="fas fa-exclamation-triangle"></i> Null Value Imputation</h5>
|
| 116 |
+
</div>
|
| 117 |
+
<div class="card-body">
|
| 118 |
+
<p class="text-muted mb-3">
|
| 119 |
+
Configure how missing values are handled for each feature.
|
| 120 |
+
<strong>Statistical imputation is highly recommended</strong> to prevent unnecessary data loss compared to deleting records.
|
| 121 |
+
</p>
|
| 122 |
+
<div class="table-responsive">
|
| 123 |
+
<table class="table table-bordered table-sm align-middle">
|
| 124 |
+
<thead class="table-light">
|
| 125 |
+
<tr>
|
| 126 |
+
<th>Column</th>
|
| 127 |
+
<th>Missing Count</th>
|
| 128 |
+
<th>Type</th>
|
| 129 |
+
<th>Imputation Strategy</th>
|
| 130 |
+
</tr>
|
| 131 |
+
</thead>
|
| 132 |
+
<tbody>
|
| 133 |
+
{% for col in data.analysis.columns %}
|
| 134 |
+
{% set count = data.analysis.missing_values.get(col, 0) %}
|
| 135 |
+
{% if count > 0 %}
|
| 136 |
+
<tr class="imputation-row" data-column="{{ col }}">
|
| 137 |
+
<td><strong>{{ col }}</strong></td>
|
| 138 |
+
<td>
|
| 139 |
+
<span class="badge bg-danger">{{ count }} missing</span>
|
| 140 |
+
</td>
|
| 141 |
+
<td class="col-type-td">
|
| 142 |
+
{% if col in data.analysis.categorical_columns %}
|
| 143 |
+
<span class="badge bg-warning text-dark">Categorical</span>
|
| 144 |
+
{% else %}
|
| 145 |
+
<span class="badge bg-primary">Numeric</span>
|
| 146 |
+
{% endif %}
|
| 147 |
+
</td>
|
| 148 |
+
<td>
|
| 149 |
+
<div class="d-flex flex-column gap-1">
|
| 150 |
+
<select class="form-select form-select-sm imputation-select" name="null_{{ col }}" onchange="toggleCustomInput(this, 'custom_input_{{ loop.index }}')">
|
| 151 |
+
{% if col in data.analysis.categorical_columns %}
|
| 152 |
+
<option value="auto" selected>Auto (smart mode)</option>
|
| 153 |
+
<option value="mode">Mode (most frequent) β Recommended</option>
|
| 154 |
+
<option value="zero">Fill with 'Unknown'</option>
|
| 155 |
+
<option value="custom">Custom Constant...</option>
|
| 156 |
+
<option value="drop">Delete rows with missing</option>
|
| 157 |
+
{% else %}
|
| 158 |
+
<option value="auto" selected>Auto (smart median)</option>
|
| 159 |
+
<option value="median">Median β Recommended</option>
|
| 160 |
+
<option value="mean">Mean</option>
|
| 161 |
+
<option value="mode">Mode</option>
|
| 162 |
+
<option value="zero">Fill with 0</option>
|
| 163 |
+
<option value="custom">Custom Constant...</option>
|
| 164 |
+
<option value="drop">Delete rows with missing</option>
|
| 165 |
+
{% endif %}
|
| 166 |
+
</select>
|
| 167 |
+
<input type="text" class="form-control form-control-sm mt-1 custom-impute-val" name="null_custom_{{ col }}" id="custom_input_{{ loop.index }}" style="display:none;" placeholder="Enter custom value...">
|
| 168 |
+
</div>
|
| 169 |
+
</td>
|
| 170 |
+
</tr>
|
| 171 |
+
{% endif %}
|
| 172 |
+
{% endfor %}
|
| 173 |
+
</tbody>
|
| 174 |
+
</table>
|
| 175 |
+
</div>
|
| 176 |
+
</div>
|
| 177 |
+
</div>
|
| 178 |
+
{% endif %}
|
| 179 |
+
|
| 180 |
+
<!-- βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
|
| 181 |
+
<!-- SECTION 2: DATA TYPE OVERRIDE (FIX 8) -->
|
| 182 |
+
<!-- βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
|
| 183 |
+
{% if data.analysis.numeric_columns %}
|
| 184 |
+
<div class="card shadow mb-4">
|
| 185 |
+
<div class="card-header bg-secondary text-white">
|
| 186 |
+
<h5 class="mb-0"><i class="fas fa-exchange-alt"></i> Data Type Override <small class="fw-normal">(optional)</small></h5>
|
| 187 |
+
</div>
|
| 188 |
+
<div class="card-body">
|
| 189 |
+
<p class="text-muted mb-3">
|
| 190 |
+
Numeric columns detected below. If any column is actually a <strong>category / product code / identifier</strong> (e.g. ID, category numbers), tick the box so it gets correctly treated as a categorical column rather than scaled as a continuous value.
|
| 191 |
+
</p>
|
| 192 |
+
<div class="row">
|
| 193 |
+
{% for col in data.analysis.numeric_columns %}
|
| 194 |
+
<div class="col-md-4 col-sm-6 mb-2">
|
| 195 |
+
<div class="form-check">
|
| 196 |
+
<input class="form-check-input override-checkbox" type="checkbox" name="cat_override" value="{{ col }}" id="co_{{ loop.index }}">
|
| 197 |
+
<label class="form-check-label" for="co_{{ loop.index }}">
|
| 198 |
+
<span class="badge bg-primary me-1">num</span> {{ col }}
|
| 199 |
+
<small class="text-muted">({{ data.analysis.col_stats[col].unique }} unique)</small>
|
| 200 |
+
</label>
|
| 201 |
+
</div>
|
| 202 |
+
</div>
|
| 203 |
+
{% endfor %}
|
| 204 |
+
</div>
|
| 205 |
+
</div>
|
| 206 |
+
</div>
|
| 207 |
+
{% endif %}
|
| 208 |
+
|
| 209 |
+
<!-- βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
|
| 210 |
+
<!-- SECTION 2.5: DELETE COLUMNS FEATURE -->
|
| 211 |
+
<!-- βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
|
| 212 |
+
<div class="card shadow mb-4 border-danger">
|
| 213 |
+
<div class="card-header bg-danger text-white">
|
| 214 |
+
<h5 class="mb-0"><i class="fas fa-trash-alt"></i> Drop Columns <small class="fw-normal">(optional)</small></h5>
|
| 215 |
+
</div>
|
| 216 |
+
<div class="card-body">
|
| 217 |
+
<p class="text-muted mb-3">
|
| 218 |
+
Select any columns you want to completely <strong>delete</strong> from the dataset before training. These columns will be ignored.
|
| 219 |
+
</p>
|
| 220 |
+
<div class="row">
|
| 221 |
+
{% for col in data.analysis.columns %}
|
| 222 |
+
<div class="col-md-4 col-sm-6 mb-2">
|
| 223 |
+
<div class="form-check">
|
| 224 |
+
<input class="form-check-input drop-checkbox" type="checkbox" name="drop_columns" value="{{ col }}" id="drop_{{ loop.index }}">
|
| 225 |
+
<label class="form-check-label text-danger" for="drop_{{ loop.index }}">
|
| 226 |
+
{{ col }}
|
| 227 |
+
</label>
|
| 228 |
+
</div>
|
| 229 |
+
</div>
|
| 230 |
+
{% endfor %}
|
| 231 |
+
</div>
|
| 232 |
+
</div>
|
| 233 |
+
</div>
|
| 234 |
+
|
| 235 |
+
<!-- βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
|
| 236 |
+
<!-- SECTION 3: PROBLEM CONFIGURATION (FIX 3) -->
|
| 237 |
+
<!-- βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
|
| 238 |
+
<div class="card shadow mb-4">
|
| 239 |
+
<div class="card-header bg-primary text-white">
|
| 240 |
+
<h5 class="mb-0"><i class="fas fa-cog"></i> Problem Configuration</h5>
|
| 241 |
+
</div>
|
| 242 |
+
<div class="card-body">
|
| 243 |
+
|
| 244 |
+
<!-- Problem Type (FIX 3) -->
|
| 245 |
+
<div class="mb-3">
|
| 246 |
+
<label class="form-label fw-bold">Problem Type</label>
|
| 247 |
+
<select class="form-select" id="problem_type" name="problem_type">
|
| 248 |
+
<option value="auto" selected>Auto Detect</option>
|
| 249 |
+
<option value="classification">Classification (predict a category)</option>
|
| 250 |
+
<option value="regression">Regression (predict a number)</option>
|
| 251 |
+
<option value="clustering">Clustering β Unsupervised</option>
|
| 252 |
+
<option value="dimensionality_reduction">Dimensionality Reduction β Unsupervised</option>
|
| 253 |
+
<option value="association">Association β Unsupervised</option>
|
| 254 |
+
</select>
|
| 255 |
+
</div>
|
| 256 |
+
|
| 257 |
+
<!-- Target Column β hidden for unsupervised (FIX 3) -->
|
| 258 |
+
<div class="mb-3" id="target_col_section">
|
| 259 |
+
<label class="form-label fw-bold">
|
| 260 |
+
Target Column <span class="text-danger">*</span>
|
| 261 |
+
</label>
|
| 262 |
+
<select class="form-select" id="target_column" name="target_column">
|
| 263 |
+
<option value="">β Select Target Column β</option>
|
| 264 |
+
{% for col in data.analysis.columns %}
|
| 265 |
+
<option value="{{ col }}">{{ col }}</option>
|
| 266 |
+
{% endfor %}
|
| 267 |
+
</select>
|
| 268 |
+
<div class="form-text">The column you want to predict</div>
|
| 269 |
+
</div>
|
| 270 |
+
|
| 271 |
+
<!-- Split Type (FIX 4) -->
|
| 272 |
+
<div class="mb-3" id="split_section">
|
| 273 |
+
<label class="form-label fw-bold">Data Split Strategy</label>
|
| 274 |
+
<div class="row g-2">
|
| 275 |
+
<div class="col-md-6">
|
| 276 |
+
<div class="form-check card p-3 border split-card" id="card_tt">
|
| 277 |
+
<input class="form-check-input" type="radio" name="split_type" value="train_test"
|
| 278 |
+
id="split_tt" checked>
|
| 279 |
+
<label class="form-check-label w-100" for="split_tt">
|
| 280 |
+
<strong>Train / Test Split</strong>
|
| 281 |
+
<div class="text-muted small mt-1">Standard evaluation.<br>e.g. 80% train, 20% test</div>
|
| 282 |
+
</label>
|
| 283 |
+
</div>
|
| 284 |
+
</div>
|
| 285 |
+
<div class="col-md-6">
|
| 286 |
+
<div class="form-check card p-3 border split-card" id="card_ttv">
|
| 287 |
+
<input class="form-check-input" type="radio" name="split_type" value="train_test_val"
|
| 288 |
+
id="split_ttv">
|
| 289 |
+
<label class="form-check-label w-100" for="split_ttv">
|
| 290 |
+
<strong>Train / Test / Validation Split</strong>
|
| 291 |
+
<div class="text-muted small mt-1">Better model tuning.<br>e.g. 60% / 20% / 20%</div>
|
| 292 |
+
</label>
|
| 293 |
+
</div>
|
| 294 |
+
</div>
|
| 295 |
+
</div>
|
| 296 |
+
</div>
|
| 297 |
+
|
| 298 |
+
<!-- Split sizes -->
|
| 299 |
+
<div class="row g-3" id="split_sizes">
|
| 300 |
+
<div class="col-md-6" id="test_size_box">
|
| 301 |
+
<label class="form-label fw-bold">Test Set Size</label>
|
| 302 |
+
<select class="form-select" name="test_size">
|
| 303 |
+
<option value="0.2" selected>20% (Recommended)</option>
|
| 304 |
+
<option value="0.25">25%</option>
|
| 305 |
+
<option value="0.3">30%</option>
|
| 306 |
+
<option value="0.15">15%</option>
|
| 307 |
+
</select>
|
| 308 |
+
</div>
|
| 309 |
+
<div class="col-md-6" id="val_size_box" style="display:none;">
|
| 310 |
+
<label class="form-label fw-bold">Validation Set Size</label>
|
| 311 |
+
<select class="form-select" name="val_size">
|
| 312 |
+
<option value="0.2" selected>20% (Recommended)</option>
|
| 313 |
+
<option value="0.15">15%</option>
|
| 314 |
+
<option value="0.1">10%</option>
|
| 315 |
+
</select>
|
| 316 |
+
</div>
|
| 317 |
+
</div>
|
| 318 |
+
|
| 319 |
+
</div>
|
| 320 |
+
</div>
|
| 321 |
+
|
| 322 |
+
<!-- βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
|
| 323 |
+
<!-- SECTION 4: PER-COLUMN SCALING (FIX 5 & 6) -->
|
| 324 |
+
<!-- βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
|
| 325 |
+
{% if data.analysis.numeric_columns %}
|
| 326 |
+
<div class="card shadow mb-4" id="numeric_scaling_card">
|
| 327 |
+
<div class="card-header bg-success text-white d-flex justify-content-between align-items-center">
|
| 328 |
+
<h5 class="mb-0"><i class="fas fa-balance-scale"></i> Scaling β Numeric Columns</h5>
|
| 329 |
+
<div>
|
| 330 |
+
<label class="text-white me-2 small">Apply same to all:</label>
|
| 331 |
+
<select class="form-select form-select-sm d-inline-block w-auto" id="globalScaling">
|
| 332 |
+
<option value="">β Pick β</option>
|
| 333 |
+
<option value="standard">Standard</option>
|
| 334 |
+
<option value="minmax">Min-Max</option>
|
| 335 |
+
<option value="robust">Robust</option>
|
| 336 |
+
<option value="normalizer">Normalizer</option>
|
| 337 |
+
<option value="none">None</option>
|
| 338 |
+
</select>
|
| 339 |
+
</div>
|
| 340 |
+
</div>
|
| 341 |
+
<div class="card-body">
|
| 342 |
+
<p class="text-muted small mb-3">
|
| 343 |
+
Choose a scaling method per column. Continuous features are standardly scaled, while categorical overrides will be excluded.
|
| 344 |
+
</p>
|
| 345 |
+
<div class="table-responsive">
|
| 346 |
+
<table class="table table-sm table-bordered align-middle">
|
| 347 |
+
<thead class="table-light">
|
| 348 |
+
<tr><th>Column</th><th>Scaling Method</th></tr>
|
| 349 |
+
</thead>
|
| 350 |
+
<tbody>
|
| 351 |
+
{% for col in data.analysis.numeric_columns %}
|
| 352 |
+
<tr class="scaling-row" data-column="{{ col }}">
|
| 353 |
+
<td><span class="badge bg-primary">num</span> {{ col }}</td>
|
| 354 |
+
<td>
|
| 355 |
+
<select class="form-select form-select-sm scaling-col" name="scale_{{ col }}">
|
| 356 |
+
<option value="standard" selected>Standard (z-score)</option>
|
| 357 |
+
<option value="minmax">Min-Max [0,1]</option>
|
| 358 |
+
<option value="robust">Robust (outlier-safe)</option>
|
| 359 |
+
<option value="normalizer">Normalizer</option>
|
| 360 |
+
<option value="none">No Scaling</option>
|
| 361 |
+
</select>
|
| 362 |
+
</td>
|
| 363 |
+
</tr>
|
| 364 |
+
{% endfor %}
|
| 365 |
+
</tbody>
|
| 366 |
+
</table>
|
| 367 |
+
</div>
|
| 368 |
+
</div>
|
| 369 |
+
</div>
|
| 370 |
+
{% endif %}
|
| 371 |
+
|
| 372 |
+
<!-- βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
|
| 373 |
+
<!-- SECTION 5: PER-COLUMN ENCODING (FIX 5 & 7) -->
|
| 374 |
+
<!-- βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
|
| 375 |
+
<div class="card shadow mb-4" id="categorical_encoding_card" {% if not data.analysis.categorical_columns %}style="display:none;"{% endif %}>
|
| 376 |
+
<div class="card-header bg-warning text-dark d-flex justify-content-between align-items-center">
|
| 377 |
+
<h5 class="mb-0"><i class="fas fa-tags"></i> Encoding β Categorical Columns</h5>
|
| 378 |
+
<div>
|
| 379 |
+
<label class="me-2 small">Apply same to all:</label>
|
| 380 |
+
<select class="form-select form-select-sm d-inline-block w-auto" id="globalEncoding">
|
| 381 |
+
<option value="">β Pick β</option>
|
| 382 |
+
<option value="auto">Auto</option>
|
| 383 |
+
<option value="onehot">One-Hot</option>
|
| 384 |
+
<option value="label">Label</option>
|
| 385 |
+
<option value="ordinal">Ordinal</option>
|
| 386 |
+
<option value="target">Target</option>
|
| 387 |
+
<option value="binary">Binary</option>
|
| 388 |
+
</select>
|
| 389 |
+
</div>
|
| 390 |
+
</div>
|
| 391 |
+
<div class="card-body">
|
| 392 |
+
<p class="text-muted small mb-3">
|
| 393 |
+
Choose an encoding method per column. Each column can use a different method.
|
| 394 |
+
</p>
|
| 395 |
+
<div class="table-responsive">
|
| 396 |
+
<table class="table table-sm table-bordered align-middle">
|
| 397 |
+
<thead class="table-light">
|
| 398 |
+
<tr><th>Column</th><th>Unique Values</th><th>Encoding Method</th></tr>
|
| 399 |
+
</thead>
|
| 400 |
+
<tbody id="encoding_table_body">
|
| 401 |
+
<!-- Regular Categorical Columns -->
|
| 402 |
+
{% for col in data.analysis.categorical_columns %}
|
| 403 |
+
<tr class="encoding-row" data-column="{{ col }}">
|
| 404 |
+
<td><span class="badge bg-warning text-dark">cat</span> {{ col }}</td>
|
| 405 |
+
<td><span class="badge bg-secondary">{{ data.analysis.col_stats[col].unique }}</span></td>
|
| 406 |
+
<td>
|
| 407 |
+
<select class="form-select form-select-sm encoding-col" name="encode_{{ col }}">
|
| 408 |
+
<option value="auto" selected>Auto (smart detect)</option>
|
| 409 |
+
<option value="onehot">One-Hot Encoding</option>
|
| 410 |
+
<option value="label">Label Encoding</option>
|
| 411 |
+
<option value="ordinal">Ordinal Encoding</option>
|
| 412 |
+
<option value="target">Target Encoding</option>
|
| 413 |
+
<option value="binary">Binary (LabelBinarizer)</option>
|
| 414 |
+
</select>
|
| 415 |
+
</td>
|
| 416 |
+
</tr>
|
| 417 |
+
{% endfor %}
|
| 418 |
+
|
| 419 |
+
<!-- Pre-rendered Hidden Overridden Numeric Columns -->
|
| 420 |
+
{% if data.analysis.numeric_columns %}
|
| 421 |
+
{% for col in data.analysis.numeric_columns %}
|
| 422 |
+
<tr class="encoding-row" data-column="{{ col }}" id="enc_row_{{ col }}" style="display:none;">
|
| 423 |
+
<td><span class="badge bg-warning text-dark">cat</span> {{ col }} <span class="badge bg-info text-white">overridden</span></td>
|
| 424 |
+
<td><span class="badge bg-secondary">{{ data.analysis.col_stats[col].unique }}</span></td>
|
| 425 |
+
<td>
|
| 426 |
+
<select class="form-select form-select-sm encoding-col" name="encode_{{ col }}" disabled>
|
| 427 |
+
<option value="auto" selected>Auto (smart detect)</option>
|
| 428 |
+
<option value="onehot">One-Hot Encoding</option>
|
| 429 |
+
<option value="label">Label Encoding</option>
|
| 430 |
+
<option value="ordinal">Ordinal Encoding</option>
|
| 431 |
+
<option value="target">Target Encoding</option>
|
| 432 |
+
<option value="binary">Binary (LabelBinarizer)</option>
|
| 433 |
+
</select>
|
| 434 |
+
</td>
|
| 435 |
+
</tr>
|
| 436 |
+
{% endfor %}
|
| 437 |
+
{% endif %}
|
| 438 |
+
</tbody>
|
| 439 |
+
</table>
|
| 440 |
+
</div>
|
| 441 |
+
</div>
|
| 442 |
+
</div>
|
| 443 |
+
|
| 444 |
+
<!-- Submit -->
|
| 445 |
+
<div class="d-grid gap-2">
|
| 446 |
+
<button type="submit" class="btn btn-primary btn-lg" id="trainBtn">
|
| 447 |
+
<i class="fas fa-play"></i> Start Training
|
| 448 |
+
</button>
|
| 449 |
+
<a href="{{ url_for('index') }}" class="btn btn-outline-secondary">
|
| 450 |
+
<i class="fas fa-arrow-left"></i> Back to Home
|
| 451 |
+
</a>
|
| 452 |
+
</div>
|
| 453 |
+
|
| 454 |
+
</form>
|
| 455 |
+
</div>
|
| 456 |
+
</div>
|
| 457 |
+
</div>
|
| 458 |
+
|
| 459 |
+
<!-- Loading Overlay -->
|
| 460 |
+
<div id="loadingOverlay" style="display:none;">
|
| 461 |
+
<div class="spinner-container">
|
| 462 |
+
<div class="spinner-border text-primary" role="status" style="width:4rem;height:4rem;">
|
| 463 |
+
<span class="visually-hidden">Loading...</span>
|
| 464 |
+
</div>
|
| 465 |
+
<h4 class="mt-3 text-white">Training Models...</h4>
|
| 466 |
+
<p class="text-white-50">Testing all algorithms and selecting the best one</p>
|
| 467 |
+
</div>
|
| 468 |
+
</div>
|
| 469 |
+
|
| 470 |
+
<style>
|
| 471 |
+
.stat-box { background:#f8f9fa; border-radius:8px; padding:12px; }
|
| 472 |
+
.stat-num { font-size:1.8rem; font-weight:700; }
|
| 473 |
+
.split-card { cursor:pointer; transition:border-color .2s; }
|
| 474 |
+
.split-card.active { border-color:#0d6efd !important; background:#f0f5ff; }
|
| 475 |
+
|
| 476 |
+
#loadingOverlay {
|
| 477 |
+
position:fixed; top:0; left:0; width:100%; height:100%;
|
| 478 |
+
background:rgba(0,0,0,0.85); z-index:9999;
|
| 479 |
+
display:flex; align-items:center; justify-content:center;
|
| 480 |
+
}
|
| 481 |
+
.spinner-container { text-align:center; }
|
| 482 |
+
</style>
|
| 483 |
+
|
| 484 |
+
<script>
|
| 485 |
+
// ββ Show loading on form submit ββββββββββββββββββββββββββββββββββββββββββ
|
| 486 |
+
document.getElementById('configForm').addEventListener('submit', function() {
|
| 487 |
+
document.getElementById('loadingOverlay').style.display = 'flex';
|
| 488 |
+
});
|
| 489 |
+
|
| 490 |
+
// ββ Custom Imputation Input toggling ββββββββββββββββββββββββββββββββββββββ
|
| 491 |
+
function toggleCustomInput(selectObj, inputId) {
|
| 492 |
+
const customInput = document.getElementById(inputId);
|
| 493 |
+
if (selectObj.value === 'custom') {
|
| 494 |
+
customInput.style.display = '';
|
| 495 |
+
customInput.required = true;
|
| 496 |
+
} else {
|
| 497 |
+
customInput.style.display = 'none';
|
| 498 |
+
customInput.required = false;
|
| 499 |
+
}
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
// ββ Data Type Override Coordination βββββββββββββββββββββββββββββββββββββββ
|
| 503 |
+
document.querySelectorAll('.override-checkbox').forEach(cb => {
|
| 504 |
+
cb.addEventListener('change', function() {
|
| 505 |
+
const col = this.value;
|
| 506 |
+
const isChecked = this.checked;
|
| 507 |
+
|
| 508 |
+
// Scaling row
|
| 509 |
+
const scaleRow = document.querySelector(`.scaling-row[data-column="${col}"]`);
|
| 510 |
+
if (scaleRow) {
|
| 511 |
+
scaleRow.style.display = isChecked ? 'none' : '';
|
| 512 |
+
scaleRow.querySelector('select').disabled = isChecked;
|
| 513 |
+
}
|
| 514 |
+
|
| 515 |
+
// Encoding row (pre-rendered hidden overridden rows)
|
| 516 |
+
const encodeRow = document.getElementById(`enc_row_${col}`);
|
| 517 |
+
if (encodeRow) {
|
| 518 |
+
encodeRow.style.display = isChecked ? '' : 'none';
|
| 519 |
+
encodeRow.querySelector('select').disabled = !isChecked;
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
// Update target badge and options in Imputation table (display Categorical vs Numeric)
|
| 523 |
+
const imputeRow = document.querySelector(`.imputation-row[data-column="${col}"]`);
|
| 524 |
+
if (imputeRow) {
|
| 525 |
+
const typeTd = imputeRow.querySelector('.col-type-td');
|
| 526 |
+
if (typeTd) {
|
| 527 |
+
if (isChecked) {
|
| 528 |
+
typeTd.innerHTML = '<span class="badge bg-warning text-dark">Categorical (overridden)</span>';
|
| 529 |
+
} else {
|
| 530 |
+
typeTd.innerHTML = '<span class="badge bg-primary">Numeric</span>';
|
| 531 |
+
}
|
| 532 |
+
}
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
// Update categorical encoding card visibility
|
| 536 |
+
updateEncodingCardVisibility();
|
| 537 |
+
|
| 538 |
+
// Re-apply target hiding in case target column was changed or overridden
|
| 539 |
+
hideTargetFromPreprocessing();
|
| 540 |
+
});
|
| 541 |
+
});
|
| 542 |
+
|
| 543 |
+
function updateEncodingCardVisibility() {
|
| 544 |
+
const card = document.getElementById('categorical_encoding_card');
|
| 545 |
+
if (!card) return;
|
| 546 |
+
|
| 547 |
+
// Find visible encoding rows
|
| 548 |
+
const visibleRows = Array.from(card.querySelectorAll('.encoding-row')).filter(row => {
|
| 549 |
+
return row.style.display !== 'none';
|
| 550 |
+
});
|
| 551 |
+
|
| 552 |
+
card.style.display = visibleRows.length > 0 ? '' : 'none';
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
// ββ Toggle Target Column & Splits for Unsupervised ββββββββββββββββββββββββ
|
| 556 |
+
const problemType = document.getElementById('problem_type');
|
| 557 |
+
const targetSec = document.getElementById('target_col_section');
|
| 558 |
+
const splitSec = document.getElementById('split_section');
|
| 559 |
+
const splitSizes = document.getElementById('split_sizes');
|
| 560 |
+
const targetInput = document.getElementById('target_column');
|
| 561 |
+
|
| 562 |
+
const UNSUPERVISED = ['clustering', 'dimensionality_reduction', 'association'];
|
| 563 |
+
|
| 564 |
+
function toggleUnsupervised() {
|
| 565 |
+
const isUnsup = UNSUPERVISED.includes(problemType.value);
|
| 566 |
+
targetSec.style.display = isUnsup ? 'none' : '';
|
| 567 |
+
splitSec.style.display = isUnsup ? 'none' : '';
|
| 568 |
+
splitSizes.style.display = isUnsup ? 'none' : '';
|
| 569 |
+
targetInput.required = !isUnsup;
|
| 570 |
+
|
| 571 |
+
if (isUnsup) {
|
| 572 |
+
targetInput.value = '';
|
| 573 |
+
hideTargetFromPreprocessing();
|
| 574 |
+
}
|
| 575 |
+
}
|
| 576 |
+
|
| 577 |
+
problemType.addEventListener('change', toggleUnsupervised);
|
| 578 |
+
toggleUnsupervised();
|
| 579 |
+
|
| 580 |
+
// ββ Show/hide validation size box βββββββββββββββββββββββββββββββββββββββββ
|
| 581 |
+
document.querySelectorAll('input[name="split_type"]').forEach(radio => {
|
| 582 |
+
radio.addEventListener('change', () => {
|
| 583 |
+
const isVal = document.getElementById('split_ttv').checked;
|
| 584 |
+
document.getElementById('val_size_box').style.display = isVal ? '' : 'none';
|
| 585 |
+
|
| 586 |
+
// highlight selected card
|
| 587 |
+
document.getElementById('card_tt').classList.toggle('active', !isVal);
|
| 588 |
+
document.getElementById('card_ttv').classList.toggle('active', isVal);
|
| 589 |
+
});
|
| 590 |
+
});
|
| 591 |
+
|
| 592 |
+
// ββ Split card click ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 593 |
+
document.querySelectorAll('.split-card').forEach(card => {
|
| 594 |
+
card.addEventListener('click', () => {
|
| 595 |
+
const radio = card.querySelector('input[type="radio"]');
|
| 596 |
+
radio.checked = true;
|
| 597 |
+
radio.dispatchEvent(new Event('change'));
|
| 598 |
+
});
|
| 599 |
+
});
|
| 600 |
+
|
| 601 |
+
// ββ Hide Target Column from Preprocessing Tables ββββββββββββββββββββββββββ
|
| 602 |
+
function hideTargetFromPreprocessing() {
|
| 603 |
+
const targetCol = targetInput.value;
|
| 604 |
+
|
| 605 |
+
// Check if it's dropped
|
| 606 |
+
const isDropped = document.querySelector(`.drop-checkbox[value="${targetCol}"]`)?.checked;
|
| 607 |
+
if (isDropped && targetCol) {
|
| 608 |
+
alert(`You cannot select a dropped column ('${targetCol}') as the Target Column! Please uncheck it in the 'Drop Columns' section or select a different target.`);
|
| 609 |
+
targetInput.value = ''; // Reset target column
|
| 610 |
+
return hideTargetFromPreprocessing(); // Re-run with empty target
|
| 611 |
+
}
|
| 612 |
+
|
| 613 |
+
// Imputation rows
|
| 614 |
+
document.querySelectorAll('.imputation-row').forEach(row => {
|
| 615 |
+
const colName = row.getAttribute('data-column');
|
| 616 |
+
const dropped = document.querySelector(`.drop-checkbox[value="${colName}"]`)?.checked;
|
| 617 |
+
row.style.display = ((targetCol && colName === targetCol) || dropped) ? 'none' : '';
|
| 618 |
+
});
|
| 619 |
+
|
| 620 |
+
// Scaling rows (continuous numeric)
|
| 621 |
+
document.querySelectorAll('.scaling-row').forEach(row => {
|
| 622 |
+
const colName = row.getAttribute('data-column');
|
| 623 |
+
const isOverride = document.querySelector(`.override-checkbox[value="${colName}"]`)?.checked;
|
| 624 |
+
const dropped = document.querySelector(`.drop-checkbox[value="${colName}"]`)?.checked;
|
| 625 |
+
|
| 626 |
+
if (targetCol && colName === targetCol) {
|
| 627 |
+
row.style.display = 'none';
|
| 628 |
+
} else if (isOverride || dropped) {
|
| 629 |
+
row.style.display = 'none'; // Overridden columns are hidden in scaling table
|
| 630 |
+
} else {
|
| 631 |
+
row.style.display = '';
|
| 632 |
+
}
|
| 633 |
+
});
|
| 634 |
+
|
| 635 |
+
// Encoding rows (categorical + overridden numeric)
|
| 636 |
+
document.querySelectorAll('.encoding-row').forEach(row => {
|
| 637 |
+
const colName = row.getAttribute('data-column');
|
| 638 |
+
const isOverride = document.querySelector(`.override-checkbox[value="${colName}"]`)?.checked;
|
| 639 |
+
const dropped = document.querySelector(`.drop-checkbox[value="${colName}"]`)?.checked;
|
| 640 |
+
const isInitiallyCategorical = !document.querySelector(`.override-checkbox[value="${colName}"]`);
|
| 641 |
+
|
| 642 |
+
if ((targetCol && colName === targetCol) || dropped) {
|
| 643 |
+
row.style.display = 'none';
|
| 644 |
+
} else if (isInitiallyCategorical) {
|
| 645 |
+
row.style.display = ''; // Regular categorical column
|
| 646 |
+
} else if (isOverride) {
|
| 647 |
+
row.style.display = ''; // Overridden numeric column is shown
|
| 648 |
+
} else {
|
| 649 |
+
row.style.display = 'none'; // Unchecked numeric column is hidden
|
| 650 |
+
}
|
| 651 |
+
});
|
| 652 |
+
|
| 653 |
+
// Update encoding card visibility
|
| 654 |
+
updateEncodingCardVisibility();
|
| 655 |
+
}
|
| 656 |
+
|
| 657 |
+
// Listen to target column changes
|
| 658 |
+
targetInput.addEventListener('change', hideTargetFromPreprocessing);
|
| 659 |
+
document.querySelectorAll('.drop-checkbox').forEach(cb => {
|
| 660 |
+
cb.addEventListener('change', hideTargetFromPreprocessing);
|
| 661 |
+
});
|
| 662 |
+
hideTargetFromPreprocessing(); // Run on page load
|
| 663 |
+
|
| 664 |
+
// ββ Global selectors ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 665 |
+
document.getElementById('globalScaling')?.addEventListener('change', function() {
|
| 666 |
+
if (!this.value) return;
|
| 667 |
+
document.querySelectorAll('.scaling-col:not([disabled])').forEach(s => s.value = this.value);
|
| 668 |
+
});
|
| 669 |
+
|
| 670 |
+
document.getElementById('globalEncoding')?.addEventListener('change', function() {
|
| 671 |
+
if (!this.value) return;
|
| 672 |
+
document.querySelectorAll('.encoding-col:not([disabled])').forEach(s => s.value = this.value);
|
| 673 |
+
});
|
| 674 |
+
</script>
|
| 675 |
+
{% endblock %}
|
templates/documentation.html
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
|
| 3 |
+
{% block title %}Documentation - Data2Model{% endblock %}
|
| 4 |
+
|
| 5 |
+
{% block content %}
|
| 6 |
+
<div class="container my-5">
|
| 7 |
+
<div class="row">
|
| 8 |
+
<div class="col-lg-10 mx-auto">
|
| 9 |
+
<div class="text-center mb-4">
|
| 10 |
+
<h1 class="display-4">
|
| 11 |
+
<i class="fas fa-book"></i> Documentation
|
| 12 |
+
</h1>
|
| 13 |
+
<p class="lead">Quick guide to using Data2Model</p>
|
| 14 |
+
</div>
|
| 15 |
+
|
| 16 |
+
<!-- Quick Start -->
|
| 17 |
+
<div class="card shadow mb-4">
|
| 18 |
+
<div class="card-header bg-primary text-white">
|
| 19 |
+
<h4 class="mb-0">Getting Started (4 Steps)</h4>
|
| 20 |
+
</div>
|
| 21 |
+
<div class="card-body">
|
| 22 |
+
<ol class="mb-0">
|
| 23 |
+
<li class="mb-2">
|
| 24 |
+
<strong>Upload Dataset</strong> - CSV, Excel, or JSON file
|
| 25 |
+
</li>
|
| 26 |
+
<li class="mb-2">
|
| 27 |
+
<strong>Configure</strong> - Select target column and options
|
| 28 |
+
</li>
|
| 29 |
+
<li class="mb-2">
|
| 30 |
+
<strong>Train</strong> - Click "Start Training" and wait
|
| 31 |
+
</li>
|
| 32 |
+
<li class="mb-2">
|
| 33 |
+
<strong>Download</strong> - Get your trained model
|
| 34 |
+
</li>
|
| 35 |
+
</ol>
|
| 36 |
+
</div>
|
| 37 |
+
</div>
|
| 38 |
+
|
| 39 |
+
<!-- Configuration Options -->
|
| 40 |
+
<div class="card shadow mb-4">
|
| 41 |
+
<div class="card-header bg-info text-white">
|
| 42 |
+
<h4 class="mb-0">Configuration Options</h4>
|
| 43 |
+
</div>
|
| 44 |
+
<div class="card-body">
|
| 45 |
+
<div class="row">
|
| 46 |
+
<div class="col-md-6">
|
| 47 |
+
<h6 class="text-primary">Problem Type</h6>
|
| 48 |
+
<ul class="small mb-3">
|
| 49 |
+
<li><strong>Auto Detect</strong> - Recommended</li>
|
| 50 |
+
<li>Classification - Categorical predictions</li>
|
| 51 |
+
<li>Regression - Numerical predictions</li>
|
| 52 |
+
<li>Clustering - Group similar data</li>
|
| 53 |
+
<li>Dimensionality Reduction</li>
|
| 54 |
+
</ul>
|
| 55 |
+
|
| 56 |
+
<h6 class="text-success">Encoding Methods</h6>
|
| 57 |
+
<ul class="small mb-0">
|
| 58 |
+
<li>Auto (One-Hot/Label)</li>
|
| 59 |
+
<li>One-Hot, Label, Ordinal</li>
|
| 60 |
+
<li>Target, Binary</li>
|
| 61 |
+
</ul>
|
| 62 |
+
</div>
|
| 63 |
+
<div class="col-md-6">
|
| 64 |
+
<h6 class="text-warning">Feature Scaling</h6>
|
| 65 |
+
<ul class="small mb-3">
|
| 66 |
+
<li><strong>Standard</strong> - Recommended</li>
|
| 67 |
+
<li>Min-Max - Scale to [0,1]</li>
|
| 68 |
+
<li>Robust - For outliers</li>
|
| 69 |
+
<li>Normalizer - Unit norm</li>
|
| 70 |
+
</ul>
|
| 71 |
+
|
| 72 |
+
<h6 class="text-info">Test Size</h6>
|
| 73 |
+
<p class="small mb-0">
|
| 74 |
+
β’ 20% - Standard datasets<br>
|
| 75 |
+
β’ Auto 60/20/20 split for large datasets (>100K rows)
|
| 76 |
+
</p>
|
| 77 |
+
</div>
|
| 78 |
+
</div>
|
| 79 |
+
</div>
|
| 80 |
+
</div>
|
| 81 |
+
|
| 82 |
+
<!-- Understanding Results -->
|
| 83 |
+
<div class="card shadow mb-4">
|
| 84 |
+
<div class="card-header bg-success text-white">
|
| 85 |
+
<h4 class="mb-0">Understanding Results</h4>
|
| 86 |
+
</div>
|
| 87 |
+
<div class="card-body">
|
| 88 |
+
<div class="row">
|
| 89 |
+
<div class="col-md-6">
|
| 90 |
+
<h6 class="text-success">Classification Metrics</h6>
|
| 91 |
+
<ul class="small mb-0">
|
| 92 |
+
<li><strong>Accuracy:</strong> Overall correctness (higher is better)</li>
|
| 93 |
+
<li><strong>Precision:</strong> Correct positive predictions</li>
|
| 94 |
+
<li><strong>Recall:</strong> Found all positives</li>
|
| 95 |
+
<li><strong>F1 Score:</strong> Balance of precision & recall</li>
|
| 96 |
+
</ul>
|
| 97 |
+
</div>
|
| 98 |
+
<div class="col-md-6">
|
| 99 |
+
<h6 class="text-primary">Regression Metrics</h6>
|
| 100 |
+
<ul class="small mb-0">
|
| 101 |
+
<li><strong>RΒ² Score:</strong> Variance explained (closer to 1 is better)</li>
|
| 102 |
+
<li><strong>RMSE:</strong> Average error (lower is better)</li>
|
| 103 |
+
<li><strong>MAE:</strong> Absolute error (lower is better)</li>
|
| 104 |
+
<li><strong>MSE:</strong> Squared error (lower is better)</li>
|
| 105 |
+
</ul>
|
| 106 |
+
</div>
|
| 107 |
+
</div>
|
| 108 |
+
</div>
|
| 109 |
+
</div>
|
| 110 |
+
|
| 111 |
+
<!-- Making Predictions -->
|
| 112 |
+
<div class="card shadow mb-4">
|
| 113 |
+
<div class="card-header bg-warning text-dark">
|
| 114 |
+
<h4 class="mb-0">Making Predictions</h4>
|
| 115 |
+
</div>
|
| 116 |
+
<div class="card-body">
|
| 117 |
+
<ol class="mb-3">
|
| 118 |
+
<li>Go to "Predict" page</li>
|
| 119 |
+
<li>Upload new data (same features, no target column)</li>
|
| 120 |
+
<li>Get predictions and download results</li>
|
| 121 |
+
</ol>
|
| 122 |
+
<div class="alert alert-info mb-0">
|
| 123 |
+
<strong>Important:</strong> Prediction data must have the same features as training data!
|
| 124 |
+
</div>
|
| 125 |
+
</div>
|
| 126 |
+
</div>
|
| 127 |
+
|
| 128 |
+
<!-- Using Downloaded Models -->
|
| 129 |
+
<div class="card shadow mb-4">
|
| 130 |
+
<div class="card-header bg-dark text-white">
|
| 131 |
+
<h4 class="mb-0">Using Downloaded Models in Python</h4>
|
| 132 |
+
</div>
|
| 133 |
+
<div class="card-body">
|
| 134 |
+
<pre class="bg-light p-3 mb-0"><code>import pickle
|
| 135 |
+
import pandas as pd
|
| 136 |
+
|
| 137 |
+
# Load model
|
| 138 |
+
with open('model_file.pkl', 'rb') as f:
|
| 139 |
+
model_data = pickle.load(f)
|
| 140 |
+
|
| 141 |
+
model = model_data['model']
|
| 142 |
+
scaler = model_data['scaler']
|
| 143 |
+
|
| 144 |
+
# Load and predict
|
| 145 |
+
X_new = pd.read_csv('new_data.csv')
|
| 146 |
+
if scaler:
|
| 147 |
+
X_new = scaler.transform(X_new)
|
| 148 |
+
predictions = model.predict(X_new)
|
| 149 |
+
print(predictions)</code></pre>
|
| 150 |
+
</div>
|
| 151 |
+
</div>
|
| 152 |
+
|
| 153 |
+
<!-- FAQ -->
|
| 154 |
+
<div class="card shadow">
|
| 155 |
+
<div class="card-header bg-secondary text-white">
|
| 156 |
+
<h4 class="mb-0">Frequently Asked Questions</h4>
|
| 157 |
+
</div>
|
| 158 |
+
<div class="card-body">
|
| 159 |
+
<h6>Q: Do I need to register?</h6>
|
| 160 |
+
<p class="small">No! Data2Model is completely free and requires no registration.</p>
|
| 161 |
+
|
| 162 |
+
<h6>Q: What file formats are supported?</h6>
|
| 163 |
+
<p class="small">CSV, Excel (.xlsx, .xls), and JSON files.</p>
|
| 164 |
+
|
| 165 |
+
<h6>Q: How long does training take?</h6>
|
| 166 |
+
<p class="small">Typically 1-5 minutes depending on dataset size.</p>
|
| 167 |
+
|
| 168 |
+
<h6>Q: Can I use the model in my application?</h6>
|
| 169 |
+
<p class="small">Yes! Download the .pkl file and use it with scikit-learn in Python.</p>
|
| 170 |
+
|
| 171 |
+
<h6>Q: What if my data is too large?</h6>
|
| 172 |
+
<p class="small">For datasets >100K rows, we automatically use 60/20/20 train/test/validation split for better accuracy.</p>
|
| 173 |
+
|
| 174 |
+
<h6 class="mb-2">Need more help?</h6>
|
| 175 |
+
<a href="{{ url_for('feedback') }}" class="btn btn-primary btn-sm">
|
| 176 |
+
<i class="fas fa-comment"></i> Contact Support
|
| 177 |
+
</a>
|
| 178 |
+
</div>
|
| 179 |
+
</div>
|
| 180 |
+
</div>
|
| 181 |
+
</div>
|
| 182 |
+
</div>
|
| 183 |
+
{% endblock %}
|
templates/feedback.html
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
|
| 3 |
+
{% block title %}Feedback - Data2Model{% endblock %}
|
| 4 |
+
|
| 5 |
+
{% block content %}
|
| 6 |
+
<div class="container my-5">
|
| 7 |
+
<div class="row">
|
| 8 |
+
<div class="col-lg-8 mx-auto">
|
| 9 |
+
<div class="text-center mb-5">
|
| 10 |
+
<h1 class="display-4">
|
| 11 |
+
<i class="fas fa-comment-alt"></i> We Value Your Feedback
|
| 12 |
+
</h1>
|
| 13 |
+
<p class="lead">Help us improve Data2Model with your suggestions</p>
|
| 14 |
+
</div>
|
| 15 |
+
|
| 16 |
+
<div class="card shadow">
|
| 17 |
+
<div class="card-header bg-primary text-white">
|
| 18 |
+
<h4 class="mb-0">
|
| 19 |
+
<i class="fas fa-paper-plane"></i> Submit Feedback
|
| 20 |
+
</h4>
|
| 21 |
+
</div>
|
| 22 |
+
<div class="card-body">
|
| 23 |
+
<form action="{{ url_for('feedback') }}" method="post">
|
| 24 |
+
<!-- Name -->
|
| 25 |
+
<div class="mb-3">
|
| 26 |
+
<label for="name" class="form-label">
|
| 27 |
+
<strong>Name</strong>
|
| 28 |
+
</label>
|
| 29 |
+
<input type="text" class="form-control" id="name" name="name"
|
| 30 |
+
placeholder="Your name" required>
|
| 31 |
+
</div>
|
| 32 |
+
|
| 33 |
+
<!-- Email -->
|
| 34 |
+
<div class="mb-3">
|
| 35 |
+
<label for="email" class="form-label">
|
| 36 |
+
<strong>Email</strong>
|
| 37 |
+
</label>
|
| 38 |
+
<input type="email" class="form-control" id="email" name="email"
|
| 39 |
+
placeholder="your.email@example.com" required>
|
| 40 |
+
</div>
|
| 41 |
+
|
| 42 |
+
<!-- Rating -->
|
| 43 |
+
<div class="mb-3">
|
| 44 |
+
<label class="form-label">
|
| 45 |
+
<strong>How would you rate your experience?</strong>
|
| 46 |
+
</label>
|
| 47 |
+
<div class="btn-group d-flex" role="group">
|
| 48 |
+
<input type="radio" class="btn-check" name="rating" id="rating1" value="1">
|
| 49 |
+
<label class="btn btn-outline-danger" for="rating1">
|
| 50 |
+
<i class="fas fa-star"></i> 1
|
| 51 |
+
</label>
|
| 52 |
+
|
| 53 |
+
<input type="radio" class="btn-check" name="rating" id="rating2" value="2">
|
| 54 |
+
<label class="btn btn-outline-warning" for="rating2">
|
| 55 |
+
<i class="fas fa-star"></i> 2
|
| 56 |
+
</label>
|
| 57 |
+
|
| 58 |
+
<input type="radio" class="btn-check" name="rating" id="rating3" value="3">
|
| 59 |
+
<label class="btn btn-outline-info" for="rating3">
|
| 60 |
+
<i class="fas fa-star"></i> 3
|
| 61 |
+
</label>
|
| 62 |
+
|
| 63 |
+
<input type="radio" class="btn-check" name="rating" id="rating4" value="4">
|
| 64 |
+
<label class="btn btn-outline-primary" for="rating4">
|
| 65 |
+
<i class="fas fa-star"></i> 4
|
| 66 |
+
</label>
|
| 67 |
+
|
| 68 |
+
<input type="radio" class="btn-check" name="rating" id="rating5" value="5" checked>
|
| 69 |
+
<label class="btn btn-outline-success" for="rating5">
|
| 70 |
+
<i class="fas fa-star"></i> 5
|
| 71 |
+
</label>
|
| 72 |
+
</div>
|
| 73 |
+
</div>
|
| 74 |
+
|
| 75 |
+
<!-- Message -->
|
| 76 |
+
<div class="mb-3">
|
| 77 |
+
<label for="message" class="form-label">
|
| 78 |
+
<strong>Your Feedback</strong>
|
| 79 |
+
</label>
|
| 80 |
+
<textarea class="form-control" id="message" name="message" rows="6"
|
| 81 |
+
placeholder="Tell us about your experience, suggestions, or report any issues..."
|
| 82 |
+
required></textarea>
|
| 83 |
+
</div>
|
| 84 |
+
|
| 85 |
+
<!-- Submit Button -->
|
| 86 |
+
<div class="d-grid">
|
| 87 |
+
<button type="submit" class="btn btn-primary btn-lg">
|
| 88 |
+
<i class="fas fa-paper-plane"></i> Submit Feedback
|
| 89 |
+
</button>
|
| 90 |
+
</div>
|
| 91 |
+
</form>
|
| 92 |
+
</div>
|
| 93 |
+
</div>
|
| 94 |
+
|
| 95 |
+
<!-- Contact Info -->
|
| 96 |
+
<div class="card shadow mt-4">
|
| 97 |
+
<div class="card-body text-center">
|
| 98 |
+
<h5>Other Ways to Reach Us</h5>
|
| 99 |
+
<p style="color: #2d3748; font-size: 1.1rem;">
|
| 100 |
+
<i class="fas fa-envelope"></i> supportdata2model@gmail.in<br>
|
| 101 |
+
<i class="fas fa-envelope"></i> data2model@gmail.in
|
| 102 |
+
</p>
|
| 103 |
+
</div>
|
| 104 |
+
</div>
|
| 105 |
+
</div>
|
| 106 |
+
</div>
|
| 107 |
+
</div>
|
| 108 |
+
{% endblock %}
|
templates/index.html
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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block title %}Data2Model - Home{% endblock %}
|
| 4 |
+
|
| 5 |
+
{% block content %}
|
| 6 |
+
<!-- Hero Section -->
|
| 7 |
+
<div class="hero-section py-5">
|
| 8 |
+
<div class="container">
|
| 9 |
+
<div class="row align-items-center">
|
| 10 |
+
<div class="col-lg-6">
|
| 11 |
+
<h1 class="display-4 fw-bold mb-4 hero-title">
|
| 12 |
+
<i class="fas fa-robot"></i> Data2Model
|
| 13 |
+
</h1>
|
| 14 |
+
<h2 class="hero-subtitle mb-4">
|
| 15 |
+
Transform Your Data into Powerful Machine Learning Models in Minutes
|
| 16 |
+
</h2>
|
| 17 |
+
<p class="hero-description mb-4">
|
| 18 |
+
Upload your dataset, and let our automated ML platform handle everything from
|
| 19 |
+
preprocessing to model training and evaluation. No coding required!
|
| 20 |
+
</p>
|
| 21 |
+
<div class="d-flex gap-2">
|
| 22 |
+
<a href="#upload-section" class="btn btn-dark btn-lg">
|
| 23 |
+
<i class="fas fa-upload"></i> Get Started
|
| 24 |
+
</a>
|
| 25 |
+
<a href="{{ url_for('documentation') }}" class="btn btn-dark btn-lg">
|
| 26 |
+
<i class="fas fa-book"></i> Learn More
|
| 27 |
+
</a>
|
| 28 |
+
</div>
|
| 29 |
+
</div>
|
| 30 |
+
<div class="col-lg-6 text-center">
|
| 31 |
+
<i class="fas fa-brain fa-10x text-primary opacity-50"></i>
|
| 32 |
+
</div>
|
| 33 |
+
</div>
|
| 34 |
+
</div>
|
| 35 |
+
</div>
|
| 36 |
+
|
| 37 |
+
<!-- Value Proposition Section -->
|
| 38 |
+
<div class="container my-5">
|
| 39 |
+
<div class="row text-center">
|
| 40 |
+
<div class="col-md-4 mb-3">
|
| 41 |
+
<i class="fas fa-clock fa-3x text-primary mb-3"></i>
|
| 42 |
+
<h5>Save Time</h5>
|
| 43 |
+
<p class="text-muted">Build ML models in minutes, not weeks</p>
|
| 44 |
+
</div>
|
| 45 |
+
<div class="col-md-4 mb-3">
|
| 46 |
+
<i class="fas fa-code fa-3x text-success mb-3"></i>
|
| 47 |
+
<h5>No Coding Required</h5>
|
| 48 |
+
<p class="text-muted">User-friendly interface for everyone</p>
|
| 49 |
+
</div>
|
| 50 |
+
<div class="col-md-4 mb-3">
|
| 51 |
+
<i class="fas fa-chart-line fa-3x text-info mb-3"></i>
|
| 52 |
+
<h5>High Accuracy</h5>
|
| 53 |
+
<p class="text-muted">Automatic algorithm selection for best results</p>
|
| 54 |
+
</div>
|
| 55 |
+
</div>
|
| 56 |
+
</div>
|
| 57 |
+
|
| 58 |
+
<!-- Features Section -->
|
| 59 |
+
<div class="container my-5">
|
| 60 |
+
<h2 class="text-center mb-5">Key Features</h2>
|
| 61 |
+
<div class="row g-4">
|
| 62 |
+
<div class="col-md-4">
|
| 63 |
+
<div class="card h-100 shadow-sm">
|
| 64 |
+
<div class="card-body text-center">
|
| 65 |
+
<i class="fas fa-magic fa-3x text-primary mb-3"></i>
|
| 66 |
+
<h5 class="card-title">Fully Automated</h5>
|
| 67 |
+
<p class="card-text">
|
| 68 |
+
Automatic data preprocessing, feature engineering, model selection,
|
| 69 |
+
and hyperparameter tuning. Just upload and click!
|
| 70 |
+
</p>
|
| 71 |
+
</div>
|
| 72 |
+
</div>
|
| 73 |
+
</div>
|
| 74 |
+
<div class="col-md-4">
|
| 75 |
+
<div class="card h-100 shadow-sm">
|
| 76 |
+
<div class="card-body text-center">
|
| 77 |
+
<i class="fas fa-chart-bar fa-3x text-success mb-3"></i>
|
| 78 |
+
<h5 class="card-title">Multiple Algorithms</h5>
|
| 79 |
+
<p class="card-text">
|
| 80 |
+
Supports classification, regression, and clustering. Automatically
|
| 81 |
+
compares multiple algorithms and selects the best one.
|
| 82 |
+
</p>
|
| 83 |
+
</div>
|
| 84 |
+
</div>
|
| 85 |
+
</div>
|
| 86 |
+
<div class="col-md-4">
|
| 87 |
+
<div class="card h-100 shadow-sm">
|
| 88 |
+
<div class="card-body text-center">
|
| 89 |
+
<i class="fas fa-download fa-3x text-info mb-3"></i>
|
| 90 |
+
<h5 class="card-title">Downloadable Models</h5>
|
| 91 |
+
<p class="card-text">
|
| 92 |
+
Download your trained models for future use. Deploy them in your
|
| 93 |
+
applications or make predictions on new data.
|
| 94 |
+
</p>
|
| 95 |
+
</div>
|
| 96 |
+
</div>
|
| 97 |
+
</div>
|
| 98 |
+
</div>
|
| 99 |
+
</div>
|
| 100 |
+
|
| 101 |
+
<!-- Upload Section -->
|
| 102 |
+
<div id="upload-section" class="bg-light py-5">
|
| 103 |
+
<div class="container">
|
| 104 |
+
<div class="row justify-content-center">
|
| 105 |
+
<div class="col-lg-8">
|
| 106 |
+
<div class="card shadow">
|
| 107 |
+
<div class="card-header bg-primary text-white">
|
| 108 |
+
<h4 class="mb-0">
|
| 109 |
+
<i class="fas fa-upload"></i> Upload Your Dataset
|
| 110 |
+
</h4>
|
| 111 |
+
</div>
|
| 112 |
+
<div class="card-body">
|
| 113 |
+
<form action="{{ url_for('upload_file') }}" method="post" enctype="multipart/form-data" id="uploadForm">
|
| 114 |
+
<div class="mb-4">
|
| 115 |
+
<label for="file" class="form-label">
|
| 116 |
+
<strong>Select your dataset file</strong>
|
| 117 |
+
</label>
|
| 118 |
+
<input type="file" class="form-control" id="file" name="file"
|
| 119 |
+
accept=".csv,.xlsx,.xls,.json" required>
|
| 120 |
+
<div class="form-text">
|
| 121 |
+
Supported formats: CSV, Excel (.xlsx, .xls), JSON
|
| 122 |
+
</div>
|
| 123 |
+
</div>
|
| 124 |
+
|
| 125 |
+
<div class="alert alert-info">
|
| 126 |
+
<h6 class="alert-heading">
|
| 127 |
+
<i class="fas fa-info-circle"></i> What happens next?
|
| 128 |
+
</h6>
|
| 129 |
+
<ol class="mb-0 ps-3">
|
| 130 |
+
<li>Your dataset will be analyzed automatically</li>
|
| 131 |
+
<li>Select your target column and configure options</li>
|
| 132 |
+
<li>Our system will train multiple ML models</li>
|
| 133 |
+
<li>Get results and download the best model</li>
|
| 134 |
+
</ol>
|
| 135 |
+
</div>
|
| 136 |
+
|
| 137 |
+
<div class="d-grid">
|
| 138 |
+
<button type="submit" class="btn btn-primary btn-lg">
|
| 139 |
+
<i class="fas fa-upload"></i> Upload and Analyze
|
| 140 |
+
</button>
|
| 141 |
+
</div>
|
| 142 |
+
</form>
|
| 143 |
+
</div>
|
| 144 |
+
</div>
|
| 145 |
+
</div>
|
| 146 |
+
</div>
|
| 147 |
+
</div>
|
| 148 |
+
</div>
|
| 149 |
+
|
| 150 |
+
<!-- How It Works -->
|
| 151 |
+
<div class="container my-5">
|
| 152 |
+
<h2 class="text-center mb-5">How It Works</h2>
|
| 153 |
+
<div class="row">
|
| 154 |
+
<div class="col-md-3 text-center mb-4">
|
| 155 |
+
<div class="step-circle bg-primary text-white mx-auto mb-3">1</div>
|
| 156 |
+
<h5>Upload Data</h5>
|
| 157 |
+
<p>Upload your CSV, Excel, or JSON file</p>
|
| 158 |
+
</div>
|
| 159 |
+
<div class="col-md-3 text-center mb-4">
|
| 160 |
+
<div class="step-circle bg-success text-white mx-auto mb-3">2</div>
|
| 161 |
+
<h5>Configure</h5>
|
| 162 |
+
<p>Select target column and options</p>
|
| 163 |
+
</div>
|
| 164 |
+
<div class="col-md-3 text-center mb-4">
|
| 165 |
+
<div class="step-circle bg-info text-white mx-auto mb-3">3</div>
|
| 166 |
+
<h5>Train Models</h5>
|
| 167 |
+
<p>System trains and compares models</p>
|
| 168 |
+
</div>
|
| 169 |
+
<div class="col-md-3 text-center mb-4">
|
| 170 |
+
<div class="step-circle bg-warning text-white mx-auto mb-3">4</div>
|
| 171 |
+
<h5>Download</h5>
|
| 172 |
+
<p>Get your trained model and results</p>
|
| 173 |
+
</div>
|
| 174 |
+
</div>
|
| 175 |
+
</div>
|
| 176 |
+
|
| 177 |
+
<!-- Supported Algorithms -->
|
| 178 |
+
<div class="bg-light py-5">
|
| 179 |
+
<div class="container">
|
| 180 |
+
<h2 class="text-center mb-5">Supported Algorithms</h2>
|
| 181 |
+
<div class="row">
|
| 182 |
+
<div class="col-md-6 mb-4">
|
| 183 |
+
<div class="card h-100">
|
| 184 |
+
<div class="card-header bg-success text-white">
|
| 185 |
+
<h5 class="mb-0">Classification</h5>
|
| 186 |
+
</div>
|
| 187 |
+
<div class="card-body">
|
| 188 |
+
<ul class="list-unstyled">
|
| 189 |
+
<li><i class="fas fa-check text-success"></i> Logistic Regression</li>
|
| 190 |
+
<li><i class="fas fa-check text-success"></i> Random Forest</li>
|
| 191 |
+
<li><i class="fas fa-check text-success"></i> Gradient Boosting</li>
|
| 192 |
+
<li><i class="fas fa-check text-success"></i> Decision Tree</li>
|
| 193 |
+
<li><i class="fas fa-check text-success"></i> K-Nearest Neighbors</li>
|
| 194 |
+
<li><i class="fas fa-check text-success"></i> Naive Bayes</li>
|
| 195 |
+
<li><i class="fas fa-check text-success"></i> Support Vector Machine</li>
|
| 196 |
+
<li><i class="fas fa-check text-success"></i> AdaBoost</li>
|
| 197 |
+
</ul>
|
| 198 |
+
</div>
|
| 199 |
+
</div>
|
| 200 |
+
</div>
|
| 201 |
+
<div class="col-md-6 mb-4">
|
| 202 |
+
<div class="card h-100">
|
| 203 |
+
<div class="card-header bg-primary text-white">
|
| 204 |
+
<h5 class="mb-0">Regression</h5>
|
| 205 |
+
</div>
|
| 206 |
+
<div class="card-body">
|
| 207 |
+
<ul class="list-unstyled">
|
| 208 |
+
<li><i class="fas fa-check text-primary"></i> Linear Regression</li>
|
| 209 |
+
<li><i class="fas fa-check text-primary"></i> Random Forest</li>
|
| 210 |
+
<li><i class="fas fa-check text-primary"></i> Gradient Boosting</li>
|
| 211 |
+
<li><i class="fas fa-check text-primary"></i> XGBoost</li>
|
| 212 |
+
<li><i class="fas fa-check text-primary"></i> LightGBM</li>
|
| 213 |
+
<li><i class="fas fa-check text-primary"></i> Decision Tree</li>
|
| 214 |
+
<li><i class="fas fa-check text-primary"></i> K-Nearest Neighbors</li>
|
| 215 |
+
<li><i class="fas fa-check text-primary"></i> Support Vector Regression (SVR)</li>
|
| 216 |
+
</ul>
|
| 217 |
+
</div>
|
| 218 |
+
</div>
|
| 219 |
+
</div>
|
| 220 |
+
</div>
|
| 221 |
+
</div>
|
| 222 |
+
</div>
|
| 223 |
+
|
| 224 |
+
<style>
|
| 225 |
+
.hero-section {
|
| 226 |
+
background: linear-gradient(135deg, #f5f0e8 0%, #faf7f2 50%, #f0ebe3 100%);
|
| 227 |
+
min-height: 500px;
|
| 228 |
+
border-radius: 0 0 50px 50px;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
.hero-title {
|
| 232 |
+
color: #2d3748;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
.hero-subtitle {
|
| 236 |
+
color: #2d3748;
|
| 237 |
+
font-size: 1.8rem;
|
| 238 |
+
font-weight: 600;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
.hero-description {
|
| 242 |
+
color: #4a5568;
|
| 243 |
+
font-size: 1.1rem;
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
.step-circle {
|
| 247 |
+
width: 80px;
|
| 248 |
+
height: 80px;
|
| 249 |
+
line-height: 80px;
|
| 250 |
+
border-radius: 50%;
|
| 251 |
+
font-size: 2rem;
|
| 252 |
+
font-weight: bold;
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
.bg-gradient {
|
| 256 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 257 |
+
}
|
| 258 |
+
</style>
|
| 259 |
+
{% endblock %}
|
templates/predict.html
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
{% block title %}Predict - Data2Model{% endblock %}
|
| 3 |
+
|
| 4 |
+
{% block content %}
|
| 5 |
+
<div class="container my-5">
|
| 6 |
+
<div class="text-center mb-4">
|
| 7 |
+
<h1 class="display-4">
|
| 8 |
+
<i class="fas fa-chart-line"></i> Make Predictions
|
| 9 |
+
</h1>
|
| 10 |
+
<p class="lead">Use your validated model to predict on new data</p>
|
| 11 |
+
</div>
|
| 12 |
+
|
| 13 |
+
<!-- Model Status Banner -->
|
| 14 |
+
<div class="row mb-4">
|
| 15 |
+
<div class="col-lg-8 mx-auto">
|
| 16 |
+
<div class="alert alert-success d-flex align-items-center gap-3 mb-0">
|
| 17 |
+
<i class="fas fa-unlock-alt fa-2x"></i>
|
| 18 |
+
<div>
|
| 19 |
+
<strong>Model Ready:</strong> {{ model_state.model_name }}
|
| 20 |
+
<span class="badge bg-primary ms-2">{{ model_state.problem_type|title }}</span><br>
|
| 21 |
+
<small>Split: {{ model_state.split_info }} β trained, tested & validated β</small>
|
| 22 |
+
</div>
|
| 23 |
+
</div>
|
| 24 |
+
</div>
|
| 25 |
+
</div>
|
| 26 |
+
|
| 27 |
+
{% if predictions %}
|
| 28 |
+
<!-- Predictions Results -->
|
| 29 |
+
<div class="row mb-4">
|
| 30 |
+
<div class="col-lg-10 mx-auto">
|
| 31 |
+
<div class="card shadow">
|
| 32 |
+
<div class="card-header bg-success text-white">
|
| 33 |
+
<h4 class="mb-0">
|
| 34 |
+
<i class="fas fa-check-circle"></i> Predictions Generated Successfully!
|
| 35 |
+
</h4>
|
| 36 |
+
</div>
|
| 37 |
+
<div class="card-body">
|
| 38 |
+
<p>Total predictions made: <strong>{{ predictions|length }}</strong></p>
|
| 39 |
+
|
| 40 |
+
<div class="table-responsive mt-3">
|
| 41 |
+
<table class="table table-striped table-hover">
|
| 42 |
+
<thead class="table-dark">
|
| 43 |
+
<tr>
|
| 44 |
+
<th>Row #</th>
|
| 45 |
+
<th>Prediction</th>
|
| 46 |
+
</tr>
|
| 47 |
+
</thead>
|
| 48 |
+
<tbody>
|
| 49 |
+
{% for i, pred in enumerate(predictions) %}
|
| 50 |
+
<tr>
|
| 51 |
+
<td>{{ i + 1 }}</td>
|
| 52 |
+
<td><span class="badge bg-primary">{{ pred }}</span></td>
|
| 53 |
+
</tr>
|
| 54 |
+
{% endfor %}
|
| 55 |
+
</tbody>
|
| 56 |
+
</table>
|
| 57 |
+
</div>
|
| 58 |
+
|
| 59 |
+
{% if predictions|length == 100 %}
|
| 60 |
+
<p class="text-muted small">
|
| 61 |
+
<i class="fas fa-info-circle"></i> Showing first 100 predictions.
|
| 62 |
+
Download the full file to see all results.
|
| 63 |
+
</p>
|
| 64 |
+
{% endif %}
|
| 65 |
+
|
| 66 |
+
<div class="d-grid gap-2 mt-3">
|
| 67 |
+
<a href="{{ url_for('static', filename='predictions.csv') }}"
|
| 68 |
+
class="btn btn-success btn-lg" download>
|
| 69 |
+
<i class="fas fa-download"></i> Download Full Predictions (CSV)
|
| 70 |
+
</a>
|
| 71 |
+
<button type="button" class="btn btn-outline-primary" onclick="location.reload()">
|
| 72 |
+
<i class="fas fa-redo"></i> Make Another Prediction
|
| 73 |
+
</button>
|
| 74 |
+
</div>
|
| 75 |
+
</div>
|
| 76 |
+
</div>
|
| 77 |
+
</div>
|
| 78 |
+
</div>
|
| 79 |
+
{% else %}
|
| 80 |
+
<!-- Upload Form for Prediction -->
|
| 81 |
+
<div class="row">
|
| 82 |
+
<div class="col-lg-8 mx-auto">
|
| 83 |
+
<div class="card shadow">
|
| 84 |
+
<div class="card-header bg-primary text-white">
|
| 85 |
+
<h4 class="mb-0">
|
| 86 |
+
<i class="fas fa-upload"></i> Upload Data for Prediction
|
| 87 |
+
</h4>
|
| 88 |
+
</div>
|
| 89 |
+
<div class="card-body">
|
| 90 |
+
<form action="{{ url_for('predict') }}" method="post" enctype="multipart/form-data">
|
| 91 |
+
<div class="mb-4">
|
| 92 |
+
<label for="file" class="form-label">
|
| 93 |
+
<strong>Select your dataset file</strong>
|
| 94 |
+
</label>
|
| 95 |
+
<input type="file" class="form-control" id="file" name="file"
|
| 96 |
+
accept=".csv,.xlsx,.xls,.json" required>
|
| 97 |
+
<div class="form-text">
|
| 98 |
+
Upload a file with the same features as your training data
|
| 99 |
+
</div>
|
| 100 |
+
</div>
|
| 101 |
+
|
| 102 |
+
<div class="alert alert-info">
|
| 103 |
+
<h6 class="alert-heading">
|
| 104 |
+
<i class="fas fa-info-circle"></i> Important Notes:
|
| 105 |
+
</h6>
|
| 106 |
+
<ul class="mb-0">
|
| 107 |
+
<li>Ensure your data has the <strong>same features</strong> as the training data</li>
|
| 108 |
+
<li>Feature names and order should match</li>
|
| 109 |
+
<li>Do NOT include the target column in prediction data</li>
|
| 110 |
+
<li>Missing values will be handled automatically</li>
|
| 111 |
+
</ul>
|
| 112 |
+
</div>
|
| 113 |
+
|
| 114 |
+
<div class="d-grid gap-2">
|
| 115 |
+
<button type="submit" class="btn btn-primary btn-lg">
|
| 116 |
+
<i class="fas fa-play"></i> Generate Predictions
|
| 117 |
+
</button>
|
| 118 |
+
<a href="{{ url_for('index') }}" class="btn btn-outline-secondary">
|
| 119 |
+
<i class="fas fa-arrow-left"></i> Back to Home
|
| 120 |
+
</a>
|
| 121 |
+
</div>
|
| 122 |
+
</form>
|
| 123 |
+
</div>
|
| 124 |
+
</div>
|
| 125 |
+
|
| 126 |
+
</div>
|
| 127 |
+
</div>
|
| 128 |
+
{% endif %}
|
| 129 |
+
</div>
|
| 130 |
+
|
| 131 |
+
{% if predictions %}
|
| 132 |
+
<script>
|
| 133 |
+
// Add enumerate filter functionality
|
| 134 |
+
Jinja2.filters.enumerate = function(arr) {
|
| 135 |
+
return arr.map((item, index) => [index, item]);
|
| 136 |
+
};
|
| 137 |
+
</script>
|
| 138 |
+
{% endif %}
|
| 139 |
+
{% endblock %}
|
templates/predict_locked.html
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
{% block title %}Predict β Locked | Data2Model{% endblock %}
|
| 3 |
+
|
| 4 |
+
{% block content %}
|
| 5 |
+
<div class="container my-5">
|
| 6 |
+
<div class="col-lg-7 mx-auto text-center">
|
| 7 |
+
|
| 8 |
+
<!-- Lock Icon -->
|
| 9 |
+
<div class="mb-4">
|
| 10 |
+
<div class="lock-circle mx-auto mb-3">
|
| 11 |
+
<i class="fas fa-lock fa-4x text-secondary"></i>
|
| 12 |
+
</div>
|
| 13 |
+
<h1 class="display-5 fw-bold">Prediction Locked</h1>
|
| 14 |
+
<p class="lead text-muted">
|
| 15 |
+
The Predict page is only available after training a model with a
|
| 16 |
+
<strong>Train / Test / Validation</strong> split.
|
| 17 |
+
</p>
|
| 18 |
+
</div>
|
| 19 |
+
|
| 20 |
+
<!-- Why locked? -->
|
| 21 |
+
<div class="card shadow mb-4 text-start">
|
| 22 |
+
<div class="card-header bg-warning text-dark">
|
| 23 |
+
<h5 class="mb-0"><i class="fas fa-question-circle"></i> Why is this locked?</h5>
|
| 24 |
+
</div>
|
| 25 |
+
<div class="card-body">
|
| 26 |
+
{% if not model_trained %}
|
| 27 |
+
<div class="d-flex align-items-start gap-3 mb-3">
|
| 28 |
+
<span class="badge bg-danger fs-6 mt-1">1</span>
|
| 29 |
+
<div>
|
| 30 |
+
<strong>No model trained yet</strong><br>
|
| 31 |
+
<span class="text-muted">You haven't uploaded and trained any model. Go to the Home page to begin.</span>
|
| 32 |
+
</div>
|
| 33 |
+
</div>
|
| 34 |
+
{% else %}
|
| 35 |
+
<div class="d-flex align-items-start gap-3 mb-3">
|
| 36 |
+
<span class="badge bg-warning text-dark fs-6 mt-1">!</span>
|
| 37 |
+
<div>
|
| 38 |
+
<strong>Model trained with 2-way split only</strong><br>
|
| 39 |
+
<span class="text-muted">
|
| 40 |
+
Your last training used a <em>Train / Test</em> split only (no validation set).
|
| 41 |
+
A validation set is required to ensure the model is properly evaluated before predictions.
|
| 42 |
+
</span>
|
| 43 |
+
</div>
|
| 44 |
+
</div>
|
| 45 |
+
{% endif %}
|
| 46 |
+
</div>
|
| 47 |
+
</div>
|
| 48 |
+
|
| 49 |
+
<!-- 3-step workflow -->
|
| 50 |
+
<div class="card shadow mb-4 text-start">
|
| 51 |
+
<div class="card-header bg-primary text-white">
|
| 52 |
+
<h5 class="mb-0"><i class="fas fa-unlock-alt"></i> How to Unlock Predictions</h5>
|
| 53 |
+
</div>
|
| 54 |
+
<div class="card-body">
|
| 55 |
+
<div class="d-flex align-items-start gap-3 mb-3">
|
| 56 |
+
<div class="step-badge bg-primary text-white">1</div>
|
| 57 |
+
<div>
|
| 58 |
+
<strong>Upload your dataset</strong> on the Home page
|
| 59 |
+
</div>
|
| 60 |
+
</div>
|
| 61 |
+
<div class="d-flex align-items-start gap-3 mb-3">
|
| 62 |
+
<div class="step-badge bg-primary text-white">2</div>
|
| 63 |
+
<div>
|
| 64 |
+
<strong>On the Configure page</strong>, select
|
| 65 |
+
<span class="badge bg-success">Train / Test / Validation Split</span>
|
| 66 |
+
under "Data Split Strategy"
|
| 67 |
+
<div class="text-muted small mt-1">
|
| 68 |
+
This splits your data into 3 parts β e.g. 60% training, 20% testing, 20% validation
|
| 69 |
+
</div>
|
| 70 |
+
</div>
|
| 71 |
+
</div>
|
| 72 |
+
<div class="d-flex align-items-start gap-3">
|
| 73 |
+
<div class="step-badge bg-success text-white">3</div>
|
| 74 |
+
<div>
|
| 75 |
+
<strong>Train the model.</strong>
|
| 76 |
+
The Predict page will automatically unlock after successful training with validation.
|
| 77 |
+
</div>
|
| 78 |
+
</div>
|
| 79 |
+
</div>
|
| 80 |
+
</div>
|
| 81 |
+
|
| 82 |
+
<!-- Why validation matters -->
|
| 83 |
+
<div class="card shadow mb-4 text-start border-info">
|
| 84 |
+
<div class="card-body">
|
| 85 |
+
<h6 class="text-info"><i class="fas fa-info-circle"></i> Why is a validation set required?</h6>
|
| 86 |
+
<p class="mb-0 text-muted small">
|
| 87 |
+
A model evaluated only on training + test data might be over-fitted or misleadingly accurate.
|
| 88 |
+
The <strong>validation set</strong> is a completely separate portion of data the model never sees
|
| 89 |
+
during training, giving a true measure of how well it will perform on real-world new data.
|
| 90 |
+
Only after passing this check is the model trustworthy enough for making predictions.
|
| 91 |
+
</p>
|
| 92 |
+
</div>
|
| 93 |
+
</div>
|
| 94 |
+
|
| 95 |
+
<!-- Action buttons -->
|
| 96 |
+
<div class="d-grid gap-2">
|
| 97 |
+
<a href="{{ url_for('index') }}" class="btn btn-primary btn-lg">
|
| 98 |
+
<i class="fas fa-upload"></i> Go to Home β Upload & Train
|
| 99 |
+
</a>
|
| 100 |
+
{% if model_trained %}
|
| 101 |
+
<p class="text-muted small mt-1">
|
| 102 |
+
Your previous model is still saved. Simply re-train with the 3-way split to unlock predictions.
|
| 103 |
+
</p>
|
| 104 |
+
{% endif %}
|
| 105 |
+
</div>
|
| 106 |
+
|
| 107 |
+
</div>
|
| 108 |
+
</div>
|
| 109 |
+
|
| 110 |
+
<style>
|
| 111 |
+
.lock-circle {
|
| 112 |
+
width: 100px; height: 100px;
|
| 113 |
+
border-radius: 50%;
|
| 114 |
+
background: #f8f9fa;
|
| 115 |
+
border: 3px solid #dee2e6;
|
| 116 |
+
display: flex; align-items: center; justify-content: center;
|
| 117 |
+
}
|
| 118 |
+
.step-badge {
|
| 119 |
+
min-width: 32px; height: 32px;
|
| 120 |
+
border-radius: 50%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1 |
+
{% extends "base.html" %}
|
| 2 |
+
|
| 3 |
+
{% block title %}Training Results - Data2Model{% endblock %}
|
| 4 |
+
|
| 5 |
+
{% block content %}
|
| 6 |
+
<div class="container my-5">
|
| 7 |
+
<div class="text-center mb-5">
|
| 8 |
+
<h1 class="display-4">
|
| 9 |
+
<i class="fas fa-check-circle text-success"></i> Training Complete!
|
| 10 |
+
</h1>
|
| 11 |
+
<p class="lead">Your machine learning model has been successfully trained</p>
|
| 12 |
+
</div>
|
| 13 |
+
|
| 14 |
+
<!-- Model Information -->
|
| 15 |
+
<div class="row mb-4">
|
| 16 |
+
<div class="col-lg-8 mx-auto">
|
| 17 |
+
<div class="card shadow">
|
| 18 |
+
<div class="card-header bg-success text-white">
|
| 19 |
+
<h4 class="mb-0">
|
| 20 |
+
<i class="fas fa-trophy"></i> Best Model: {{ pipeline.model_name }}
|
| 21 |
+
</h4>
|
| 22 |
+
</div>
|
| 23 |
+
<div class="card-body">
|
| 24 |
+
<div class="row">
|
| 25 |
+
<div class="col-md-6">
|
| 26 |
+
<p><strong>Problem Type:</strong>
|
| 27 |
+
<span class="badge bg-primary">{{ pipeline.problem_type|title }}</span>
|
| 28 |
+
</p>
|
| 29 |
+
<p><strong>Algorithm:</strong> {{ pipeline.model_name }}</p>
|
| 30 |
+
</div>
|
| 31 |
+
<div class="col-md-6">
|
| 32 |
+
<p><strong>Target Variable:</strong> {{ pipeline.target_name }}</p>
|
| 33 |
+
<p><strong>Features Used:</strong> {{ pipeline.feature_names|length }}</p>
|
| 34 |
+
</div>
|
| 35 |
+
</div>
|
| 36 |
+
</div>
|
| 37 |
+
</div>
|
| 38 |
+
</div>
|
| 39 |
+
</div>
|
| 40 |
+
|
| 41 |
+
<!-- Performance Metrics -->
|
| 42 |
+
<div class="row mb-4">
|
| 43 |
+
<div class="col-lg-8 mx-auto">
|
| 44 |
+
<div class="card shadow">
|
| 45 |
+
<div class="card-header bg-primary text-white">
|
| 46 |
+
<h4 class="mb-0">
|
| 47 |
+
<i class="fas fa-chart-bar"></i> Performance Metrics
|
| 48 |
+
</h4>
|
| 49 |
+
</div>
|
| 50 |
+
<div class="card-body">
|
| 51 |
+
{% if pipeline.problem_type == 'classification' %}
|
| 52 |
+
<!-- Classification Metrics -->
|
| 53 |
+
<div class="row text-center">
|
| 54 |
+
<div class="col-md-3 mb-3">
|
| 55 |
+
<div class="metric-box">
|
| 56 |
+
<h3 class="text-success">{{ "%.2f%%"|format(results.results.accuracy * 100) }}</h3>
|
| 57 |
+
<p class="text-muted">Test Accuracy</p>
|
| 58 |
+
</div>
|
| 59 |
+
</div>
|
| 60 |
+
<div class="col-md-3 mb-3">
|
| 61 |
+
<div class="metric-box">
|
| 62 |
+
<h3 class="text-info">{{ "%.2f%%"|format(results.results.precision * 100) }}</h3>
|
| 63 |
+
<p class="text-muted">Precision</p>
|
| 64 |
+
</div>
|
| 65 |
+
</div>
|
| 66 |
+
<div class="col-md-3 mb-3">
|
| 67 |
+
<div class="metric-box">
|
| 68 |
+
<h3 class="text-warning">{{ "%.2f%%"|format(results.results.recall * 100) }}</h3>
|
| 69 |
+
<p class="text-muted">Recall</p>
|
| 70 |
+
</div>
|
| 71 |
+
</div>
|
| 72 |
+
<div class="col-md-3 mb-3">
|
| 73 |
+
<div class="metric-box">
|
| 74 |
+
<h3 class="text-primary">{{ "%.2f%%"|format(results.results.f1_score * 100) }}</h3>
|
| 75 |
+
<p class="text-muted">F1 Score</p>
|
| 76 |
+
</div>
|
| 77 |
+
</div>
|
| 78 |
+
</div>
|
| 79 |
+
|
| 80 |
+
{% if results.results.validation_accuracy %}
|
| 81 |
+
<div class="alert alert-info mt-3">
|
| 82 |
+
<strong>Validation Set Accuracy:</strong> {{ "%.2f%%"|format(results.results.validation_accuracy * 100) }}
|
| 83 |
+
<br><small>Large dataset detected - used 60% training, 20% testing, 20% validation split</small>
|
| 84 |
+
</div>
|
| 85 |
+
{% endif %}
|
| 86 |
+
|
| 87 |
+
{% elif pipeline.problem_type == 'regression' %}
|
| 88 |
+
<!-- Regression Metrics -->
|
| 89 |
+
<div class="row text-center">
|
| 90 |
+
<div class="col-md-3 mb-3">
|
| 91 |
+
<div class="metric-box">
|
| 92 |
+
<h3 class="text-success">{{ "%.4f"|format(results.results.r2_score) }}</h3>
|
| 93 |
+
<p class="text-muted">Test RΒ² Score</p>
|
| 94 |
+
</div>
|
| 95 |
+
</div>
|
| 96 |
+
<div class="col-md-3 mb-3">
|
| 97 |
+
<div class="metric-box">
|
| 98 |
+
<h3 class="text-info">{{ "%.4f"|format(results.results.rmse) }}</h3>
|
| 99 |
+
<p class="text-muted">RMSE</p>
|
| 100 |
+
</div>
|
| 101 |
+
</div>
|
| 102 |
+
<div class="col-md-3 mb-3">
|
| 103 |
+
<div class="metric-box">
|
| 104 |
+
<h3 class="text-warning">{{ "%.4f"|format(results.results.mae) }}</h3>
|
| 105 |
+
<p class="text-muted">MAE</p>
|
| 106 |
+
</div>
|
| 107 |
+
</div>
|
| 108 |
+
<div class="col-md-3 mb-3">
|
| 109 |
+
<div class="metric-box">
|
| 110 |
+
<h3 class="text-danger">{{ "%.4f"|format(results.results.mse) }}</h3>
|
| 111 |
+
<p class="text-muted">MSE</p>
|
| 112 |
+
</div>
|
| 113 |
+
</div>
|
| 114 |
+
</div>
|
| 115 |
+
|
| 116 |
+
{% if results.results.validation_r2 %}
|
| 117 |
+
<div class="alert alert-info mt-3">
|
| 118 |
+
<strong>Validation Set Metrics:</strong> RΒ² = {{ "%.4f"|format(results.results.validation_r2) }},
|
| 119 |
+
RMSE = {{ "%.4f"|format(results.results.validation_rmse) }}
|
| 120 |
+
<br><small>Large dataset detected - used 60% training, 20% testing, 20% validation split</small>
|
| 121 |
+
</div>
|
| 122 |
+
{% endif %}
|
| 123 |
+
{% endif %}
|
| 124 |
+
|
| 125 |
+
<div class="mt-4">
|
| 126 |
+
<h6>Metrics Explained:</h6>
|
| 127 |
+
<ul class="small text-muted">
|
| 128 |
+
{% if pipeline.problem_type == 'classification' %}
|
| 129 |
+
<li><strong>Accuracy:</strong> Percentage of correct predictions</li>
|
| 130 |
+
<li><strong>Precision:</strong> Of predicted positives, how many were correct</li>
|
| 131 |
+
<li><strong>Recall:</strong> Of actual positives, how many were found</li>
|
| 132 |
+
<li><strong>F1 Score:</strong> Harmonic mean of precision and recall</li>
|
| 133 |
+
{% else %}
|
| 134 |
+
<li><strong>RΒ² Score:</strong> Proportion of variance explained (closer to 1 is better)</li>
|
| 135 |
+
<li><strong>RMSE:</strong> Root Mean Square Error (lower is better)</li>
|
| 136 |
+
<li><strong>MAE:</strong> Mean Absolute Error (lower is better)</li>
|
| 137 |
+
<li><strong>MSE:</strong> Mean Squared Error (lower is better)</li>
|
| 138 |
+
{% endif %}
|
| 139 |
+
</ul>
|
| 140 |
+
</div>
|
| 141 |
+
</div>
|
| 142 |
+
</div>
|
| 143 |
+
</div>
|
| 144 |
+
</div>
|
| 145 |
+
|
| 146 |
+
<!-- Preprocessing Steps -->
|
| 147 |
+
<div class="row mb-4">
|
| 148 |
+
<div class="col-lg-8 mx-auto">
|
| 149 |
+
<div class="card shadow">
|
| 150 |
+
<div class="card-header bg-info text-white">
|
| 151 |
+
<h4 class="mb-0">
|
| 152 |
+
<i class="fas fa-tasks"></i> Preprocessing Steps Applied
|
| 153 |
+
</h4>
|
| 154 |
+
</div>
|
| 155 |
+
<div class="card-body">
|
| 156 |
+
<ol>
|
| 157 |
+
{% for step in pipeline.preprocessing_steps %}
|
| 158 |
+
<li>{{ step }}</li>
|
| 159 |
+
{% endfor %}
|
| 160 |
+
</ol>
|
| 161 |
+
</div>
|
| 162 |
+
</div>
|
| 163 |
+
</div>
|
| 164 |
+
</div>
|
| 165 |
+
|
| 166 |
+
<!-- Split Info Banner -->
|
| 167 |
+
<div class="row mb-4">
|
| 168 |
+
<div class="col-lg-8 mx-auto">
|
| 169 |
+
{% if results.use_val %}
|
| 170 |
+
<div class="alert alert-success d-flex align-items-center gap-3">
|
| 171 |
+
<i class="fas fa-check-circle fa-2x"></i>
|
| 172 |
+
<div>
|
| 173 |
+
<strong>3-Way Split Used:</strong> {{ results.split_info }}<br>
|
| 174 |
+
<span class="small">Model trained, tested, and validated β Prediction is fully unlocked!</span>
|
| 175 |
+
</div>
|
| 176 |
+
</div>
|
| 177 |
+
{% else %}
|
| 178 |
+
<div class="alert alert-success d-flex align-items-center gap-3">
|
| 179 |
+
<i class="fas fa-check-circle fa-2x"></i>
|
| 180 |
+
<div>
|
| 181 |
+
<strong>2-Way Split Used:</strong> {{ results.split_info }}<br>
|
| 182 |
+
<span class="small">Model trained and tested β Prediction is fully unlocked!</span>
|
| 183 |
+
</div>
|
| 184 |
+
</div>
|
| 185 |
+
{% endif %}
|
| 186 |
+
</div>
|
| 187 |
+
</div>
|
| 188 |
+
|
| 189 |
+
<!-- Download Section -->
|
| 190 |
+
<div class="row mb-4">
|
| 191 |
+
<div class="col-lg-8 mx-auto">
|
| 192 |
+
<div class="card shadow border-success">
|
| 193 |
+
<div class="card-body text-center">
|
| 194 |
+
<h4>
|
| 195 |
+
<i class="fas fa-download"></i> Download Your Model
|
| 196 |
+
</h4>
|
| 197 |
+
<p class="text-muted">
|
| 198 |
+
Save the trained model for future predictions
|
| 199 |
+
</p>
|
| 200 |
+
<a href="{{ url_for('download_model') }}" class="btn btn-success btn-lg">
|
| 201 |
+
<i class="fas fa-download"></i> Download Model (.pkl)
|
| 202 |
+
</a>
|
| 203 |
+
</div>
|
| 204 |
+
</div>
|
| 205 |
+
</div>
|
| 206 |
+
</div>
|
| 207 |
+
|
| 208 |
+
<!-- Deployable App Download Section -->
|
| 209 |
+
<div class="row mb-4">
|
| 210 |
+
<div class="col-lg-8 mx-auto">
|
| 211 |
+
<div class="card shadow border-primary" style="background: linear-gradient(135deg, #1e293b, #0f172a); border-width: 2px;">
|
| 212 |
+
<div class="card-body text-center py-4">
|
| 213 |
+
<div class="mb-3">
|
| 214 |
+
<span style="font-size: 3rem;">π</span>
|
| 215 |
+
</div>
|
| 216 |
+
<h4 class="text-white">
|
| 217 |
+
<i class="fas fa-box-open"></i> Download Deployable Web App
|
| 218 |
+
</h4>
|
| 219 |
+
<p class="text-white-50 mb-1">
|
| 220 |
+
Get a <strong class="text-info">complete, ready-to-run Flask application</strong> with your trained model built-in.
|
| 221 |
+
</p>
|
| 222 |
+
<p class="text-white-50 small mb-3">
|
| 223 |
+
Includes <code>app.py</code>, a beautiful <code>index.html</code>, model artifacts, and <code>requirements.txt</code>.<br>
|
| 224 |
+
Just unzip β <code>pip install -r requirements.txt</code> β <code>python app.py</code> and you're live!
|
| 225 |
+
</p>
|
| 226 |
+
<a href="{{ url_for('download_app') }}" class="btn btn-lg text-white px-5 py-3" style="background: linear-gradient(135deg, #6366f1, #4f46e5); border: none; border-radius: 14px; font-weight: 700; font-size: 1.1rem; transition: all 0.3s;" onmouseover="this.style.transform='translateY(-2px)'; this.style.boxShadow='0 12px 30px rgba(99,102,241,0.35)';" onmouseout="this.style.transform=''; this.style.boxShadow='';">
|
| 227 |
+
<i class="fas fa-file-zipper"></i> Download App (.zip)
|
| 228 |
+
</a>
|
| 229 |
+
<div class="mt-3">
|
| 230 |
+
<span class="badge bg-info"><i class="fas fa-code"></i> app.py</span>
|
| 231 |
+
<span class="badge bg-warning text-dark"><i class="fas fa-palette"></i> index.html</span>
|
| 232 |
+
<span class="badge bg-success"><i class="fas fa-brain"></i> model.pkl</span>
|
| 233 |
+
<span class="badge bg-secondary"><i class="fas fa-list"></i> requirements.txt</span>
|
| 234 |
+
</div>
|
| 235 |
+
</div>
|
| 236 |
+
</div>
|
| 237 |
+
</div>
|
| 238 |
+
</div>
|
| 239 |
+
|
| 240 |
+
<!-- Preprocessing Artifacts Download Section (only shown when applicable) -->
|
| 241 |
+
{% if model_state.scaling_applied or model_state.encoding_applied %}
|
| 242 |
+
<div class="row mb-4">
|
| 243 |
+
<div class="col-lg-8 mx-auto">
|
| 244 |
+
<div class="card shadow border-info">
|
| 245 |
+
<div class="card-header bg-info text-white">
|
| 246 |
+
<h5 class="mb-0">
|
| 247 |
+
<i class="fas fa-cogs"></i> Download Preprocessing Artifacts
|
| 248 |
+
</h5>
|
| 249 |
+
</div>
|
| 250 |
+
<div class="card-body">
|
| 251 |
+
<p class="text-muted small mb-3">
|
| 252 |
+
These fitted preprocessing objects were used during training.
|
| 253 |
+
Download and reuse them during inference to ensure consistent transformations.
|
| 254 |
+
</p>
|
| 255 |
+
<div class="d-flex flex-wrap gap-3 justify-content-center">
|
| 256 |
+
{% if model_state.scaling_applied %}
|
| 257 |
+
<a href="{{ url_for('download_scaler') }}" class="btn btn-outline-primary btn-lg">
|
| 258 |
+
<i class="fas fa-balance-scale"></i> Download Scaler (.pkl)
|
| 259 |
+
<span class="badge bg-primary ms-2">Numeric</span>
|
| 260 |
+
</a>
|
| 261 |
+
{% endif %}
|
| 262 |
+
{% if model_state.encoding_applied %}
|
| 263 |
+
<a href="{{ url_for('download_encoder') }}" class="btn btn-outline-warning btn-lg">
|
| 264 |
+
<i class="fas fa-tag"></i> Download Encoder (.pkl)
|
| 265 |
+
<span class="badge bg-warning text-dark ms-2">Categorical</span>
|
| 266 |
+
</a>
|
| 267 |
+
{% endif %}
|
| 268 |
+
</div>
|
| 269 |
+
</div>
|
| 270 |
+
</div>
|
| 271 |
+
</div>
|
| 272 |
+
</div>
|
| 273 |
+
{% endif %}
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
<!-- Actions -->
|
| 277 |
+
<div class="row">
|
| 278 |
+
<div class="col-lg-8 mx-auto">
|
| 279 |
+
<div class="d-grid gap-2">
|
| 280 |
+
{% if predict_unlocked %}
|
| 281 |
+
<a href="{{ url_for('predict') }}" class="btn btn-primary btn-lg">
|
| 282 |
+
<i class="fas fa-chart-line"></i> Make Predictions
|
| 283 |
+
<span class="badge bg-success ms-2">Unlocked</span>
|
| 284 |
+
</a>
|
| 285 |
+
{% else %}
|
| 286 |
+
<button class="btn btn-secondary btn-lg" disabled title="Retrain with 3-way split to unlock">
|
| 287 |
+
<i class="fas fa-lock"></i> Make Predictions
|
| 288 |
+
<span class="badge bg-dark ms-2">Locked β needs Train/Test/Val split</span>
|
| 289 |
+
</button>
|
| 290 |
+
{% endif %}
|
| 291 |
+
<a href="{{ url_for('index') }}" class="btn btn-outline-secondary">
|
| 292 |
+
<i class="fas fa-plus"></i> Train Another Model
|
| 293 |
+
</a>
|
| 294 |
+
</div>
|
| 295 |
+
</div>
|
| 296 |
+
</div>
|
| 297 |
+
</div>
|
| 298 |
+
|
| 299 |
+
<style>
|
| 300 |
+
.metric-box {
|
| 301 |
+
padding: 20px;
|
| 302 |
+
border-radius: 10px;
|
| 303 |
+
background-color: #f8f9fa;
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
.metric-box h3 {
|
| 307 |
+
font-size: 2.5rem;
|
| 308 |
+
font-weight: bold;
|
| 309 |
+
margin-bottom: 5px;
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
.metric-box p {
|
| 313 |
+
margin-bottom: 0;
|
| 314 |
+
font-weight: 500;
|
| 315 |
+
}
|
| 316 |
+
</style>
|
| 317 |
+
{% endblock %}
|