text_plain_output_1.png
from sklearn.utils import resample

from sklearn.utils import resample

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sb

train_data = pd.read_csv('/kaggle/input/heartbeat/mitbih_train.csv', header=None)

test_data = pd.read_csv('/kaggle/input/heartbeat/mitbih_train.csv', header=None)

train_target = train_data[187].value_counts()

np.random.seed(2018)
sample = np.random.choice(train_data.shape[0], 200, replace=False)
subset = train_data.loc[sample]

percentages = [count / subset.shape[0] * 100 for count in subset[187].value_counts()]
percentages[0]

base_color = sb.color_palette()[0]
type_orderion = subset[187].value_counts().index
plt.xticks(rotation=90)

from sklearn.utils import resample
target1 = train_data[train_data[187] == 1]
target2 = train_data[train_data[187] == 2]
target3 = train_data[train_data[187] == 3]
target4 = train_data[train_data[187] == 4]
target0 = train_data[train_data[187] == 0].sample(n=20000, random_state=42)
target1_sample = resample(target1, replace=True, n_samples=20000, random_state=0)
target2_sample = resample(target2, replace=True, n_samples=20000, random_state=0)
target3_sample = resample(target3, replace=True, n_samples=20000, random_state=0)
target4_sample = resample(target4, replace=True, n_samples=20000, random_state=0)
train_data = pd.concat([target0, target1_sample, target2_sample, target3_sample, target4_sample])

train_target = train_data[187].value_counts()

sorted_counts = train_data[187].value_counts()
plt.axis('square')

test_target = test_data[187].value_counts()

sorted_counts = train_data[187].value_counts()
plt.figure(figsize=[12, 5.01])
plt.pie(sorted_counts, labels=sorted_counts.index, startangle=90, counterclock=False)
plt.axis('square')