From 05c892510af16493f27d8ccb50b5705c772553e8 Mon Sep 17 00:00:00 2001 From: s487178 Date: Wed, 5 Apr 2023 19:40:37 +0200 Subject: [PATCH] update python file --- body_performance.py | 92 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 20 deletions(-) diff --git a/body_performance.py b/body_performance.py index 6c81631..9f8dd21 100644 --- a/body_performance.py +++ b/body_performance.py @@ -7,13 +7,13 @@ import pandas as pd import plotly.express as px import seaborn as sns +from sklearn.model_selection import train_test_split +from sklearn.preprocessing import MinMaxScaler -df = pd.read_csv(r'./body_performance.csv') +df = pd.read_csv(r'.\body_performance.csv') -#print(df.dtypes) -#df['BMI'] = float(df['weight_kg'])/(float(df['height_cm'])*0.01)^2 df['BMI'] = df['weight_kg']/(0.0001*df['height_cm']*df['height_cm']) -df.head() +print(df.head()) # In[ ]: @@ -29,9 +29,39 @@ df_copy = df.copy() # In[ ]: +body_train, body_test = train_test_split(df, test_size=int(df["age"].count()*0.2), random_state=1) +body_test, body_valid = train_test_split(body_test, test_size=int(body_test["age"].count()*0.5), random_state=1) + +print("number of elements in data frame: {}".format(df['age'].count())) +print("train: {}".format(body_train["age"].count())) +print("test: {}".format(body_test["age"].count())) +print("valid: {}".format(body_valid["age"].count())) + + +# In[ ]: + + +print(df.describe(include='all')) +#sit and bend forward_cm jest na minusie!!! + + +# In[ ]: + + +scaler = MinMaxScaler() +df[['age', 'height_cm', 'weight_kg','body fat_%', + 'diastolic','systolic','gripForce','sit-ups counts', + 'broad jump_cm','BMI']] = scaler.fit_transform(df[[ + 'age', 'height_cm', 'weight_kg','body fat_%', + 'diastolic','systolic','gripForce','sit-ups counts', + 'broad jump_cm','BMI']]) + +scaler = MinMaxScaler(feature_range=(-1, 1)) +df['sit and bend forward_cm'] = scaler.fit_transform(df[['sit and bend forward_cm']]) df.describe(include='all') + # In[ ]: @@ -41,48 +71,70 @@ df.info() # In[ ]: -df["class"].value_counts().plot(kind="bar") +print('Each class in data frame: \n{}'.format(df['class'].value_counts())) +print('Each class in train data: \n{}'.format(body_train['class'].value_counts())) +print('Each class in test data: \n{}'.format(body_test['class'].value_counts())) +print('Each class in valid data: \n{}'.format(body_valid['class'].value_counts())) # In[ ]: -df[["class","body fat_%"]].groupby("class").mean().plot(kind="bar") + # In[ ]: -sns.set_theme() -sns.relplot(data = df.head(200), x = 'broad jump_cm', y = 'sit-ups counts', hue = 'class') + # In[ ]: -sns.relplot(data = df[df['gender'] == 'M'].head(200), x = 'body fat_%', y = 'BMI', hue = 'class') +#df["class"].value_counts().plot(kind="bar") # In[ ]: -sns.relplot(data = df[df['gender'] == 'F'].head(200), x = 'body fat_%', y = 'BMI', hue = 'class') +#df[["class","body fat_%"]].groupby("class").mean().plot(kind="bar") # In[ ]: -px.box(df, y=['height_cm', - 'weight_kg', - 'body fat_%', - 'diastolic', - 'systolic', - 'gripForce', - 'sit and bend forward_cm', - 'sit-ups counts', - 'broad jump_cm', - 'BMI']) +#sns.set_theme() + +#sns.relplot(data = df.head(200), x = 'broad jump_cm', y = 'sit-ups counts', hue = 'class') + + +# In[ ]: + + +#sns.relplot(data = df[df['gender'] == 'M'].head(200), x = 'body fat_%', y = 'BMI', hue = 'class') + + +# In[ ]: + + +#sns.relplot(data = df[df['gender'] == 'F'].head(200), x = 'body fat_%', y = 'BMI', hue = 'class') + + +# In[ ]: + + +#px.box(df, y=['height_cm', +# 'weight_kg', +# 'body fat_%', +# 'diastolic', +# 'systolic', +# 'gripForce', +# 'sit and bend forward_cm', +# 'sit-ups counts', +# 'broad jump_cm', +# 'BMI']) # In[ ]: