Spaces:
Sleeping
Sleeping
File size: 2,798 Bytes
080d992 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | """
Quick evaluation script: loads the saved visaModel from artifact/model.pkl,
reproduces the same feature-engineering that data_ingestion.py performs,
splits the data, and prints classification metrics on the test set.
"""
import pickle
from datetime import date
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.metrics import (
accuracy_score,
f1_score,
precision_score,
recall_score,
classification_report,
)
from visa_approval_prediction.entity.estimator import visaModel
# ββ Constants (same as visa_approval_prediction.constants) ββββββββββββββ
CURRENT_YEAR = date.today().year
TARGET_COLUMN = "case_status"
# ββ 1. Load the saved model ββββββββββββββββββββββββββββββββββββββββββββ
with open("artifact/model.pkl", "rb") as f:
model: visaModel = pickle.load(f)
print(f"Loaded model: {model}")
# ββ 2. Load the raw dataset ββββββββββββββββββββββββββββββββββββββββββββ
df = pd.read_csv("EasyVisa.csv")
print(f"Dataset shape: {df.shape}")
# ββ 3. Feature engineering (mirrors data_ingestion.py) ββββββββββββββββββ
df["company_age"] = CURRENT_YEAR - df["yr_of_estab"]
df.drop(columns=["case_id", "yr_of_estab"], inplace=True)
# Encode target: Certified = 0, Denied = 1
df[TARGET_COLUMN] = df[TARGET_COLUMN].map({"Certified": 0, "Denied": 1})
# ββ 4. Stratified train/test split βββββββββββββββββββββββββββββββββββββ
_, test_set = train_test_split(
df,
test_size=0.2,
random_state=42,
stratify=df[TARGET_COLUMN],
)
# ββ 5. Separate features and target from the test split βββββββββββββββββ
X_test = test_set.drop(columns=[TARGET_COLUMN])
y_test = test_set[TARGET_COLUMN]
# ββ 6. Generate predictions βββββββββββββββββββββββββββββββββββββββββββββ
y_pred = model.predict(X_test)
# ββ 7. Print all metrics ββββββββββββββββββββββββββββββββββββββββββββββββ
print("\n===== Test-Set Metrics =====")
print(f"Accuracy : {accuracy_score(y_test, y_pred):.4f}")
print(f"F1 : {f1_score(y_test, y_pred):.4f}")
print(f"Precision: {precision_score(y_test, y_pred):.4f}")
print(f"Recall : {recall_score(y_test, y_pred):.4f}")
print("\n--- Classification Report ---")
print(classification_report(y_test, y_pred, target_names=["Certified", "Denied"]))
|