Page 170 - FULL REPORT 30012024
P. 170

return 'Underweight'
                            elif bmi < 25:
                                return 'Normal weight'
                            elif bmi < 30:
                                return 'Overweight'
                            else:
                                return 'Obesity'

                        # Function to predict stroke risk and identify influential factors
                        def predict_stroke_risk(gender, age, hypertension, heart_disease, bmi,
                        smoking_status,
                                                 ever_married, work_type, Residence_type):
                            # Encode categorical variables
                            gender = le_gender.transform([gender])[0]
                            smoking_status = le_smoking_status.transform([smoking_status])[0]
                            ever_married = le_ever_married.transform([ever_married])[0]
                            work_type = le_work_type.transform([work_type])[0]
                            Residence_type = le_Residence_type.transform([Residence_type])[0]
                            age_category = le_age_category.transform([categorize_age(age)])[0]
                            bmi_category = le_bmi_category.transform([categorize_bmi(bmi)])[0]

                            # Create input data for prediction
                            feature_names = ['gender', 'hypertension', 'heart_disease',
                        'ever_married', 'work_type',
                                             'Residence_type', 'age_category', 'bmi_category',
                        'smoking_status']
                            input_df = pd.DataFrame([[gender, hypertension, heart_disease,
                        ever_married, work_type, Residence_type, age_category,
                                                      bmi_category, smoking_status]],
                        columns=feature_names)

                            # Predict stroke risk
                            probability = model.predict_proba(input_df)[:, 1]
                            stroke_risk = probability[0] * 100



                            stroke_risk = round(stroke_risk, 2)

                             # Ensure minimum output is 1
                            if stroke_risk < 1:
                                stroke_risk = stroke_risk + 1


                            return stroke_risk



                        #delete userdata
                        @app.route('/delete_user_data/<string:user_id>', methods=['POST'])
                        def delete_user_data(user_id):

                            mydb = get_db_connection()
                            cursor = mydb.cursor()

                            # Execute the DELETE query
                            cursor.execute("DELETE FROM userdata WHERE id = %s", (user_id,))
                                                               153
   165   166   167   168   169   170   171   172   173   174   175