Download index.html from MarcRyan/spe: direct link, hf CLI and curl.
- Browser
- Download file 48.6 kB
-
https://huggingface.co/spaces/MarcRyan/spe/resolve/main/index.html
- Command line
-
hf download hf://spaces/MarcRyan/spe/index.html
-
curl -L -o index.html https://huggingface.co/spaces/MarcRyan/spe/resolve/main/index.html
48.6 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Soccer Prediction Neural Network</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://unpkg.com/brain.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.neuron {
transition: all 0.3s ease;
}
.neuron:hover {
transform: scale(1.1);
box-shadow: 0 0 15px rgba(59, 130, 246, 0.6);
}
.connection {
stroke-dasharray: 1000;
stroke-dashoffset: 1000;
animation: dash 2s linear forwards;
}
@keyframes dash {
to {
stroke-dashoffset: 0;
}
}
.pulse {
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0% {
transform: scale(0.95);
box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.7);
}
70% {
transform: scale(1);
box-shadow: 0 0 0 10px rgba(220, 38, 38, 0);
}
100% {
transform: scale(0.95);
box-shadow: 0 0 0 0 rgba(220, 38, 38, 0);
}
}
.team-card {
transition: all 0.3s ease;
}
.team-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}
.progress-ring__circle {
transition: stroke-dashoffset 0.5s;
transform: rotate(-90deg);
transform-origin: 50% 50%;
}
.stat-badge {
font-size: 0.7rem;
padding: 0.2rem 0.4rem;
border-radius: 0.25rem;
}
.offensive-stat {
background-color: #3B82F6;
color: white;
}
.defensive-stat {
background-color: #EF4444;
color: white;
}
.teamwork-stat {
background-color: #10B981;
color: white;
}
.discipline-stat {
background-color: #F59E0B;
color: white;
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="container mx-auto px-4 py-8">
<header class="mb-12 text-center">
<h1 class="text-4xl font-bold text-green-600 mb-2">
<i class="fas fa-futbol mr-3"></i>Advanced Soccer Prediction Engine
</h1>
<p class="text-gray-600 max-w-3xl mx-auto">
Comprehensive neural network analysis using 12 key performance metrics to predict match outcomes.
The system learns from extensive soccer statistics to provide accurate loss probability predictions.
</p>
</header>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
<!-- Control Panel -->
<div class="bg-white rounded-xl shadow-lg p-6 h-fit">
<h2 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
<i class="fas fa-sliders-h mr-2 text-green-500"></i>Network Configuration
</h2>
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Hidden Layers</label>
<input type="range" id="hiddenLayers" min="1" max="5" value="3" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer">
<div class="flex justify-between text-xs text-gray-500 mt-1">
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
<span>5</span>
</div>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Neurons per Layer</label>
<input type="range" id="neuronsPerLayer" min="2" max="20" value="12" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer">
<div class="flex justify-between text-xs text-gray-500 mt-1">
<span>2</span>
<span>6</span>
<span>12</span>
<span>16</span>
<span>20</span>
</div>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Learning Rate</label>
<input type="range" id="learningRate" min="0.01" max="0.5" step="0.01" value="0.2" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer">
<div class="flex justify-between text-xs text-gray-500 mt-1">
<span>0.01</span>
<span>0.25</span>
<span>0.5</span>
</div>
</div>
<div class="pt-2">
<button id="trainBtn" class="w-full bg-green-600 hover:bg-green-700 text-white font-medium py-2 px-4 rounded-lg transition duration-200 flex items-center justify-center">
<i class="fas fa-brain mr-2"></i>
Train Network
</button>
</div>
</div>
<div class="mt-6 pt-4 border-t border-gray-200">
<h3 class="text-sm font-medium text-gray-700 mb-2 flex items-center">
<i class="fas fa-database mr-2 text-green-500"></i>Training Data Parameters
</h3>
<div class="grid grid-cols-2 gap-3">
<div>
<label class="block text-xs font-medium text-gray-500 mb-1">Seasons</label>
<select id="seasonRange" class="w-full text-sm border rounded px-2 py-1">
<option value="5">Last 5 seasons</option>
<option value="10" selected>Last 10 seasons</option>
<option value="15">Last 15 seasons</option>
</select>
</div>
<div>
<label class="block text-xs font-medium text-gray-500 mb-1">Stat Weight</label>
<select id="statWeight" class="w-full text-sm border rounded px-2 py-1">
<option value="balanced">Balanced</option>
<option value="offense">Offense-heavy</option>
<option value="defense">Defense-heavy</option>
</select>
</div>
</div>
</div>
</div>
<!-- Network Visualization -->
<div class="lg:col-span-2">
<div class="bg-white rounded-xl shadow-lg p-6">
<div class="flex justify-between items-center mb-4">
<h2 class="text-xl font-semibold text-gray-800 flex items-center">
<i class="fas fa-project-diagram mr-2 text-green-500"></i>Network Architecture
</h2>
<div class="flex space-x-2">
<button id="resetBtn" class="text-sm bg-gray-200 hover:bg-gray-300 text-gray-800 py-1 px-3 rounded flex items-center">
<i class="fas fa-redo mr-1 text-xs"></i> Reset
</button>
</div>
</div>
<div class="relative h-96 w-full bg-gray-50 rounded-lg overflow-hidden">
<svg id="networkDiagram" class="w-full h-full">
<!-- Network will be rendered here -->
</svg>
<div id="loadingOverlay" class="absolute inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden">
<div class="bg-white p-4 rounded-lg flex items-center shadow-lg">
<svg class="animate-spin -ml-1 mr-3 h-5 w-5 text-green-600" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
<span class="text-gray-800">Training network with soccer data...</span>
</div>
</div>
</div>
<div class="mt-6 grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="bg-gray-50 p-4 rounded-lg">
<h3 class="text-sm font-medium text-gray-700 mb-2 flex items-center">
<i class="fas fa-chart-line mr-2 text-green-500"></i>Team Performance Input
</h3>
<div class="grid grid-cols-2 gap-2">
<!-- Offensive Stats -->
<div>
<label class="block text-xs font-medium text-gray-500 mb-1 flex items-center">
<span class="stat-badge offensive-stat mr-1">OFF</span> Shots on Target
</label>
<input type="number" id="shotsOnTargetInput" min="100" max="300" step="1" value="180" class="w-full px-2 py-1 border rounded text-sm">
</div>
<div>
<label class="block text-xs font-medium text-gray-500 mb-1 flex items-center">
<span class="stat-badge offensive-stat mr-1">OFF</span> Goals Scored
</label>
<input type="number" id="goalsScoredInput" min="30" max="100" step="1" value="65" class="w-full px-2 py-1 border rounded text-sm">
</div>
<div>
<label class="block text-xs font-medium text-gray-500 mb-1 flex items-center">
<span class="stat-badge offensive-stat mr-1">OFF</span> Key Passes
</label>
<input type="number" id="keyPassesInput" min="200" max="600" step="1" value="400" class="w-full px-2 py-1 border rounded text-sm">
</div>
<div>
<label class="block text-xs font-medium text-gray-500 mb-1 flex items-center">
<span class="stat-badge offensive-stat mr-1">OFF</span> Dribbles
</label>
<input type="number" id="dribblesInput" min="100" max="500" step="1" value="300" class="w-full px-2 py-1 border rounded text-sm">
</div>
<!-- Defensive Stats -->
<div>
<label class="block text-xs font-medium text-gray-500 mb-1 flex items-center">
<span class="stat-badge defensive-stat mr-1">DEF</span> Goals Conceded
</label>
<input type="number" id="goalsConcededInput" min="20" max="80" step="1" value="40" class="w-full px-2 py-1 border rounded text-sm">
</div>
<div>
<label class="block text-xs font-medium text-gray-500 mb-1 flex items-center">
<span class="stat-badge defensive-stat mr-1">DEF</span> Tackles
</label>
<input type="number" id="tacklesInput" min="300" max="800" step="1" value="500" class="w-full px-2 py-1 border rounded text-sm">
</div>
<div>
<label class="block text-xs font-medium text-gray-500 mb-1 flex items-center">
<span class="stat-badge defensive-stat mr-1">DEF</span> Interceptions
</label>
<input type="number" id="interceptionsInput" min="200" max="600" step="1" value="400" class="w-full px-2 py-1 border rounded text-sm">
</div>
<div>
<label class="block text-xs font-medium text-gray-500 mb-1 flex items-center">
<span class="stat-badge defensive-stat mr-1">DEF</span> Clearances
</label>
<input type="number" id="clearancesInput" min="300" max="900" step="1" value="600" class="w-full px-2 py-1 border rounded text-sm">
</div>
<!-- Teamwork Stats -->
<div>
<label class="block text-xs font-medium text-gray-500 mb-1 flex items-center">
<span class="stat-badge teamwork-stat mr-1">TMW</span> Pass Accuracy %
</label>
<input type="number" id="passAccuracyInput" min="70" max="90" step="0.1" value="80" class="w-full px-2 py-1 border rounded text-sm">
</div>
<div>
<label class="block text-xs font-medium text-gray-500 mb-1 flex items-center">
<span class="stat-badge teamwork-stat mr-1">TMW</span> Cross Accuracy %
</label>
<input type="number" id="crossAccuracyInput" min="20" max="50" step="0.1" value="35" class="w-full px-2 py-1 border rounded text-sm">
</div>
<!-- Discipline Stats -->
<div>
<label class="block text-xs font-medium text-gray-500 mb-1 flex items-center">
<span class="stat-badge discipline-stat mr-1">DSC</span> Yellow Cards
</label>
<input type="number" id="yellowCardsInput" min="30" max="100" step="1" value="60" class="w-full px-2 py-1 border rounded text-sm">
</div>
<div>
<label class="block text-xs font-medium text-gray-500 mb-1 flex items-center">
<span class="stat-badge discipline-stat mr-1">DSC</span> Red Cards
</label>
<input type="number" id="redCardsInput" min="0" max="10" step="1" value="3" class="w-full px-2 py-1 border rounded text-sm">
</div>
</div>
</div>
<div class="bg-gray-50 p-4 rounded-lg">
<h3 class="text-sm font-medium text-gray-700 mb-2 flex items-center">
<i class="fas fa-percentage mr-2 text-green-500"></i>Loss Probability
</h3>
<div class="flex items-center">
<div class="relative w-16 h-16 mr-4">
<svg class="w-full h-full" viewBox="0 0 36 36">
<path
d="M18 2.0845
a 15.9155 15.9155 0 0 1 0 31.831
a 15.9155 15.9155 0 0 1 0 -31.831"
fill="none"
stroke="#E5E7EB"
stroke-width="3"
/>
<path
id="progressRing"
d="M18 2.0845
a 15.9155 15.9155 0 0 1 0 31.831
a 15.9155 15.9155 0 0 1 0 -31.831"
fill="none"
stroke="#EF4444"
stroke-width="3"
stroke-dasharray="100, 100"
/>
</svg>
<div id="lossPercentage" class="absolute inset-0 flex items-center justify-center text-lg font-bold text-red-600">0%</div>
</div>
<div class="flex-1">
<div class="text-xs text-gray-500 mb-1">Prediction Confidence</div>
<div class="w-full bg-gray-200 rounded-full h-2">
<div id="confidenceBar" class="bg-green-600 h-2 rounded-full" style="width: 0%"></div>
</div>
<div id="predictionText" class="text-sm mt-2 font-medium text-gray-700">Enter team stats to predict</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Team Prediction Cards -->
<div class="mt-8">
<h2 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
<i class="fas fa-table mr-2 text-green-500"></i>Team Loss Predictions
</h2>
<div id="teamPredictions" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
<!-- Team cards will be dynamically inserted here -->
</div>
</div>
<!-- Training Progress -->
<div class="mt-8 bg-white rounded-xl shadow-lg p-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
<i class="fas fa-chart-bar mr-2 text-green-500"></i>Training Progress
</h2>
<canvas id="errorChart" class="w-full h-64"></canvas>
</div>
<!-- Soccer Statistics Explanation -->
<div class="mt-8 bg-white rounded-xl shadow-lg p-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
<i class="fas fa-info-circle mr-2 text-green-500"></i>Key Soccer Metrics
</h2>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
<!-- Offensive Stats -->
<div class="bg-blue-50 p-4 rounded-lg">
<h3 class="font-medium text-blue-800 mb-1 flex items-center">
<span class="stat-badge offensive-stat mr-2">OFF</span> Offensive Metrics
</h3>
<ul class="text-sm text-blue-600 space-y-1">
<li><strong>Shots on Target:</strong> Direct attempts on goal</li>
<li><strong>Goals Scored:</strong> Total goals per season</li>
<li><strong>Key Passes:</strong> Passes leading to shots</li>
<li><strong>Dribbles:</strong> Successful player runs</li>
</ul>
</div>
<!-- Defensive Stats -->
<div class="bg-red-50 p-4 rounded-lg">
<h3 class="font-medium text-red-800 mb-1 flex items-center">
<span class="stat-badge defensive-stat mr-2">DEF</span> Defensive Metrics
</h3>
<ul class="text-sm text-red-600 space-y-1">
<li><strong>Goals Conceded:</strong> Goals allowed</li>
<li><strong>Tackles:</strong> Successful defensive challenges</li>
<li><strong>Interceptions:</strong> Passes intercepted</li>
<li><strong>Clearances:</strong> Defensive removals</li>
</ul>
</div>
<!-- Teamwork Stats -->
<div class="bg-green-50 p-4 rounded-lg">
<h3 class="font-medium text-green-800 mb-1 flex items-center">
<span class="stat-badge teamwork-stat mr-2">TMW</span> Teamwork Metrics
</h3>
<ul class="text-sm text-green-600 space-y-1">
<li><strong>Pass Accuracy:</strong> Successful pass percentage</li>
<li><strong>Cross Accuracy:</strong> Successful crosses</li>
</ul>
</div>
<!-- Discipline Stats -->
<div class="bg-yellow-50 p-4 rounded-lg">
<h3 class="font-medium text-yellow-800 mb-1 flex items-center">
<span class="stat-badge discipline-stat mr-2">DSC</span> Discipline Metrics
</h3>
<ul class="text-sm text-yellow-600 space-y-1">
<li><strong>Yellow Cards:</strong> Cautions received</li>
<li><strong>Red Cards:</strong> Ejections received</li>
</ul>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Configuration
const config = {
hiddenLayers: 3,
neuronsPerLayer: 12,
learningRate: 0.2,
iterations: 20000,
errorThresh: 0.005
};
// Sample soccer team data (in a real app, this would come from an API)
const soccerTeams = [
{
name: "Manchester City",
logo: "⚽",
goalsConceded: 32,
shotsOnTarget: 280,
goalsScored: 85,
keyPasses: 450,
dribbles: 350,
passAccuracy: 89.2,
crossAccuracy: 38.5,
tackles: 520,
interceptions: 480,
clearances: 580,
yellowCards: 45,
redCards: 1
},
{
name: "Liverpool",
logo: "⚽",
goalsConceded: 38,
shotsOnTarget: 265,
goalsScored: 78,
keyPasses: 420,
dribbles: 320,
passAccuracy: 85.7,
crossAccuracy: 36.2,
tackles: 550,
interceptions: 460,
clearances: 620,
yellowCards: 52,
redCards: 2
},
{
name: "Chelsea",
logo: "⚽",
goalsConceded: 45,
shotsOnTarget: 240,
goalsScored: 70,
keyPasses: 400,
dribbles: 290,
passAccuracy: 84.1,
crossAccuracy: 34.8,
tackles: 580,
interceptions: 440,
clearances: 650,
yellowCards: 58,
redCards: 3
},
{
name: "Tottenham",
logo: "⚽",
goalsConceded: 48,
shotsOnTarget: 225,
goalsScored: 68,
keyPasses: 380,
dribbles: 270,
passAccuracy: 82.3,
crossAccuracy: 33.5,
tackles: 600,
interceptions: 420,
clearances: 680,
yellowCards: 62,
redCards: 4
},
{
name: "Arsenal",
logo: "⚽",
goalsConceded: 42,
shotsOnTarget: 235,
goalsScored: 72,
keyPasses: 390,
dribbles: 280,
passAccuracy: 83.5,
crossAccuracy: 35.1,
tackles: 570,
interceptions: 430,
clearances: 630,
yellowCards: 55,
redCards: 2
},
{
name: "Manchester Utd",
logo: "⚽",
goalsConceded: 51,
shotsOnTarget: 210,
goalsScored: 65,
keyPasses: 370,
dribbles: 260,
passAccuracy: 81.8,
crossAccuracy: 32.7,
tackles: 620,
interceptions: 410,
clearances: 700,
yellowCards: 68,
redCards: 5
},
{
name: "Leicester",
logo: "⚽",
goalsConceded: 54,
shotsOnTarget: 195,
goalsScored: 60,
keyPasses: 350,
dribbles: 240,
passAccuracy: 79.6,
crossAccuracy: 31.2,
tackles: 640,
interceptions: 400,
clearances: 720,
yellowCards: 72,
redCards: 6
},
{
name: "West Ham",
logo: "⚽",
goalsConceded: 58,
shotsOnTarget: 185,
goalsScored: 58,
keyPasses: 340,
dribbles: 230,
passAccuracy: 78.2,
crossAccuracy: 30.5,
tackles: 660,
interceptions: 390,
clearances: 750,
yellowCards: 78,
redCards: 7
}
];
// DOM Elements
const diagram = document.getElementById('networkDiagram');
const hiddenLayersInput = document.getElementById('hiddenLayers');
const neuronsPerLayerInput = document.getElementById('neuronsPerLayer');
const learningRateInput = document.getElementById('learningRate');
const trainBtn = document.getElementById('trainBtn');
const resetBtn = document.getElementById('resetBtn');
// Input elements for all 12 stats
const goalsConcededInput = document.getElementById('goalsConcededInput');
const shotsOnTargetInput = document.getElementById('shotsOnTargetInput');
const goalsScoredInput = document.getElementById('goalsScoredInput');
const keyPassesInput = document.getElementById('keyPassesInput');
const dribblesInput = document.getElementById('dribblesInput');
const passAccuracyInput = document.getElementById('passAccuracyInput');
const crossAccuracyInput = document.getElementById('crossAccuracyInput');
const tacklesInput = document.getElementById('tacklesInput');
const interceptionsInput = document.getElementById('interceptionsInput');
const clearancesInput = document.getElementById('clearancesInput');
const yellowCardsInput = document.getElementById('yellowCardsInput');
const redCardsInput = document.getElementById('redCardsInput');
const lossPercentage = document.getElementById('lossPercentage');
const confidenceBar = document.getElementById('confidenceBar');
const predictionText = document.getElementById('predictionText');
const progressRing = document.getElementById('progressRing');
const loadingOverlay = document.getElementById('loadingOverlay');
const teamPredictions = document.getElementById('teamPredictions');
const seasonRange = document.getElementById('seasonRange');
const statWeight = document.getElementById('statWeight');
// Initialize network
let net = new brain.NeuralNetwork();
let errorChart;
// Initialize UI
initUI();
drawNetwork();
initChart();
renderTeamCards();
// Event Listeners
hiddenLayersInput.addEventListener('input', updateConfig);
neuronsPerLayerInput.addEventListener('input', updateConfig);
learningRateInput.addEventListener('input', updateConfig);
trainBtn.addEventListener('click', trainNetwork);
resetBtn.addEventListener('click', resetNetwork);
// Add input event listeners for all stat inputs
[
goalsConcededInput, shotsOnTargetInput, goalsScoredInput,
keyPassesInput, dribblesInput, passAccuracyInput,
crossAccuracyInput, tacklesInput, interceptionsInput,
clearancesInput, yellowCardsInput, redCardsInput
].forEach(input => {
input.addEventListener('input', () => {
// Only predict if network is trained
if (net.trainOpts) {
predictLossProbability();
}
});
});
// Functions
function initUI() {
hiddenLayersInput.value = config.hiddenLayers;
neuronsPerLayerInput.value = config.neuronsPerLayer;
learningRateInput.value = config.learningRate;
}
function updateConfig() {
config.hiddenLayers = parseInt(hiddenLayersInput.value);
config.neuronsPerLayer = parseInt(neuronsPerLayerInput.value);
config.learningRate = parseFloat(learningRateInput.value);
drawNetwork();
}
function resetNetwork() {
net = new brain.NeuralNetwork();
drawNetwork();
resetChart();
lossPercentage.textContent = '0%';
progressRing.setAttribute('stroke-dasharray', '0, 100');
confidenceBar.style.width = '0%';
predictionText.textContent = 'Enter team stats to predict';
}
function trainNetwork() {
loadingOverlay.classList.remove('hidden');
trainBtn.disabled = true;
// Generate synthetic training data based on soccer stats
const trainingData = generateTrainingData();
// Configure network
const networkConfig = {
hiddenLayers: Array(config.hiddenLayers).fill(config.neuronsPerLayer),
learningRate: config.learningRate,
iterations: config.iterations,
errorThresh: config.errorThresh,
log: true,
logPeriod: 1000,
callback: function(info) {
updateChart(info.iterations, info.error);
},
callbackPeriod: 1000
};
// Train in a timeout to allow UI to update
setTimeout(() => {
net.train(trainingData, networkConfig);
loadingOverlay.classList.add('hidden');
trainBtn.disabled = false;
drawNetwork();
// After training, update predictions for all teams
updateAllTeamPredictions();
// Also predict for the current input values
predictLossProbability();
}, 100);
}
function generateTrainingData() {
// In a real application, this would be actual historical soccer data
// For this demo, we generate synthetic data that follows general trends:
// More goals conceded, fewer shots on target, lower pass accuracy, more yellow cards = more likely to lose
const data = [];
const seasons = parseInt(seasonRange.value);
const weight = statWeight.value;
// Generate data for multiple seasons
for (let i = 0; i < seasons * 100; i++) {
// Random stats within realistic ranges
const goalsConceded = Math.floor(randomInRange(20, 80));
const shotsOnTarget = Math.floor(randomInRange(100, 300));
const goalsScored = Math.floor(randomInRange(30, 100));
const keyPasses = Math.floor(randomInRange(200, 600));
const dribbles = Math.floor(randomInRange(100, 500));
const passAccuracy = randomInRange(70, 90);
const crossAccuracy = randomInRange(20, 50);
const tackles = Math.floor(randomInRange(300, 800));
const interceptions = Math.floor(randomInRange(200, 600));
const clearances = Math.floor(randomInRange(300, 900));
const yellowCards = Math.floor(randomInRange(30, 100));
const redCards = Math.floor(randomInRange(0, 10));
// Calculate loss probability based on stats
let lossProbability;
if (weight === 'offense') {
// More weight on offensive stats
lossProbability = (
(0.1 * normalize(goalsConceded, 20, 80)) +
(0.2 * (1 - normalize(shotsOnTarget, 100, 300))) +
(0.2 * (1 - normalize(goalsScored, 30, 100))) +
(0.15 * (1 - normalize(keyPasses, 200, 600))) +
(0.15 * (1 - normalize(dribbles, 100, 500))) +
(0.1 * (1 - normalize(passAccuracy, 70, 90))) +
(0.05 * (1 - normalize(crossAccuracy, 20, 50))) +
(0.025 * normalize(tackles, 300, 800)) +
(0.025 * normalize(interceptions, 200, 600)) +
(0.025 * normalize(clearances, 300, 900)) +
(0.025 * normalize(yellowCards, 30, 100)) +
(0.025 * normalize(redCards, 0, 10))
);
} else if (weight === 'defense') {
// More weight on defensive stats
lossProbability = (
(0.3 * normalize(goalsConceded, 20, 80)) +
(0.05 * (1 - normalize(shotsOnTarget, 100, 300))) +
(0.05 * (1 - normalize(goalsScored, 30, 100))) +
(0.05 * (1 - normalize(keyPasses, 200, 600))) +
(0.05 * (1 - normalize(dribbles, 100, 500))) +
(0.1 * (1 - normalize(passAccuracy, 70, 90))) +
(0.05 * (1 - normalize(crossAccuracy, 20, 50))) +
(0.1 * normalize(tackles, 300, 800)) +
(0.1 * normalize(interceptions, 200, 600)) +
(0.1 * normalize(clearances, 300, 900)) +
(0.05 * normalize(yellowCards, 30, 100)) +
(0.05 * normalize(redCards, 0, 10))
);
} else {
// Balanced approach
lossProbability = (
(0.15 * normalize(goalsConceded, 20, 80)) +
(0.1 * (1 - normalize(shotsOnTarget, 100, 300))) +
(0.1 * (1 - normalize(goalsScored, 30, 100))) +
(0.1 * (1 - normalize(keyPasses, 200, 600))) +
(0.1 * (1 - normalize(dribbles, 100, 500))) +
(0.1 * (1 - normalize(passAccuracy, 70, 90))) +
(0.05 * (1 - normalize(crossAccuracy, 20, 50))) +
(0.1 * normalize(tackles, 300, 800)) +
(0.1 * normalize(interceptions, 200, 600)) +
(0.05 * normalize(clearances, 300, 900)) +
(0.025 * normalize(yellowCards, 30, 100)) +
(0.025 * normalize(redCards, 0, 10))
);
}
// Add some randomness
lossProbability += randomInRange(-0.1, 0.1);
lossProbability = Math.max(0, Math.min(1, lossProbability));
// Determine if this would be a loss (1) or win (0)
const outcome = lossProbability > 0.5 ? 1 : 0;
// Add to training data
data.push({
input: [
normalize(goalsConceded, 20, 80),
normalize(shotsOnTarget, 100, 300),
normalize(goalsScored, 30, 100),
normalize(keyPasses, 200, 600),
normalize(dribbles, 100, 500),
normalize(passAccuracy, 70, 90),
normalize(crossAccuracy, 20, 50),
normalize(tackles, 300, 800),
normalize(interceptions, 200, 600),
normalize(clearances, 300, 900),
normalize(yellowCards, 30, 100),
normalize(redCards, 0, 10)
],
output: [outcome]
});
}
return data;
}
function predictLossProbability() {
// Get all 12 input values
const goalsConceded = parseFloat(goalsConcededInput.value);
const shotsOnTarget = parseFloat(shotsOnTargetInput.value);
const goalsScored = parseFloat(goalsScoredInput.value);
const keyPasses = parseFloat(keyPassesInput.value);
const dribbles = parseFloat(dribblesInput.value);
const passAccuracy = parseFloat(passAccuracyInput.value);
const crossAccuracy = parseFloat(crossAccuracyInput.value);
const tackles = parseFloat(tacklesInput.value);
const interceptions = parseFloat(interceptionsInput.value);
const clearances = parseFloat(clearancesInput.value);
const yellowCards = parseFloat(yellowCardsInput.value);
const redCards = parseFloat(redCardsInput.value);
const input = [
normalize(goalsConceded, 20, 80),
normalize(shotsOnTarget, 100, 300),
normalize(goalsScored, 30, 100),
normalize(keyPasses, 200, 600),
normalize(dribbles, 100, 500),
normalize(passAccuracy, 70, 90),
normalize(crossAccuracy, 20, 50),
normalize(tackles, 300, 800),
normalize(interceptions, 200, 600),
normalize(clearances, 300, 900),
normalize(yellowCards, 30, 100),
normalize(redCards, 0, 10)
];
const output = net.run(input);
const lossProb = output[0];
const lossPercent = Math.round(lossProb * 100);
const confidence = Math.abs(lossProb - 0.5) * 2; // How far from 50%
// Update UI
lossPercentage.textContent = `${lossPercent}%`;
progressRing.setAttribute('stroke-dasharray', `${lossPercent}, ${100 - lossPercent}`);
confidenceBar.style.width = `${confidence * 100}%`;
if (lossProb > 0.7) {
predictionText.innerHTML = `<span class="text-red-600">High loss probability</span>`;
progressRing.setAttribute('stroke', '#EF4444');
} else if (lossProb > 0.55) {
predictionText.innerHTML = `<span class="text-orange-500">Moderate loss probability</span>`;
progressRing.setAttribute('stroke', '#F97316');
} else if (lossProb > 0.45) {
predictionText.textContent = "Neutral prediction";
progressRing.setAttribute('stroke', '#6B7280');
} else if (lossProb > 0.3) {
predictionText.innerHTML = `<span class="text-green-500">Moderate win probability</span>`;
progressRing.setAttribute('stroke', '#10B981');
} else {
predictionText.innerHTML = `<span class="text-green-600">High win probability</span>`;
progressRing.setAttribute('stroke', '#059669');
}
}
function renderTeamCards() {
teamPredictions.innerHTML = '';
soccerTeams.forEach(team => {
const card = document.createElement('div');
card.className = 'bg-white rounded-lg shadow-md p-4 team-card';
card.innerHTML = `
<div class="flex items-center mb-3">
<div class="text-2xl mr-3">${team.logo}</div>
<h3 class="font-semibold text-gray-800">${team.name}</h3>
</div>
<div class="grid grid-cols-2 gap-2 text-xs mb-3">
<div><span class="text-gray-500">Conceded:</span> ${team.goalsConceded}</div>
<div><span class="text-gray-500">Shots:</span> ${team.shotsOnTarget}</div>
<div><span class="text-gray-500">Goals:</span> ${team.goalsScored}</div>
<div><span class="text-gray-500">Pass %:</span> ${team.passAccuracy.toFixed(1)}</div>
<div><span class="text-gray-500">Tackles:</span> ${team.tackles}</div>
<div><span class="text-gray-500">Yellows:</span> ${team.yellowCards}</div>
</div>
<div class="flex items-center">
<div class="relative w-10 h-10 mr-2">
<svg class="w-full h-full" viewBox="0 0 36 36">
<path
d="M18 2.0845
a 15.9155 15.9155 0 0 1 0 31.831
a 15.9155 15.9155 0 0 1 0 -31.831"
fill="none"
stroke="#E5E7EB"
stroke-width="2"
/>
<path
class="team-progress"
d="M18 2.0845
a 15.9155 15.9155 0 0 1 0 31.831
a 15.9155 15.9155 0 0 1 0 -31.831"
fill="none"
stroke="#EF4444"
stroke-width="2"
stroke-dasharray="0, 100"
/>
</svg>
<div class="team-percentage absolute inset-0 flex items-center justify-center text-xs font-bold text-red-600">-</div>
</div>
<button class="text-xs bg-green-100 hover:bg-green-200 text-green-800 py-1 px-2 rounded flex items-center ml-auto predict-btn" data-team='${JSON.stringify(team)}'>
<i class="fas fa-calculator mr-1 text-xs"></i> Predict
</button>
</div>
`;
teamPredictions.appendChild(card);
});
// Add event listeners to predict buttons
document.querySelectorAll('.predict-btn').forEach(btn => {
btn.addEventListener('click', function() {
const team = JSON.parse(this.getAttribute('data-team'));
// Set all 12 input values
goalsConcededInput.value = team.goalsConceded;
shotsOnTargetInput.value = team.shotsOnTarget;
goalsScoredInput.value = team.goalsScored;
keyPassesInput.value = team.keyPasses;
dribblesInput.value = team.dribbles;
passAccuracyInput.value = team.passAccuracy;
crossAccuracyInput.value = team.crossAccuracy;
tacklesInput.value = team.tackles;
interceptionsInput.value = team.interceptions;
clearancesInput.value = team.clearances;
yellowCardsInput.value = team.yellowCards;
redCardsInput.value = team.redCards;
if (net.trainOpts) {
predictLossProbability();
} else {
predictionText.textContent = "Train the network first";
}
});
});
}
function updateAllTeamPredictions() {
soccerTeams.forEach((team, index) => {
const input = [
normalize(team.goalsConceded, 20, 80),
normalize(team.shotsOnTarget, 100, 300),
normalize(team.goalsScored, 30, 100),
normalize(team.keyPasses, 200, 600),
normalize(team.dribbles, 100, 500),
normalize(team.passAccuracy, 70, 90),
normalize(team.crossAccuracy, 20, 50),
normalize(team.tackles, 300, 800),
normalize(team.interceptions, 200, 600),
normalize(team.clearances, 300, 900),
normalize(team.yellowCards, 30, 100),
normalize(team.redCards, 0, 10)
];
const output = net.run(input);
const lossPercent = Math.round(output[0] * 100);
// Update the corresponding team card
const card = teamPredictions.children[index];
const progress = card.querySelector('.team-progress');
const percentage = card.querySelector('.team-percentage');
progress.setAttribute('stroke-dasharray', `${lossPercent}, ${100 - lossPercent}`);
percentage.textContent = `${lossPercent}%`;
// Color based on probability
if (lossPercent > 70) {
progress.setAttribute('stroke', '#EF4444');
percentage.classList.add('text-red-600');
percentage.classList.remove('text-orange-500', 'text-gray-500', 'text-green-500', 'text-green-600');
} else if (lossPercent > 55) {
progress.setAttribute('stroke', '#F97316');
percentage.classList.add('text-orange-500');
percentage.classList.remove('text-red-600', 'text-gray-500', 'text-green-500', 'text-green-600');
} else if (lossPercent > 45) {
progress.setAttribute('stroke', '#6B7280');
percentage.classList.add('text-gray-500');
percentage.classList.remove('text-red-600', 'text-orange-500', 'text-green-500', 'text-green-600');
} else if (lossPercent > 30) {
progress.setAttribute('stroke', '#10B981');
percentage.classList.add('text-green-500');
percentage.classList.remove('text-red-600', 'text-orange-500', 'text-gray-500', 'text-green-600');
} else {
progress.setAttribute('stroke', '#059669');
percentage.classList.add('text-green-600');
percentage.classList.remove('text-red-600', 'text-orange-500', 'text-gray-500', 'text-green-500');
}
});
}
function drawNetwork() {
// Clear diagram
diagram.innerHTML = '';
const width = diagram.clientWidth;
const height = diagram.clientHeight;
const padding = 50;
// Calculate layer positions
const layers = [
{ neurons: 12, label: 'Input', stats: ['Conceded', 'Shots', 'Goals', 'KeyP', 'Drib', 'Pass%', 'Cross%', 'Tack', 'Int', 'Clear', 'Yel', 'Red'] },
...Array(config.hiddenLayers).fill().map((_, i) => ({
neurons: config.neuronsPerLayer,
label: `Hidden ${i + 1}`
})),
{ neurons: 1, label: 'Output', stats: ['Loss %'] }
];
const layerCount = layers.length;
const layerWidth = (width - 2 * padding) / (layerCount - 1);
// Draw connections first (so they appear behind neurons)
for (let l = 0; l < layerCount - 1; l++) {
const currentLayer = layers[l];
const nextLayer = layers[l + 1];
for (let n1 = 0; n1 < currentLayer.neurons; n1++) {
for (let n2 = 0; n2 < nextLayer.neurons; n2++) {
const x1 = padding + l * layerWidth;
const y1 = padding + (height - 2 * padding) * (n1 + 0.5) / currentLayer.neurons;
const x2 = padding + (l + 1) * layerWidth;
const y2 = padding + (height - 2 * padding) * (n2 + 0.5) / nextLayer.neurons;
// Create connection
const line = document.createElementNS('http://www.w3.org/2000/svg', 'line');
line.setAttribute('x1', x1);
line.setAttribute('y1', y1);
line.setAttribute('x2', x2);
line.setAttribute('y2', y2);
line.setAttribute('stroke', '#9CA3AF');
line.setAttribute('stroke-width', '1');
line.setAttribute('class', 'connection');
diagram.appendChild(line);
}
}
}
// Draw neurons
for (let l = 0; l < layerCount; l++) {
const layer = layers[l];
const x = padding + l * layerWidth;
for (let n = 0; n < layer.neurons; n++) {
const y = padding + (height - 2 * padding) * (n + 0.5) / layer.neurons;
// Create neuron circle
const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
circle.setAttribute('cx', x);
circle.setAttribute('cy', y);
circle.setAttribute('r', 15);
// Color input/output layers differently
if (l === 0) {
circle.setAttribute('fill', '#10B981'); // Green for input
} else if (l === layerCount - 1) {
circle.setAttribute('fill', '#EF4444'); // Red for output
} else {
circle.setAttribute('fill', '#3B82F6'); // Blue for hidden
}
circle.setAttribute('class', 'neuron');
diagram.appendChild(circle);
// Create neuron text
const text = document.createElementNS('http://www.w3.org/2000/svg', 'text');
text.setAttribute('x', x);
text.setAttribute('y', y + 4);
text.setAttribute('text-anchor', 'middle');
text.setAttribute('fill', 'white');
text.setAttribute('font-size', '8');
text.setAttribute('font-weight', 'bold');
// Show stat names for input layer
if (l === 0 && layer.stats) {
text.textContent = layer.stats[n];
} else if (l === layerCount - 1 && layer.stats) {
text.textContent = layer.stats[n];
} else {
text.textContent = `${layer.label[0]}${n + 1}`;
}
diagram.appendChild(text);
}
// Add layer label
const label = document.createElementNS('http://www.w3.org/2000/svg', 'text');
label.setAttribute('x', x);
label.setAttribute('y', height - 20);
label.setAttribute('text-anchor', 'middle');
label.setAttribute('fill', '#4B5563');
label.setAttribute('font-size', '12');
label.textContent = layer.label;
diagram.appendChild(label);
}
}
function initChart() {
const ctx = document.getElementById('errorChart').getContext('2d');
errorChart = new Chart(ctx, {
type: 'line',
data: {
labels: [],
datasets: [{
label: 'Training Error',
data: [],
borderColor: '#10B981',
backgroundColor: 'rgba(16, 185, 129, 0.1)',
borderWidth: 2,
fill: true,
tension: 0.4
}]
},
options: {
responsive: true,
plugins: {
title: {
display: true,
text: 'Neural Network Learning Progress',
font: {
size: 16
}
},
tooltip: {
callbacks: {
label: function(context) {
return `Error: ${context.parsed.y.toFixed(5)}`;
}
}
}
},
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: 'Error Rate'
}
},
x: {
title: {
display: true,
text: 'Training Iterations'
}
}
}
}
});
}
function updateChart(iteration, error) {
errorChart.data.labels.push(iteration);
errorChart.data.datasets[0].data.push(error);
errorChart.update();
}
function resetChart() {
errorChart.data.labels = [];
errorChart.data.datasets[0].data = [];
errorChart.update();
}
// Helper functions
function randomInRange(min, max) {
return Math.random() * (max - min) + min;
}
function normalize(value, min, max) {
return (value - min) / (max - min);
}
});
</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=MarcRyan/spe" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Soccer Prediction Neural Network</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://unpkg.com/brain.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.neuron {
transition: all 0.3s ease;
}
.neuron:hover {
transform: scale(1.1);
box-shadow: 0 0 15px rgba(59, 130, 246, 0.6);
}
.connection {
stroke-dasharray: 1000;
stroke-dashoffset: 1000;
animation: dash 2s linear forwards;
}
@keyframes dash {
to {
stroke-dashoffset: 0;
}
}
.pulse {
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0% {
transform: scale(0.95);
box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.7);
}
70% {
transform: scale(1);
box-shadow: 0 0 0 10px rgba(220, 38, 38, 0);
}
100% {
transform: scale(0.95);
box-shadow: 0 0 0 0 rgba(220, 38, 38, 0);
}
}
.team-card {
transition: all 0.3s ease;
}
.team-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}
.progress-ring__circle {
transition: stroke-dashoffset 0.5s;
transform: rotate(-90deg);
transform-origin: 50% 50%;
}
.stat-badge {
font-size: 0.7rem;
padding: 0.2rem 0.4rem;
border-radius: 0.25rem;
}
.offensive-stat {
background-color: #3B82F6;
color: white;
}
.defensive-stat {
background-color: #EF4444;
color: white;
}
.teamwork-stat {
background-color: #10B981;
color: white;
}
.discipline-stat {
background-color: #F59E0B;
color: white;
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="container mx-auto px-4 py-8">
<header class="mb-12 text-center">
<h1 class="text-4xl font-bold text-green-600 mb-2">
<i class="fas fa-futbol mr-3"></i>Advanced Soccer Prediction Engine
</h1>
<p class="text-gray-600 max-w-3xl mx-auto">
Comprehensive neural network analysis using 12 key performance metrics to predict match outcomes.
The system learns from extensive soccer statistics to provide accurate loss probability predictions.
</p>
</header>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
<!-- Control Panel -->
<div class="bg-white rounded-xl shadow-lg p-6 h-fit">
<h2 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
<i class="fas fa-sliders-h mr-2 text-green-500"></i>Network Configuration
</h2>
<div class="space-y-4">