File size: 5,814 Bytes
3816915 |
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
import gradio as gr
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.multioutput import MultiOutputClassifier
from sklearn.metrics import accuracy_score
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
# ------------------- Load Data -------------------
df = pd.read_csv("Balanced_Placement_Data.csv")
features = [
'ssc_percentage', 'hsc_percentage', 'undergrad_degree', 'Graduate_degree_percentage',
'emp_test_percentage', 'Internship_Experience_Months', 'Certifications_Count',
'Technical_Skills_Score', 'Soft_Skills_Score', 'Hackathons_Participated',
'Resume_Score', 'Online_Course_Count', 'Social_Media_Presence'
]
target_columns = ['Placement_Status', 'Domain_of_Interest']
X = df[features]
y = df[target_columns]
categorical_features = ['undergrad_degree']
numerical_features = list(set(features) - set(categorical_features))
preprocessor = ColumnTransformer([
("num", StandardScaler(), numerical_features),
("cat", OneHotEncoder(drop="first"), categorical_features)
])
models = {
"Random Forest": RandomForestClassifier(random_state=42),
"Decision Tree": DecisionTreeClassifier(random_state=42),
"KNN": KNeighborsClassifier(),
"Logistic Regression": LogisticRegression(max_iter=1000),
"SVM": SVC(probability=True)
}
# ------------------- Train Models -------------------
def train_models():
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
results = {}
for name, clf in models.items():
pipe = Pipeline([
("preprocessor", preprocessor),
("classifier", MultiOutputClassifier(clf))
])
pipe.fit(X_train, y_train)
y_pred = pipe.predict(X_test)
placement_acc = accuracy_score(y_test["Placement_Status"], y_pred[:,0])
domain_acc = accuracy_score(y_test["Domain_of_Interest"], y_pred[:,1])
results[name] = {
"Placement Accuracy": placement_acc,
"Domain Accuracy": domain_acc,
"Model": pipe
}
return results
results = train_models()
best_model_name = max(results, key=lambda m: results[m]["Placement Accuracy"] + results[m]["Domain Accuracy"])
best_model = results[best_model_name]["Model"]
# ------------------- Prediction Function -------------------
def predict_placement_and_domain(
ssc_percentage, hsc_percentage, undergrad_degree, Graduate_degree_percentage,
emp_test_percentage, Internship_Experience_Months, Certifications_Count,
Technical_Skills_Score, Soft_Skills_Score, Hackathons_Participated,
Resume_Score, Online_Course_Count, Social_Media_Presence
):
user_input = {
"ssc_percentage": ssc_percentage,
"hsc_percentage": hsc_percentage,
"undergrad_degree": undergrad_degree,
"Graduate_degree_percentage": Graduate_degree_percentage,
"emp_test_percentage": emp_test_percentage,
"Internship_Experience_Months": Internship_Experience_Months,
"Certifications_Count": Certifications_Count,
"Technical_Skills_Score": Technical_Skills_Score,
"Soft_Skills_Score": Soft_Skills_Score,
"Hackathons_Participated": Hackathons_Participated,
"Resume_Score": Resume_Score,
"Online_Course_Count": Online_Course_Count,
"Social_Media_Presence": Social_Media_Presence
}
input_df = pd.DataFrame([user_input])
prediction = best_model.predict(input_df)
return {
"Placement Status": prediction[0][0],
"Domain of Interest": prediction[0][1],
"Best Model": best_model_name
}
# ------------------- Gradio UI -------------------
with gr.Blocks() as demo:
gr.Markdown("# 🎯 Placement & Domain Predictor")
with gr.Row():
with gr.Column():
ssc_percentage = gr.Number(label="SSC Percentage", value=70)
hsc_percentage = gr.Number(label="HSC Percentage", value=65)
undergrad_degree = gr.Dropdown(choices=list(df['undergrad_degree'].unique()), label="Undergrad Degree")
Graduate_degree_percentage = gr.Number(label="Graduate Degree %", value=60)
emp_test_percentage = gr.Number(label="Employment Test %", value=50)
Internship_Experience_Months = gr.Number(label="Internship Months", value=0)
Certifications_Count = gr.Number(label="Certifications Count", value=1)
Technical_Skills_Score = gr.Number(label="Technical Skills Score", value=60)
Soft_Skills_Score = gr.Number(label="Soft Skills Score", value=60)
Hackathons_Participated = gr.Number(label="Hackathons Participated", value=1)
Resume_Score = gr.Number(label="Resume Score", value=50)
Online_Course_Count = gr.Number(label="Online Course Count", value=2)
Social_Media_Presence = gr.Number(label="Social Media Presence (0/1)", value=1)
btn = gr.Button("Predict")
with gr.Column():
output = gr.JSON(label="Prediction Result")
btn.click(
predict_placement_and_domain,
inputs=[ssc_percentage, hsc_percentage, undergrad_degree, Graduate_degree_percentage,
emp_test_percentage, Internship_Experience_Months, Certifications_Count,
Technical_Skills_Score, Soft_Skills_Score, Hackathons_Participated,
Resume_Score, Online_Course_Count, Social_Media_Presence],
outputs=output
)
demo.launch()
|