← Back to case study

PROJECT 097 · PYTHON SOURCE

Abalone ring-count estimation

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': 97, 'dataset': 'abalone', 'title': 'Abalone ring-count estimation', 'question': 'Can physical measurements estimate observed ring counts beyond a median baseline?', 'method': 'Grouped-input regression with original ring-count errors.', 'action': 'Evaluate with independently collected animals and sampling sites before biological use.', 'limitations': 'Physical measurements use source scaling. Rings are the modeled target; the source describes an approximate age conversion. Site and animal group identifiers are unavailable, limiting biological generalization. '}

def analyze():
    df = load('abalone').copy()
    t,p,e=regression(df,ABALONE_FEATURES,'rings')
    out=result(t,'model','mae','Ring-count MAE','The target is ring count. Some predictors require dissection, so this full-feature model is not a non-destructive measurement protocol.',extra={'predictions':p},evaluation=e)
    return out

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