ForestGuard AI β Forest Cover Type Classifier
An optimized Random Forest classifier trained on the UCI Covertype dataset to predict seven forest cover types using 54 cartographic and environmental features.
Test Accuracy: 96.20% | Test Macro F1: 93.29%
- Model: RandomForestClassifier
- Framework: Scikit-learn
- Task: Multi-class classification
- Classes: 7
- Input Features: 54
Model Description
ForestGuard AI is a supervised machine learning model that predicts the forest cover type of a geographical area based on cartographic and environmental measurements.
The model was trained using the UCI Covertype dataset, containing 581,012 observations and 54 input features.
Intended Use
This model is intended for:
- Educational machine learning applications.
- Forest cover type classification experiments.
- Environmental and geographical data analysis.
- Multi-class classification demonstrations.
- Integration into Python applications and interactive dashboards.
It should not be used as the sole basis for real-world forestry, land management, or environmental decisions.
Dataset
UCI Covertype Dataset
Source: UCI Machine Learning Repository
| Dataset Property | Value |
|---|---|
| Total Observations | 581,012 |
| Input Features | 54 |
| Target Classes | 7 |
| Missing Values | 0 |
Input Features
The 54 features consist of:
- 10 quantitative cartographic features.
- 4 wilderness area binary indicators.
- 40 soil type binary indicators.
Examples of quantitative features include:
- Elevation
- Aspect
- Slope
- Horizontal and vertical distance to hydrology
- Horizontal distance to roadways
- Horizontal distance to fire points
- Hillshade measurements
Classification Labels
| Label | Forest Cover Type |
|---|---|
| 1 | Spruce/Fir |
| 2 | Lodgepole Pine |
| 3 | Ponderosa Pine |
| 4 | Cottonwood/Willow |
| 5 | Aspen |
| 6 | Douglas-fir |
| 7 | Krummholz |
Training Procedure
The model development workflow included:
- Dataset inspection and exploratory data analysis.
- Data quality validation.
- Stratified training and test splitting.
- Model comparison using Decision Tree, Random Forest, XGBoost, and Balanced Random Forest.
- Hyperparameter optimization using RandomizedSearchCV.
- Model selection based on Macro F1-score.
- Final evaluation on an untouched test set.
Hyperparameter Optimization
RandomizedSearchCV configuration:
| Setting | Value |
|---|---|
| Parameter Candidates | 8 |
| Cross-validation Folds | 3 |
| Scoring Metric | Macro F1 |
| Best CV Macro F1 | 0.9243 |
Best Hyperparameters
{
"n_estimators": 100,
"max_depth": 30,
"max_features": 0.7,
"min_samples_split": 5,
"min_samples_leaf": 1
}
Evaluation Results
The final model was evaluated on an untouched test set.
| Metric | Test Score |
|---|---|
| Accuracy | 96.20% |
| Macro Precision | 94.73% |
| Macro Recall | 92.00% |
| Macro F1-score | 93.29% |
| Weighted F1-score | 96.18% |
Per-Class Performance
| Class | Forest Cover Type | F1-score |
|---|---|---|
| 1 | Spruce/Fir | 0.96 |
| 2 | Lodgepole Pine | 0.97 |
| 3 | Ponderosa Pine | 0.96 |
| 4 | Cottonwood/Willow | 0.88 |
| 5 | Aspen | 0.87 |
| 6 | Douglas-fir | 0.93 |
| 7 | Krummholz | 0.96 |
Model Files
This repository contains the following artifacts:
| File | Description |
|---|---|
forest_cover_model.joblib |
Trained Random Forest classifier |
model_metadata.json |
Feature names, model parameters, and evaluation metadata |
Installation
Install the required Python libraries:
pip install joblib pandas numpy scikit-learn
Compatibility: The model was serialized using Scikit-learn 1.6.1. For reproducible loading, use the same Scikit-learn version.
Usage
1. Download the Model Files
from huggingface_hub import hf_hub_download
REPO_ID = "AbdelrahmanAkl/forestguard-ai-model"
model_path = hf_hub_download(
repo_id=REPO_ID,
filename="forest_cover_model.joblib",
repo_type="model"
)
metadata_path = hf_hub_download(
repo_id=REPO_ID,
filename="model_metadata.json",
repo_type="model"
)
2. Load the Model
import json
import joblib
model = joblib.load(model_path)
with open(metadata_path, "r", encoding="utf-8") as file:
metadata = json.load(file)
feature_names = metadata["feature_names"]
print("Model loaded successfully")
print("Number of features:", len(feature_names))
print("Available classes:", model.classes_)
3. Make a Prediction
Prepare a dictionary containing all 54 input features, using the exact feature names and definitions from the original Covertype dataset.
import pandas as pd
# input_features must contain all 54 features.
# Populate it with actual values from a valid observation.
input_df = pd.DataFrame(
[input_features],
columns=feature_names
)
prediction = int(model.predict(input_df)[0])
probabilities = model.predict_proba(input_df)[0]
class_probabilities = {
int(class_label): float(probability)
for class_label, probability in zip(
model.classes_,
probabilities
)
}
print("Predicted forest cover class:", prediction)
print("Class probabilities:", class_probabilities)
Important: The input must contain all 54 features with the correct names, numerical values, and original feature definitions. Wilderness area and soil type indicators must be represented correctly.
Limitations
- The model learns patterns from the UCI Covertype dataset.
- Generalization to geographical regions outside the original dataset has not been independently established.
- Feature importance reflects model reliance, not causal relationships.
- Predicted probabilities are model estimates and do not guarantee prediction correctness.
- The model is not a replacement for professional forestry assessment or field surveys.
Deployment
The trained model is integrated into an interactive Streamlit application.
Launch ForestGuard AI β Live Demo
Source Code
GitHub Repository:
https://github.com/AbdelrhmanAkl/ForestGuard-AI
Author
Abdelrahman Akl
AI Engineer | Machine Learning | Deep Learning | Agentic AI
- GitHub: https://github.com/AbdelrhmanAkl
- Hugging Face: https://huggingface.co/AbdelrahmanAkl
Developed with Python, Scikit-learn, and Streamlit.