-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraining_encoders.py
More file actions
32 lines (24 loc) · 989 Bytes
/
Copy pathtraining_encoders.py
File metadata and controls
32 lines (24 loc) · 989 Bytes
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
import pandas as pd
from category_encoders import TargetEncoder
import joblib
# Load your training data
df = pd.read_excel("dataset/Claim Fraud Detection.xlsx") # change to your actual filename
categorical_cols = [
'auto_model', 'auto_make', 'police_report_available', 'property_damage',
'incident_city', 'incident_state', 'authorities_contacted',
'incident_severity', 'collision_type', 'incident_type',
'insured_relationship', 'insured_hobbies', 'insured_occupation',
'insured_education_level', 'insured_sex', 'policy_csl', 'policy_state'
]
target_col = 'fraud_reported'
encoders = {}
for col in categorical_cols:
te = TargetEncoder()
te.fit(df[col], df[target_col])
encoders[col] = te # store encoder per column
# ✅ Save the dict of encoders
joblib.dump(encoders, "encoders.pkl")
print("Saved encoders as dictionary with keys:", list(encoders.keys()))
encoders = joblib.load("encoders.pkl")
print(type(encoders))
print(list(encoders.keys()))