import pandas as pd
from sklearn.metrics import mean_absolute_error
import joblib
import sys

def validate(dataset_path, model_path):
    df = pd.read_csv(dataset_path)
    X = df.drop('target', axis=1)
    y = df['target']
    
    model = joblib.load(model_path)
    preds = model.predict(X)
    mae = mean_absolute_error(y, preds)
    
    print(f"Overall MAE on full dataset: {mae:.4f}")
    
    # Check error distribution
    diffs = (y - preds).abs()
    within_01 = (diffs <= 0.1).mean() * 100
    within_03 = (diffs <= 0.3).mean() * 100
    
    print(f"Samples within 0.1 error: {within_01:.2f}%")
    print(f"Samples within 0.3 error: {within_03:.2f}%")

if __name__ == "__main__":
    validate(sys.argv[1], sys.argv[2])
