| 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
|
|
|
|
|
| df = pd.read_csv('hiring_data_enriched.csv')
|
|
|
|
|
| X = df[['Job_Category', 'Years_Experience', 'Education_Level', 'Skill_Fit_Score']]
|
| y = df['Final_Decision']
|
|
|
|
|
| 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(steps=[
|
| ('preprocessor', preprocessor),
|
| ('classifier', LogisticRegression(random_state=42))
|
| ])
|
|
|
|
|
| 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)
|
|
|
|
|
| with open('hiring_model.pkl', 'wb') as f:
|
| pickle.dump(model, f)
|
|
|
| print("Model trained and saved as hiring_model.pkl")
|
|
|