Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import pandas as pd | |
| from sklearn.preprocessing import LabelEncoder | |
| from sklearn.feature_selection import mutual_info_classif | |
| from sklearn.feature_selection import chi2 | |
| def data_description(action_type): | |
| df = pd.read_csv('emp_experience_data.csv') | |
| pd.options.display.max_columns = 25 | |
| pd.options.display.max_rows = 10 | |
| data_encoded = df.copy(deep=True) | |
| categorical_column = ['Attrition', 'Gender', 'BusinessTravel', 'Education', 'EmployeeExperience', 'EmployeeFeedbackSentiments', 'Designation', | |
| 'SalarySatisfaction', 'HealthBenefitsSatisfaction', 'UHGDiscountProgramUsage', 'HealthConscious', 'CareerPathSatisfaction', 'Region'] | |
| label_encoding = LabelEncoder() | |
| for col in categorical_column: | |
| data_encoded[col] = label_encoding.fit_transform(data_encoded[col]) | |
| input_data = data_encoded.drop(['Attrition'], axis=1) | |
| target_data = data_encoded[['Attrition']] | |
| col_values = list(input_data.columns.values) | |
| if action_type == "Input Data": | |
| return input_data.head() | |
| if action_type == "Target Data": | |
| return target_data.head() | |
| if action_type == "Feature Selection By Mutual Information": | |
| feature_scores = mutual_info_classif(input_data, target_data) | |
| data = [["Feature", "Mutual Information (0: independent, 1: dependent)"]] | |
| for score, fname in sorted(zip(feature_scores, col_values), reverse=True)[:10]: | |
| data.append([fname, score]) | |
| return data | |
| if action_type == "Feature Selection By Chi Square": | |
| feature_scores = chi2(input_data, target_data)[0] | |
| data = [["Feature", "Chi-Square (Frequency Distribution)"]] | |
| for score, fname in sorted(zip(feature_scores, col_values), reverse=True)[:10]: | |
| data.append([fname, score]) | |
| return data | |
| inputs = [ | |
| gr.Dropdown(["Input Data", "Target Data", "Feature Selection By Mutual Information", "Feature Selection By Chi Square"], label="Develop Data Models") | |
| ] | |
| outputs = [gr.DataFrame()] | |
| demo = gr.Interface( | |
| fn = data_description, | |
| inputs = inputs, | |
| outputs = outputs, | |
| title="Employee-Experience: Model Development", | |
| allow_flagging=False | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |