← Back to case study

PROJECT 093 · PYTHON SOURCE

Zero recorded area analysis

Study-specific code. Shared modules, dependency versions, and reproduction instructions are included in all project files.

Download Python file ↓
from pathlib import Path
import sys
ROOT = Path(__file__).resolve().parents[2]
sys.path.insert(0, str(ROOT))
import numpy as np
import pandas as pd
from scipy.stats import spearmanr
from sklearn.decomposition import PCA
from sklearn.ensemble import IsolationForest
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import confusion_matrix, precision_score, recall_score
from portfolio.data import load
from portfolio.constants import *
from portfolio.methods import result, sql, rates, associations, distribution, regression, classification, cluster
from portfolio.engine import execute

META = {'id': 93, 'dataset': 'fires', 'title': 'Zero recorded area analysis', 'question': 'How does the share of zero recorded area vary by month?', 'method': 'Zero-area indicator with monthly denominators and Wilson intervals.', 'action': 'Confirm the source measurement convention before assigning zeros a physical meaning.', 'limitations': 'The sample consists of recorded fire observations, not all places and times at risk. Zero recorded area is not evidence of no ignition. No precise dates or event identifiers are supplied. This is not an emergency forecasting system. '}

def analyze():
    df = load('fires').copy()
    df['zero_area']=df.area.eq(0).astype(int)
    t=rates(df,'month','zero_area')
    out=result(t,'month','rate','Zero recorded-area share','Zero is retained as an observed value. It does not mean that no fire occurred.')
    return out

if __name__ == "__main__":
    execute(Path(__file__).parent, META, analyze)