diabetes-predict / index.html
Soundaryasos's picture
Add 2 files
6295ad8 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Diabetes Prediction Ensemble</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/shap@0.41.0/dist/shap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.gradient-bg {
background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #a855f7 100%);
}
.feature-importance-bar {
transition: width 0.5s ease-in-out;
}
.model-card:hover {
transform: translateY(-5px);
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}
.shap-waterfall {
background-color: #f8fafc;
border-radius: 0.5rem;
padding: 1rem;
}
.input-highlight {
border-color: #4f46e5;
box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<!-- Header -->
<header class="gradient-bg text-white shadow-lg">
<div class="container mx-auto px-4 py-6">
<div class="flex justify-between items-center">
<div class="flex items-center space-x-3">
<i class="fas fa-heartbeat text-3xl"></i>
<h1 class="text-2xl font-bold">DiabetesPredict</h1>
</div>
<nav>
<ul class="flex space-x-6">
<li><a href="#" class="hover:text-gray-200 transition">Home</a></li>
</ul>
</nav>
</div>
</div>
</header>
<!-- Main Content -->
<main class="container mx-auto px-4 py-8">
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
<!-- Input Form Section -->
<div class="lg:col-span-1 bg-white rounded-xl shadow-md p-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Patient Information</h2>
<p class="text-gray-600 mb-6">Enter your health metrics to assess diabetes risk using our advanced ensemble model.</p>
<form id="predictionForm" class="space-y-4">
<div>
<label for="pregnancies" class="block text-sm font-medium text-gray-700 mb-1">Pregnancies</label>
<input type="number" id="pregnancies" name="pregnancies" min="0" max="20" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
</div>
<div>
<label for="glucose" class="block text-sm font-medium text-gray-700 mb-1">Glucose (mg/dL)</label>
<input type="number" id="glucose" name="glucose" min="0" max="300" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
</div>
<div>
<label for="bloodPressure" class="block text-sm font-medium text-gray-700 mb-1">Blood Pressure (mmHg)</label>
<input type="number" id="bloodPressure" name="bloodPressure" min="0" max="150" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
</div>
<div>
<label for="skinThickness" class="block text-sm font-medium text-gray-700 mb-1">Skin Thickness (mm)</label>
<input type="number" id="skinThickness" name="skinThickness" min="0" max="100" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
</div>
<div>
<label for="insulin" class="block text-sm font-medium text-gray-700 mb-1">Insulin (μU/mL)</label>
<input type="number" id="insulin" name="insulin" min="0" max="300" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
</div>
<div>
<label for="bmi" class="block text-sm font-medium text-gray-700 mb-1">BMI</label>
<input type="number" id="bmi" name="bmi" step="0.1" min="0" max="60" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
</div>
<div>
<label for="diabetesPedigree" class="block text-sm font-medium text-gray-700 mb-1">Diabetes Pedigree Function</label>
<input type="number" id="diabetesPedigree" name="diabetesPedigree" step="0.001" min="0" max="2.5" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
</div>
<div>
<label for="age" class="block text-sm font-medium text-gray-700 mb-1">Age (years)</label>
<input type="number" id="age" name="age" min="0" max="120" class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
</div>
<button type="submit" class="w-full gradient-bg text-white py-2 px-4 rounded-md hover:opacity-90 transition flex items-center justify-center space-x-2">
<i class="fas fa-chart-line"></i>
<span>Predict Diabetes Risk</span>
</button>
</form>
</div>
<!-- Results Section -->
<div class="lg:col-span-2 space-y-6">
<!-- Prediction Result Card -->
<div id="resultSection" class="hidden bg-white rounded-xl shadow-md p-6">
<div class="flex justify-between items-center mb-4">
<h2 class="text-xl font-semibold text-gray-800">Prediction Results</h2>
<div id="riskBadge" class="px-3 py-1 rounded-full text-sm font-medium"></div>
</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
<!-- Ensemble Prediction -->
<div class="bg-indigo-50 rounded-lg p-4">
<div class="flex justify-between items-center mb-2">
<h3 class="font-medium text-indigo-800">Ensemble Model</h3>
<i class="fas fa-project-diagram text-indigo-500"></i>
</div>
<div class="flex items-center space-x-2">
<div id="ensembleScore" class="text-2xl font-bold text-indigo-700">0.72</div>
<div class="text-sm text-gray-500">probability</div>
</div>
<div class="mt-2 h-2 w-full bg-gray-200 rounded-full overflow-hidden">
<div id="ensembleBar" class="h-full gradient-bg rounded-full"></div>
</div>
</div>
<!-- Individual Model Predictions -->
<div class="bg-green-50 rounded-lg p-4">
<div class="flex justify-between items-center mb-2">
<h3 class="font-medium text-green-800">Random Forest</h3>
<i class="fas fa-tree text-green-500"></i>
</div>
<div class="flex items-center space-x-2">
<div id="rfScore" class="text-2xl font-bold text-green-700">0.68</div>
<div class="text-sm text-gray-500">probability</div>
</div>
<div class="mt-2 h-2 w-full bg-gray-200 rounded-full overflow-hidden">
<div id="rfBar" class="h-full bg-green-500 rounded-full"></div>
</div>
</div>
<div class="bg-blue-50 rounded-lg p-4">
<div class="flex justify-between items-center mb-2">
<h3 class="font-medium text-blue-800">XGBoost</h3>
<i class="fas fa-rocket text-blue-500"></i>
</div>
<div class="flex items-center space-x-2">
<div id="xgbScore" class="text-2xl font-bold text-blue-700">0.75</div>
<div class="text-sm text-gray-500">probability</div>
</div>
<div class="mt-2 h-2 w-full bg-gray-200 rounded-full overflow-hidden">
<div id="xgbBar" class="h-full bg-blue-500 rounded-full"></div>
</div>
</div>
<div class="bg-purple-50 rounded-lg p-4">
<div class="flex justify-between items-center mb-2">
<h3 class="font-medium text-purple-800">Neural Network</h3>
<i class="fas fa-brain text-purple-500"></i>
</div>
<div class="flex items-center space-x-2">
<div id="nnScore" class="text-2xl font-bold text-purple-700">0.71</div>
<div class="text-sm text-gray-500">probability</div>
</div>
<div class="mt-2 h-2 w-full bg-gray-200 rounded-full overflow-hidden">
<div id="nnBar" class="h-full bg-purple-500 rounded-full"></div>
</div>
</div>
</div>
<!-- SHAP Explanation -->
<div class="mt-6">
<h3 class="text-lg font-medium text-gray-800 mb-3">Feature Importance Analysis</h3>
<div class="shap-waterfall mb-4">
<div id="shapWaterfall" class="h-64 flex items-center justify-center text-gray-400">
<p>SHAP waterfall plot will appear here after prediction</p>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<h4 class="text-sm font-medium text-gray-700 mb-2">Most Influential Features</h4>
<div id="topFeatures" class="space-y-2">
<!-- Will be populated by JavaScript -->
</div>
</div>
<div>
<h4 class="text-sm font-medium text-gray-700 mb-2">Recommendations</h4>
<div id="recommendations" class="text-sm text-gray-600 space-y-2">
<!-- Will be populated by JavaScript -->
</div>
</div>
</div>
</div>
</div>
<!-- Model Comparison Section -->
<div class="bg-white rounded-xl shadow-md p-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Model Performance Comparison</h2>
<p class="text-gray-600 mb-4">Our ensemble combines the strengths of three powerful machine learning models:</p>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<!-- Random Forest Card -->
<div class="model-card bg-white border border-gray-200 rounded-lg p-4 transition duration-300 hover:shadow-lg">
<div class="flex items-center space-x-3 mb-3">
<div class="bg-green-100 p-2 rounded-full">
<i class="fas fa-tree text-green-600"></i>
</div>
<h3 class="font-medium">Random Forest</h3>
</div>
<p class="text-sm text-gray-600 mb-3">An ensemble of decision trees that reduces overfitting and provides robust predictions.</p>
<div class="text-xs text-gray-500">
<div class="flex justify-between mb-1">
<span>Accuracy:</span>
<span class="font-medium">84.2%</span>
</div>
<div class="flex justify-between mb-1">
<span>Precision:</span>
<span class="font-medium">82.5%</span>
</div>
<div class="flex justify-between">
<span>Recall:</span>
<span class="font-medium">85.7%</span>
</div>
</div>
</div>
<!-- XGBoost Card -->
<div class="model-card bg-white border border-gray-200 rounded-lg p-4 transition duration-300 hover:shadow-lg">
<div class="flex items-center space-x-3 mb-3">
<div class="bg-blue-100 p-2 rounded-full">
<i class="fas fa-rocket text-blue-600"></i>
</div>
<h3 class="font-medium">XGBoost</h3>
</div>
<p class="text-sm text-gray-600 mb-3">A gradient boosting framework optimized for speed and performance with regularization.</p>
<div class="text-xs text-gray-500">
<div class="flex justify-between mb-1">
<span>Accuracy:</span>
<span class="font-medium">86.1%</span>
</div>
<div class="flex justify-between mb-1">
<span>Precision:</span>
<span class="font-medium">84.3%</span>
</div>
<div class="flex justify-between">
<span>Recall:</span>
<span class="font-medium">87.9%</span>
</div>
</div>
</div>
<!-- Neural Network Card -->
<div class="model-card bg-white border border-gray-200 rounded-lg p-4 transition duration-300 hover:shadow-lg">
<div class="flex items-center space-x-3 mb-3">
<div class="bg-purple-100 p-2 rounded-full">
<i class="fas fa-brain text-purple-600"></i>
</div>
<h3 class="font-medium">Neural Network</h3>
</div>
<p class="text-sm text-gray-600 mb-3">A deep learning model that captures complex non-linear relationships in the data.</p>
<div class="text-xs text-gray-500">
<div class="flex justify-between mb-1">
<span>Accuracy:</span>
<span class="font-medium">83.7%</span>
</div>
<div class="flex justify-between mb-1">
<span>Precision:</span>
<span class="font-medium">81.9%</span>
</div>
<div class="flex justify-between">
<span>Recall:</span>
<span class="font-medium">84.2%</span>
</div>
</div>
</div>
</div>
<div class="mt-6">
<h3 class="text-md font-medium text-gray-800 mb-2">Ensemble Performance</h3>
<div class="bg-gray-50 p-4 rounded-lg">
<div class="flex items-center space-x-2 mb-3">
<i class="fas fa-star text-yellow-500"></i>
<p class="text-sm text-gray-700">Our weighted ensemble achieves <span class="font-medium">88.3% accuracy</span> by combining the predictions of all three models.</p>
</div>
<canvas id="performanceChart" height="150"></canvas>
</div>
</div>
</div>
</div>
</div>
</main>
<!-- Footer -->
<footer class="bg-gray-800 text-white py-8">
<div class="container mx-auto px-4">
<div class="grid grid-cols-1 md:grid-cols-3 gap-8">
<div>
<h3 class="text-lg font-semibold mb-4">DiabetesPredict</h3>
<p class="text-gray-400">An advanced diabetes risk assessment tool using ensemble machine learning with explainable AI.</p>
</div>
<div>
<h3 class="text-lg font-semibold mb-4">Quick Links</h3>
<ul class="space-y-2">
<li><a href="#" class="text-gray-400 hover:text-white transition">Home</a></li>
</ul>
</div>
<div>
<h3 class="text-lg font-semibold mb-4">Contact</h3>
<ul class="space-y-2 text-gray-400">
<li class="flex items-center space-x-2">
<i class="fas fa-envelope"></i>
<span>contact@diabetespredict.org</span>
</li>
<li class="flex items-center space-x-2">
<i class="fas fa-phone"></i>
<span>+1 (555) 123-4567</span>
</li>
<li class="flex items-center space-x-2">
<i class="fas fa-map-marker-alt"></i>
<span>123 Health Lane, Boston, MA</span>
</li>
</ul>
</div>
</div>
<div class="border-t border-gray-700 mt-8 pt-6 text-center text-gray-400">
<p>© 2023 DiabetesPredict. All rights reserved.</p>
<p class="text-xs mt-2">Disclaimer: This tool is for informational purposes only and not a substitute for professional medical advice.</p>
</div>
</div>
</footer>
<script>
// Initialize performance chart
document.addEventListener('DOMContentLoaded', function() {
const ctx = document.getElementById('performanceChart').getContext('2d');
const performanceChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['Random Forest', 'XGBoost', 'Neural Network', 'Ensemble'],
datasets: [{
label: 'Accuracy (%)',
data: [84.2, 86.1, 83.7, 88.3],
backgroundColor: [
'rgba(16, 185, 129, 0.7)',
'rgba(59, 130, 246, 0.7)',
'rgba(168, 85, 247, 0.7)',
'rgba(79, 70, 229, 0.7)'
],
borderColor: [
'rgba(16, 185, 129, 1)',
'rgba(59, 130, 246, 1)',
'rgba(168, 85, 247, 1)',
'rgba(79, 70, 229, 1)'
],
borderWidth: 1
}]
},
options: {
responsive: true,
scales: {
y: {
beginAtZero: true,
max: 100,
title: {
display: true,
text: 'Accuracy (%)'
}
}
},
plugins: {
legend: {
display: false
}
}
}
});
// Highlight inputs on focus
const inputs = document.querySelectorAll('input');
inputs.forEach(input => {
input.addEventListener('focus', function() {
this.classList.add('input-highlight');
});
input.addEventListener('blur', function() {
this.classList.remove('input-highlight');
});
});
});
// Form submission handler
document.getElementById('predictionForm').addEventListener('submit', function(e) {
e.preventDefault();
// Show loading state
const submitBtn = this.querySelector('button[type="submit"]');
const originalBtnText = submitBtn.innerHTML;
submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Processing...';
submitBtn.disabled = true;
// Simulate API call with timeout
setTimeout(() => {
// Generate random probabilities for demo purposes
const rfProb = (Math.random() * 0.3 + 0.5).toFixed(2);
const xgbProb = (Math.random() * 0.3 + 0.5).toFixed(2);
const nnProb = (Math.random() * 0.3 + 0.5).toFixed(2);
const ensembleProb = ((parseFloat(rfProb) + parseFloat(xgbProb) + parseFloat(nnProb)) / 3).toFixed(2);
// Update UI with results
document.getElementById('rfScore').textContent = rfProb;
document.getElementById('xgbScore').textContent = xgbProb;
document.getElementById('nnScore').textContent = nnProb;
document.getElementById('ensembleScore').textContent = ensembleProb;
// Update progress bars
document.getElementById('rfBar').style.width = `${rfProb * 100}%`;
document.getElementById('xgbBar').style.width = `${xgbProb * 100}%`;
document.getElementById('nnBar').style.width = `${nnProb * 100}%`;
document.getElementById('ensembleBar').style.width = `${ensembleProb * 100}%`;
// Set risk level
const riskBadge = document.getElementById('riskBadge');
if (ensembleProb >= 0.7) {
riskBadge.textContent = 'High Risk';
riskBadge.className = 'px-3 py-1 rounded-full text-sm font-medium bg-red-100 text-red-800';
} else if (ensembleProb >= 0.5) {
riskBadge.textContent = 'Moderate Risk';
riskBadge.className = 'px-3 py-1 rounded-full text-sm font-medium bg-yellow-100 text-yellow-800';
} else {
riskBadge.textContent = 'Low Risk';
riskBadge.className = 'px-3 py-1 rounded-full text-sm font-medium bg-green-100 text-green-800';
}
// Generate SHAP explanation (simulated)
const shapWaterfall = document.getElementById('shapWaterfall');
shapWaterfall.innerHTML = `
<div class="text-center">
<p class="text-sm text-gray-500 mb-2">SHAP values show how each feature contributes to the prediction</p>
<div class="inline-block bg-white p-4 rounded-lg shadow">
<div class="flex items-center justify-center space-x-2 mb-2">
<div class="w-4 h-4 bg-blue-500"></div>
<span class="text-xs">Positive impact</span>
<div class="w-4 h-4 bg-red-500 ml-2"></div>
<span class="text-xs">Negative impact</span>
</div>
<div class="h-40 w-64 bg-gradient-to-r from-red-500 via-gray-200 to-blue-500 rounded"></div>
</div>
</div>
`;
// Generate top features
const features = [
{name: 'Glucose', value: (Math.random() * 0.3 + 0.1).toFixed(2), impact: Math.random() > 0.5 ? 'positive' : 'negative'},
{name: 'BMI', value: (Math.random() * 0.2 + 0.1).toFixed(2), impact: Math.random() > 0.5 ? 'positive' : 'negative'},
{name: 'Age', value: (Math.random() * 0.2 + 0.05).toFixed(2), impact: Math.random() > 0.5 ? 'positive' : 'negative'},
{name: 'Diabetes Pedigree', value: (Math.random() * 0.15 + 0.05).toFixed(2), impact: Math.random() > 0.5 ? 'positive' : 'negative'},
{name: 'Blood Pressure', value: (Math.random() * 0.1 + 0.05).toFixed(2), impact: Math.random() > 0.5 ? 'positive' : 'negative'}
];
// Sort by absolute value
features.sort((a, b) => Math.abs(b.value) - Math.abs(a.value));
const topFeaturesContainer = document.getElementById('topFeatures');
topFeaturesContainer.innerHTML = '';
features.forEach(feat => {
const featureEl = document.createElement('div');
featureEl.className = 'flex items-center justify-between';
const nameEl = document.createElement('span');
nameEl.className = 'text-sm font-medium';
nameEl.textContent = feat.name;
const valueEl = document.createElement('div');
valueEl.className = 'flex items-center';
const icon = document.createElement('i');
icon.className = `fas ${feat.impact === 'positive' ? 'fa-arrow-up text-red-500' : 'fa-arrow-down text-blue-500'} mr-1`;
const valueText = document.createElement('span');
valueText.className = 'text-sm';
valueText.textContent = feat.value;
valueEl.appendChild(icon);
valueEl.appendChild(valueText);
featureEl.appendChild(nameEl);
featureEl.appendChild(valueEl);
topFeaturesContainer.appendChild(featureEl);
});
// Generate recommendations
const recommendations = [
'Monitor glucose levels regularly',
'Maintain a healthy BMI through diet and exercise',
'Schedule regular check-ups with your doctor',
'Consider lifestyle changes to reduce risk factors'
];
const recommendationsContainer = document.getElementById('recommendations');
recommendationsContainer.innerHTML = '';
recommendations.forEach(rec => {
const recEl = document.createElement('div');
recEl.className = 'flex items-start space-x-2';
const icon = document.createElement('i');
icon.className = 'fas fa-check-circle text-green-500 mt-0.5';
const text = document.createElement('p');
text.textContent = rec;
recEl.appendChild(icon);
recEl.appendChild(text);
recommendationsContainer.appendChild(recEl);
});
// Show results section
document.getElementById('resultSection').classList.remove('hidden');
// Reset button
submitBtn.innerHTML = originalBtnText;
submitBtn.disabled = false;
}, 1500);
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Soundaryasos/diabetes-predict" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>