Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import joblib
|
|
3 |
import numpy as np
|
4 |
import pandas as pd
|
5 |
from huggingface_hub import hf_hub_download
|
6 |
-
from sklearn.preprocessing import
|
7 |
|
8 |
# Load the trained model and scaler objects from file
|
9 |
REPO_ID = "Hemg/modelxxx" # hugging face repo ID
|
@@ -30,6 +30,7 @@ def encode_categorical_columns(df):
|
|
30 |
df = pd.get_dummies(df, columns=nominal_columns, drop_first=True)
|
31 |
|
32 |
return df
|
|
|
33 |
def predict_performance(Location, Course, College, Faculty, Source, Event, Presenter, Visited_Parent, Visited_College_for_Inquiry, Attended_Any_Event, College_Fee, GPA, Year):
|
34 |
input_data = [Location, Course, College, Faculty, Source, Event, Presenter, Visited_Parent, Visited_College_for_Inquiry, Attended_Any_Event, College_Fee, GPA, Year]
|
35 |
|
@@ -41,32 +42,45 @@ def predict_performance(Location, Course, College, Faculty, Source, Event, Prese
|
|
41 |
|
42 |
input_df = pd.DataFrame([input_data], columns=feature_names)
|
43 |
|
44 |
-
|
45 |
-
# Debug print 2: Show DataFrame before encoding
|
46 |
print("\nDataFrame before encoding:")
|
47 |
print(input_df)
|
48 |
|
49 |
# Encode categorical columns
|
50 |
df = encode_categorical_columns(input_df)
|
51 |
|
52 |
-
# Debug print
|
53 |
print("\nDataFrame after encoding:")
|
54 |
print(df)
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
# Scale input data using the loaded scaler
|
57 |
scaled_input = scaler.transform(df)
|
58 |
|
|
|
|
|
|
|
|
|
59 |
# Make the prediction
|
60 |
prediction = model.predict(scaled_input)[0]
|
61 |
|
62 |
# Clip the prediction to be between 0 and 1
|
63 |
prediction = np.clip(prediction, 0, 1)
|
64 |
|
65 |
-
|
66 |
-
# Debug print
|
67 |
print("\nPrediction details:")
|
68 |
print(f"Raw prediction: {prediction}")
|
69 |
-
|
70 |
|
71 |
return f"Chance of Admission: {prediction:.1f}"
|
72 |
|
|
|
3 |
import numpy as np
|
4 |
import pandas as pd
|
5 |
from huggingface_hub import hf_hub_download
|
6 |
+
from sklearn.preprocessing import LabelEncoder
|
7 |
|
8 |
# Load the trained model and scaler objects from file
|
9 |
REPO_ID = "Hemg/modelxxx" # hugging face repo ID
|
|
|
30 |
df = pd.get_dummies(df, columns=nominal_columns, drop_first=True)
|
31 |
|
32 |
return df
|
33 |
+
|
34 |
def predict_performance(Location, Course, College, Faculty, Source, Event, Presenter, Visited_Parent, Visited_College_for_Inquiry, Attended_Any_Event, College_Fee, GPA, Year):
|
35 |
input_data = [Location, Course, College, Faculty, Source, Event, Presenter, Visited_Parent, Visited_College_for_Inquiry, Attended_Any_Event, College_Fee, GPA, Year]
|
36 |
|
|
|
42 |
|
43 |
input_df = pd.DataFrame([input_data], columns=feature_names)
|
44 |
|
45 |
+
# Debug print: Show DataFrame before encoding
|
|
|
46 |
print("\nDataFrame before encoding:")
|
47 |
print(input_df)
|
48 |
|
49 |
# Encode categorical columns
|
50 |
df = encode_categorical_columns(input_df)
|
51 |
|
52 |
+
# Debug print: Show DataFrame after encoding
|
53 |
print("\nDataFrame after encoding:")
|
54 |
print(df)
|
55 |
|
56 |
+
# Ensure the DataFrame has the same columns as the scaler was trained on
|
57 |
+
expected_columns = scaler.feature_names_in_
|
58 |
+
for col in expected_columns:
|
59 |
+
if col not in df.columns:
|
60 |
+
df[col] = 0 # Add missing columns with default value 0
|
61 |
+
|
62 |
+
df = df[expected_columns] # Reorder columns to match the scaler's training data
|
63 |
+
|
64 |
+
# Debug print: Show DataFrame after aligning columns
|
65 |
+
print("\nDataFrame after aligning columns:")
|
66 |
+
print(df)
|
67 |
+
|
68 |
# Scale input data using the loaded scaler
|
69 |
scaled_input = scaler.transform(df)
|
70 |
|
71 |
+
# Debug print: Show scaled input
|
72 |
+
print("\nScaled input:")
|
73 |
+
print(scaled_input)
|
74 |
+
|
75 |
# Make the prediction
|
76 |
prediction = model.predict(scaled_input)[0]
|
77 |
|
78 |
# Clip the prediction to be between 0 and 1
|
79 |
prediction = np.clip(prediction, 0, 1)
|
80 |
|
81 |
+
# Debug print: Show prediction details
|
|
|
82 |
print("\nPrediction details:")
|
83 |
print(f"Raw prediction: {prediction}")
|
|
|
84 |
|
85 |
return f"Chance of Admission: {prediction:.1f}"
|
86 |
|