Download train_model.py from d-e-e-k-11/AI-hiring: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/d-e-e-k-11/AI-hiring/resolve/main/train_model.py
- Command line
-
hf download hf://d-e-e-k-11/AI-hiring/train_model.py
-
curl -L -o train_model.py https://huggingface.co/d-e-e-k-11/AI-hiring/resolve/main/train_model.py
1.29 kB
| 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") | |