PROJECT 032 · PYTHON SOURCE
Sensory quality regression
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': 32, 'dataset': 'wine', 'title': 'Sensory quality regression', 'question': 'Can chemical measurements estimate sensory quality better than a median baseline?', 'method': 'Fixed grouped-input regression with original score MAE and RMSE.', 'action': 'Use error magnitude to judge whether laboratory features support an additional quality-screening study.', 'limitations': 'Sensory scores are ordinal and concentrated in the middle. Producer and batch IDs are unavailable. Associations are not recipes for changing quality or evidence of market price. '}
def analyze():
df = load('wine').copy()
t,p,e=regression(df,WINE_FEATURES,'quality')
out=result(t,'model','mae','Sensory-score MAE','Identical input signatures stay in one split. Scores are ordinal, while this benchmark treats score differences numerically.',extra={'predictions':p},evaluation=e)
return out
if __name__ == "__main__":
execute(Path(__file__).parent, META, analyze)