text_html_output_1.png
from sklearn.utils import resample

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

df = pd.read_csv('/kaggle/input/diabetes-prediction-dataset/diabetes_prediction_dataset.csv')

df = df[df.gender != 'Other']
df['gender'].replace(['Female', 'Male'], [0, 1], inplace=True)
df.smoking_history.replace(['No Info', 'never', 'former', 'current', 'not current', 'ever'], [0.5, 0, 0.5, 1, 0.5, 0.5], inplace=True)

corr = df.corr()
corr.style.background_gradient(cmap='coolwarm')

df.diabetes.value_counts()

def plot_histogram(dataset: pd.DataFrame):
    unique_labels, counts = np.unique(dataset.diabetes, return_counts=True)

from sklearn.utils import resample
df_majority = df[df.diabetes == 0]
df_minority = df[df.diabetes == 1]
df_majority_downsampled = resample(df_majority, replace=False, n_samples=df.diabetes.value_counts()[1], random_state=1234)
df_downsampled = pd.concat([df_majority_downsampled, df_minority])

plot_histogram(df_downsampled)