AI-hiring / train_model.py
d-e-e-k-11's picture
Upload folder using huggingface_hub
c9f05a2 verified
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
import pickle
# Load data
df = pd.read_csv('hiring_data_enriched.csv')
# Features and Target
X = df[['Job_Category', 'Years_Experience', 'Education_Level', 'Skill_Fit_Score']]
y = df['Final_Decision']
# Preprocessing
categorical_features = ['Job_Category', 'Education_Level']
numerical_features = ['Years_Experience', 'Skill_Fit_Score']
preprocessor = ColumnTransformer(
transformers=[
('num', StandardScaler(), numerical_features),
('cat', OneHotEncoder(handle_unknown='ignore'), categorical_features)
])
# Model Pipeline
model = Pipeline(steps=[
('preprocessor', preprocessor),
('classifier', LogisticRegression(random_state=42))
])
# Train
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model.fit(X_train, y_train)
# Save model and preprocessor
with open('hiring_model.pkl', 'wb') as f:
pickle.dump(model, f)
print("Model trained and saved as hiring_model.pkl")