Update app.py
Browse files4 unmodified lines5678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273744 unmodified linesfrom sklearn.ensemble import RandomForestClassifier
# Load your model and data preprocessing code here# Load dataset
# Import librariesfrom sklearn.preprocessing import LabelEncoder, OneHotEncoder, StandardScalerfrom sklearn.compose import ColumnTransformerimport pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport seaborn as snsfrom sklearn.model_selection import train_test_splitfrom sklearn.ensemble import RandomForestClassifierfrom sklearn.metrics import accuracy_scorefrom sklearn.pipeline import Pipelineimport gradio as grimport warningswarnings.filterwarnings('ignore')
df = pd.read_csv("/content/drive/MyDrive/Colab Notebooks/Final Project/Prof_Mai_Final_Project_Files/80_20_dataset.csv")
# EDAprint("Program distribution:")print(df['Program'].value_counts())
# Preprocessing setupX = df.drop('Program', axis=1)y = df['Program']
# Identify feature typesnumeric_cols = X.select_dtypes(include=np.number).columns.tolist()categorical_cols = X.select_dtypes(include='object').columns.tolist()
# Create preprocessing pipelinepreprocessor = ColumnTransformer( transformers=[ ('num', StandardScaler(), numeric_cols), ('cat', OneHotEncoder(handle_unknown='ignore'), categorical_cols) ])
# Encode targetlabel_encoder = LabelEncoder()y_encoded = label_encoder.fit_transform(y)
# Train-test splitX_train, X_test, y_train, y_test = train_test_split( X, y_encoded, test_size=0.2, random_state=42, stratify=y_encoded)
# Model pipelinemodel = Pipeline([ ('preprocessor', preprocessor), ('classifier', RandomForestClassifier( class_weight='balanced', random_state=42 ))])
# Train modelmodel.fit(X_train, y_train)
# Evaluationy_pred = model.predict(X_test)accuracy = accuracy_score(y_test, y_pred)print(f'\nModel Accuracy: {accuracy * 100:.2f}%')
# ...
def predict_program(*args):app.py+64