-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilitys.py
46 lines (37 loc) · 1.61 KB
/
utilitys.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pandas as pd
import numpy as np
from sklearn import preprocessing
class Utilitys:
def preprocess(self, df):
print('Before preprocessing')
print('Number of rows with zero as a variable')
for col in df.columns:
missing_rows = df.loc[df[col] == 0].shape[0]
print(col + ': ' + str(missing_rows))
df['Glucose'] = df['Glucose'].replace(0, np.nan)
df['Pregnancies'] = df['Pregnancies'].replace(0, np.nan)
df['BloodPressure'] = df['BloodPressure'].replace(0, np.nan)
df['SkinThickness'] = df['SkinThickness'].replace(0, np.nan)
df['Insulin'] = df['Insulin'].replace(0, np.nan)
df['BMI'] = df['BMI'].replace(0, np.nan)
df['Glucose'] = df['Glucose'].fillna(df['Glucose'].mean())
df['Pregnancies'] = df['Pregnancies'].fillna(df['Pregnancies'].mean())
df['BloodPressure'] = df['BloodPressure'].fillna(df['BloodPressure'].mean())
df['SkinThickness'] = df['SkinThickness'].fillna(df['SkinThickness'].mean())
df['Insulin'] = df['Insulin'].fillna(df['Insulin'].mean())
df['BMI'] = df['BMI'].fillna(df['BMI'].mean())
print('After preprocessing')
print('Number of rows with zero as a variable')
for col in df.columns:
missing_rows = df.loc[df[col] == 0].shape[0]
print(col + ': ' + str(missing_rows))
df_scaled = preprocessing.scale(df)
df_scaled = pd.DataFrame(df_scaled, columns = df.columns)
df_scaled['Outcome'] = df['Outcome']
df = df_scaled
print(df.describe().loc[['mean','std','max'],].round(2).abs())
print(df.describe())
return df_scaled
df = pd.read_csv('diabetes.csv')
utility = Utilitys()
df_processed = utility.preprocess(df)