FIFA-Player-Recomendation

Model Training Guide

Complete guide for training the FIFA Player Recommendation System models.

Quick Start

Train both models with one command:

python training/train.py

That’s it! Both models will be trained and saved to the models/ directory.


Table of Contents

  1. Training Options
  2. What Happens During Training
  3. Training Output
  4. System Requirements
  5. Troubleshooting
  6. Advanced Usage

Training Options

Train Both Models (Default)

python training/train.py

Trains both male and female player models.

Output:

Time: ~30-35 seconds total

Train Male Model Only

python training/train.py --male

Use case: When you only need male player recommendations.

Train Female Model Only

python training/train.py --female

Use case: When you only need female player recommendations.

Skip Specific Models

# Train female only (skip male)
python training/train.py --skip-male

# Train male only (skip female)
python training/train.py --skip-female

What Happens During Training

Step 1: Data Loading 📊

Step 2: Data Processing 🔧

Step 3: Model Training 🤖

Step 4: Model Saving 💾

Step 5: Model Testing 🧪


Training Output

Example output when training both models:

======================================================================
  ⚽ FIFA Player Recommendation System - Model Training
======================================================================

Models to train:
  • Male Players Model
  • Female Players Model

======================================================================
  🔵 Training Male Players Model
======================================================================

[📊] Processing Male Players data...
   ✓ Loaded 16163 players
   ✓ Extracted 34 features
   ✓ Feature matrix shape: (16163, 34)

[🤖] Training Male Players model...
Computing similarity matrix...
Similarity matrix computed: (16163, 16163)
   ✓ Similarity matrix computed: (16163, 16163)

[💾] Saving Male Players model...
Model saved to models/male_model.pkl
   ✓ Model saved: models/male_model.pkl
   ✓ File size: 1007.2 MB

[🧪] Testing Male Players model...
   ✓ Top player: Kylian Mbappé
   ✓ Search test: Found 5 players
   ✓ Recommendation test: 3 similar players found

✅ Male Players model trained successfully in 28.3s

======================================================================
  🟣 Training Female Players Model
======================================================================

[📊] Processing Female Players data...
   ✓ Loaded 1578 players
   ✓ Extracted 34 features
   ✓ Feature matrix shape: (1578, 34)

[🤖] Training Female Players model...
Computing similarity matrix...
Similarity matrix computed: (1578, 1578)
   ✓ Similarity matrix computed: (1578, 1578)

[💾] Saving Female Players model...
Model saved to models/female_model.pkl
   ✓ Model saved: models/female_model.pkl
   ✓ File size: 9.6 MB

[🧪] Testing Female Players model...
   ✓ Top player: Aitana Bonmatí
   ✓ Search test: Found 5 players
   ✓ Recommendation test: 3 similar players found

✅ Female Players model trained successfully in 1.9s

======================================================================
  📊 Training Summary
======================================================================

Models trained:
  ✅ Male Players Model   - 28.3s
  ✅ Female Players Model - 1.9s

Total training time: 30.2s

✨ You can now run the application:
   python run.py

   Or:
   cd app && python main.py

======================================================================

System Requirements

Minimum


Troubleshooting

Error: “Data file not found”

Cause: CSV files are missing or in wrong location

Solution:

# Check if files exist
ls new-data/
# Should show: male_players.csv, female_players.csv

# If missing, ensure you're in the project root directory
cd FIFA-Player-Recomendation

Error: “Memory Error” or “Killed”

Cause: Insufficient RAM (especially for male model)

Solutions:

  1. Close other applications to free up memory
  2. Train female model only (smaller): python training/train.py --female
  3. Use a machine with more RAM (recommended: 4GB+)
  4. Train on cloud (Google Colab, AWS)

Error: “Module not found”

Cause: Dependencies not installed

Solution:

pip install -r requirements.txt

Training is Very Slow

Normal behavior:

If significantly slower:

Model File Size is Large

This is expected:

Why so large?


Advanced Usage

Training in Python Script

import sys
import os
sys.path.insert(0, os.path.abspath('.'))

from src.data_processing import DataProcessor
from src.model import PlayerRecommender

# Process data
processor = DataProcessor()
processed = processor.process_for_training('new-data/male_players.csv')

# Train model
model = PlayerRecommender()
model.fit(
    data=processed['data'],
    normalized_features=processed['normalized_features'],
    feature_names=processed['feature_names']
)

# Save model
model.save('models/male_model.pkl')

# Use model
recommendations = model.recommend_similar('Kylian Mbappé', n_recommendations=10)
print(f"Found {len(recommendations)} similar players")

Automated Training (CI/CD)

For automated training in CI/CD pipelines:

# Non-interactive mode
python training/train.py > training.log 2>&1

# Check exit code
if [ $? -eq 0 ]; then
    echo "Training successful"
else
    echo "Training failed"
    exit 1
fi

Cloud Training

Google Colab

# Clone repository
!git clone https://github.com/inboxpraveen/FIFA-Player-Recomendation.git
%cd FIFA-Player-Recomendation

# Install dependencies
!pip install -r requirements.txt

# Train models
!python training/train.py

# Download trained models
from google.colab import files
files.download('models/male_model.pkl')
files.download('models/female_model.pkl')

AWS EC2

# SSH into instance
ssh -i key.pem ubuntu@ec2-instance

# Clone and train
git clone https://github.com/inboxpraveen/FIFA-Player-Recomendation.git
cd FIFA-Player-Recomendation
pip install -r requirements.txt
python training/train.py

Understanding the Algorithm

Content-Based Filtering

The system uses content-based filtering with cosine similarity:

  1. Feature Extraction: Extract 34 numerical attributes for each player
  2. Normalization: Scale all features to 0-1 range
  3. Similarity Computation: Calculate cosine similarity between all player pairs
  4. Precomputation: Store similarity matrix for fast lookups

Why Cosine Similarity?

similarity(A, B) = (A · B) / (||A|| × ||B||)

Advantages:

Time Complexity

Result: < 50ms recommendations instead of ~500ms


Re-training

When to Re-train

How to Re-train

# Simply run the training script again
python training/train.py

# Old models will be overwritten

Verification

After training, verify models exist and work:

# Check files
ls -lh models/
# Should show: male_model.pkl (~1GB), female_model.pkl (~10MB)

# Test models by running the app
python run.py

# Access in browser
# http://localhost:5000

Next Steps

  1. Verify models exist: ls models/
  2. Run the application: python run.py
  3. Test features: Search, recommend, compare players
  4. Switch genders: Toggle between male/female datasets

Getting Help

Issues during training?

  1. Check this guide’s Troubleshooting section
  2. Ensure you meet System Requirements
  3. Verify dependencies: pip install -r requirements.txt
  4. Check GitHub Issues

Still stuck? Open a new issue with:


Made with ⚽ by Praveen Kumar