|
import pandas as pd |
|
from flask import Flask, request, jsonify |
|
|
|
from sklearn.compose import ColumnTransformer |
|
from sklearn.ensemble import RandomForestClassifier |
|
from sklearn.impute import SimpleImputer |
|
from sklearn.model_selection import train_test_split |
|
from sklearn.pipeline import Pipeline |
|
from sklearn.preprocessing import LabelEncoder, StandardScaler |
|
from streamlit import * |
|
import joblib |
|
|
|
|
|
|
|
data = pd.read_csv('dataset.csv') |
|
|
|
|
|
X = data.drop('PlacedOrNot', axis=1) |
|
y = data['PlacedOrNot'] |
|
|
|
|
|
categorical_features = ['HistoryOfBacklogs'] |
|
for feature in categorical_features: |
|
encoder = LabelEncoder() |
|
X[feature] = encoder.fit_transform(X[feature]) |
|
|
|
|
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) |
|
|
|
|
|
numerical_features = ['Internships', 'CGPA'] |
|
numerical_transformer = StandardScaler() |
|
categorical_features = [ 'HistoryOfBacklogs'] |
|
categorical_transformer = SimpleImputer(strategy='most_frequent') |
|
preprocessor = ColumnTransformer( |
|
transformers=[ |
|
('num', numerical_transformer, numerical_features), |
|
('cat', categorical_transformer, categorical_features) |
|
]) |
|
|
|
pipeline = Pipeline([ |
|
('preprocessor', preprocessor), |
|
('classifier', RandomForestClassifier(random_state=42)) |
|
]) |
|
|
|
|
|
pipeline.fit(X_train, y_train) |
|
|
|
|
|
accuracy = pipeline.score(X_test, y_test) |
|
print('Accuracy:', accuracy) |
|
joblib.dump(pipeline, 'student_placement_model.joblib') |
|
|
|
|
|
def predict_placement(internships, cgpa, history_of_backlogs, stream): |
|
|
|
pipeline = joblib.load('student_placement_model.joblib') |
|
|
|
|
|
input_data = pd.DataFrame({'internships': [internships], |
|
'cgpa': [cgpa], |
|
'history_of_backlogs': [history_of_backlogs], |
|
'stream': [stream]}) |
|
|
|
|
|
prediction = pipeline.predict(input_data) |
|
|
|
return prediction[0] |
|
|
|
|
|
def streamlit_app(): |
|
title('Student Placement Prediction') |
|
internships = number_input('Number of internships:', min_value=0, max_value=10, step=1) |
|
cgpa = number_input('CGPA:', min_value=0.0, max_value=10.0, step=0.1) |
|
history_of_backlogs = number_input('Number of history of backlogs:', min_value=0, max_value=10, step=1) |
|
stream = selectbox('Stream:', options=['Science', 'Commerce', 'Arts']) |
|
prediction = predict_placement(internships, cgpa, history_of_backlogs, stream) |
|
if prediction == 1: |
|
result = 'Placed' |
|
else: |
|
result = 'Not Placed' |
|
button('Predict Placement') |
|
write(f'Result: {result}') |
|
|
|
if __name__ == '__main__': |
|
streamlit_app() |
|
|