CoolFace
Modelpublic

nahiar/tiktok-bot-detection-v2

sourceHugging Faceapache-2.0updated 9mo agoView on Hugging Face
0likes
Model Card

TIKTOK Bot Detection Model

Overview

This directory contains a trained Random Forest classifier for detecting bot accounts on Tiktok.

Model Version: v2 Training Date: 2025-12-30 11:38:35 Framework: scikit-learn 1.5.2 Algorithm: Random Forest Classifier with GridSearchCV Hyperparameter Tuning


๐Ÿ“Š Model Performance

Final Metrics (Test Set)

MetricScore
Accuracy0.9224 (92.24%)
Precision0.9596 (95.96%)
Recall0.9094 (90.94%)
F1-Score0.9338 (93.38%)
ROC-AUC0.9773 (97.73%)
Average Precision0.9596 (95.96%)

Model Improvement

  • โ€”Baseline ROC-AUC: 0.9759
  • โ€”Tuned ROC-AUC: 0.9773
  • โ€”Improvement: 0.0014 (0.14%)

๐Ÿ—‚๏ธ Files

FileDescription
tiktok_bot_detection_v2.pklTrained Random Forest model
tiktok_scaler_v2.pklMinMaxScaler for feature normalization
tiktok_features_v2.jsonList of features used by the model
tiktok_metrics_v2.txtDetailed performance metrics report
images/All visualization plots (13 images)
README.mdThis file

๐ŸŽฏ Dataset Information

Training Configuration

  • โ€”Training Samples: 2,385
  • โ€”Test Samples: 596
  • โ€”Total Samples: 2,981
  • โ€”Number of Features: 12
  • โ€”Cross-Validation Folds: 5
  • โ€”Random State: 42

Class Distribution

Training Set:

  • โ€”Human (0): 951 (39.87%)
  • โ€”Bot (1): 1,434 (60.13%)

Test Set:

  • โ€”Human (0): 244 (40.94%)
  • โ€”Bot (1): 352 (59.06%)

๐Ÿ”ง Features (13)

  1. 1.IsPrivate
  2. 2.IsVerified
  3. 3.HasProfilePic
  4. 4.FollowingCount
  5. 5.FollowerCount
  6. 6.LikesCount
  7. 7.HasInstagram
  8. 8.HasYoutube
  9. 9.HasBio
  10. 10.HasLinkInBio
  11. 11.HasPosts
  12. 12.PostsCount
  13. 13.FollowToFollowerRatio

๐Ÿ† Top 5 Most Important Features

  1. 1.FollowToFollowerRatio - 0.2330
  2. 2.LikesCount - 0.1771
  3. 3.HasInstagram - 0.1395
  4. 4.FollowingCount - 0.1349
  5. 5.FollowerCount - 0.1055

โš™๏ธ Hyperparameters

Best Parameters (from GridSearchCV)

  • โ€”class_weight: None
  • โ€”max_depth: 13
  • โ€”max_features: sqrt
  • โ€”min_samples_leaf: 2
  • โ€”min_samples_split: 10
  • โ€”n_estimators: 100

Parameter Search Space

  • โ€”n_estimators: [100, 200, 300]
  • โ€”max_depth: [10, 15, 20, None]
  • โ€”min_samples_split: [2, 5, 10]
  • โ€”min_samples_leaf: [1, 2, 4]
  • โ€”max_features: ['sqrt', 'log2']
  • โ€”bootstrap: [True, False]

Total combinations tested: 540


๐Ÿ“ˆ Cross-Validation Results

Mean Scores (5-Fold Stratified CV)

  • โ€”Accuracy: 0.9191 (ยฑ0.0097)
  • โ€”Precision: 0.9326 (ยฑ0.0115)
  • โ€”Recall: 0.9331 (ยฑ0.0166)
  • โ€”F1-Score: 0.9327 (ยฑ0.0083)
  • โ€”ROC-AUC: 0.9744 (ยฑ0.0055)

