AI & Data

Dataset Preparation by Example

California Fire Incidents

Hands-on data exploration and feature engineering

Dataset Preparation by Example

Exploring Data and understanding the features

Goal: Predict if a fire will become a major incident using ML.

California Fire Incidents: Key Features

Target & Location

  • MajorIncident - Target (boolean)
  • Latitude / Longitude
  • Counties - Geographic region
  • AcresBurned - Fire size

Resources & Timeline

  • Started / Extinguished
  • PersonnelInvolved
  • Engines, Helicopters
  • StructuresDestroyed

Dataset Discovery

What is the composition of this dataset?

Prediction: Major Fire or Not?

Removing Duplicates with Pandas

from Orange.data.pandas_compat import table_from_frame, table_to_frame

df = table_to_frame(in_data)
df = df.drop_duplicates()

out_data = table_from_frame(df)

Target Variable Balance

What is the balance between the two labels?

MajorIncident Distribution
False: 66%
True: 34%

Imbalanced Classes Strategies

When one class dominates the other, the model becomes biased:

3 Ways to Handle Imbalanced Data
Imbalanced 66% Non-Major 34% Major Strategies Oversample Duplicate minority class Undersample Reduce majority class Class Weights Penalize majority errors more Balanced 50% / 50% Fair training 50% 50%

Undersampling in Orange

Drop random data from the majority class:

import pandas as pd
from Orange.data.pandas_compat import table_from_frame, table_to_frame

df = table_to_frame(in_data)
# Separate by class
major = df[df['MajorIncident'] == True]
non_major = df[df['MajorIncident'] == False]
# Undersample majority class
non_major_sampled = non_major.sample(n=len(major), random_state=42)
# Combine
out_data = table_from_frame(pd.concat([major, non_major_sampled]))

First Evaluation with Random Forest

ML Pipeline - From Raw Data to Evaluation
Data Cleaning Raw Data Remove Duplicates Handle Missing Feature Engineering Select Features Transform Variables Modeling Train Random Forest Evaluate Accuracy < 80% Deploy ≥ 80%

Dealing with Missing Values

3 main strategies:

# Custom imputation
df['AcresBurned'] = df['AcresBurned'].fillna(df['AcresBurned'].median())
df['Counties'] = df['Counties'].fillna('Unknown')

Dealing with Date and Time

Extract useful features instead of using raw dates:

import pandas as pd

df['Started'] = pd.to_datetime(df['Started'])
# Extract useful features
df['Month'] = df['Started'].dt.month
df['DayOfWeek'] = df['Started'].dt.dayofweek
df['Season'] = df['Month'].map({12:1, 1:1, 2:1, 3:2, 4:2, 5:2,
                                 6:3, 7:3, 8:3, 9:4, 10:4, 11:4})
# Drop original date column
df = df.drop(columns=['Started'])

Adding External Data

Enrich with: California Weather Data (1998-2020)

Data Enrichment - Combining Multiple Sources
Fire Dataset Incidents Date, Location, Size Weather Dataset Conditions Temp, Wind, Humidity Join Operation Match on: • Date • Location Enriched Dataset Fire + Weather More predictive power! FIRE + TEMP = ML ML-Ready

Questions?

Dataset Preparation

Next: Data Formats

Slide Overview