๐Ÿ–ผ๏ธ Visualizations

All visualizations are saved in the images/ directory:

  1. 1.01_class_distribution.png - Training/Test set class distribution
  2. 2.02_feature_correlation.png - Feature correlation with target variable
  3. 3.03_correlation_matrix.png - Feature correlation heatmap
  4. 4.04_baseline_confusion_matrix.png - Baseline model confusion matrix
  5. 5.05_baseline_roc_curve.png - Baseline ROC curve
  6. 6.06_baseline_precision_recall.png - Baseline Precision-Recall curve
  7. 7.07_baseline_feature_importance.png - Baseline feature importance
  8. 8.08_cross_validation.png - Cross-validation score distribution
  9. 9.09_tuned_confusion_matrix.png - Tuned model confusion matrix
  10. 10.10_tuned_roc_curve.png - Tuned ROC curve
  11. 11.11_tuned_precision_recall.png - Tuned Precision-Recall curve
  12. 12.12_tuned_feature_importance.png - Tuned feature importance
  13. 13.13_model_comparison.png - Baseline vs Tuned comparison

๐Ÿš€ Usage Example

python
import joblib
import pandas as pd
import numpy as np

# Load model and scaler
model = joblib.load('tiktok_bot_detection_v2.pkl')
scaler = joblib.load('tiktok_scaler_v2.pkl')

# Prepare your data (example)
data = {
    'IsPrivate': 0.5,
    'IsVerified': 0.5,
    'HasProfilePic': 0.5,
    'FollowingCount': 0.5,
    'FollowerCount': 0.5,
    'LikesCount': 0.5,
    'HasInstagram': 0.5,
    'HasYoutube': 0.5,
    'HasBio': 0.5,
    'HasLinkInBio': 0.5,
    'HasPosts': 0.5,
    'PostsCount': 0.5,
    'FollowToFollowerRatio': 0.5,
}

# Create DataFrame
df = pd.DataFrame([data])

# Scale features
df_scaled = scaler.transform(df)

# Predict
prediction = model.predict(df_scaled)[0]
probability = model.predict_proba(df_scaled)[0]

print(f"Prediction: {'Bot' if prediction == 1 else 'Human'}")
print(f"Bot Probability: {probability[1]:.4f}")
print(f"Human Probability: {probability[0]:.4f}")

๐Ÿ“‹ Confusion Matrix Breakdown

Tuned Model (Test Set)

                Predicted
              Human    Bot
Actual Human      220      24
       Bot         18     334
  • โ€”True Negatives (TN): 220 (Correctly identified humans)
  • โ€”False Positives (FP): 24 (Humans incorrectly classified as bots)
  • โ€”False Negatives (FN): 18 (Bots incorrectly classified as humans)
  • โ€”True Positives (TP): 334 (Correctly identified bots)

๐Ÿ” Model Interpretation

Strengths

  • โ€”High ROC-AUC score (0.9754) indicates excellent discrimination capability
  • โ€”Balanced precision and recall for both classes
  • โ€”Robust cross-validation performance

Key Insights

  1. 1.Top features drive bot classification effectively
  2. 2.GridSearchCV improved performance over baseline by 0.25%
  3. 3.Model generalizes well on unseen test data

๐Ÿ“ Notes

  • โ€”Feature Scaling: All features are scaled using MinMaxScaler to [0, 1] range
  • โ€”Missing Values: Filled with 0 during preprocessing
  • โ€”Class Balance: Imbalanced dataset
  • โ€”Model Type: Ensemble method resistant to overfitting

๐Ÿ”„ Model Updates

To retrain the model:

  1. 1.Place new training data in ../data/train_tiktok.csv
  2. 2.Run the training notebook: 5_enhanced_training.ipynb
  3. 3.Update this README with new metrics

๐Ÿ“ง Contact & Support

For questions or issues regarding this model, please refer to the main project documentation.


Generated: 2025-12-30 11:38:35 Notebook: 5_enhanced_training.ipynb Platform: Tiktok