<jupyter_start><jupyter_text>Lambda School Data Science - Making Data-backed AssertionsThis is, for many, the main point of data science - to create and support reasoned arguments based on evidence. It's not a topic to master in a day, but it is worth some focused time thinking about and structuring your approach to it.  Assignment - what's going on here?Consider the data in `persons.csv` (already prepared for you, in the repo for the week). It has four columns - a unique id, followed by age (in years), weight (in lbs), and exercise time (in minutes/week) of 1200 (hypothetical) people.Try to figure out which variables are possibly related to each other, and which may be confounding relationships.Try and isolate the main relationships and then communicate them using crosstabs and graphs. Share any cool graphs that you make with the rest of the class in Slack!<jupyter_code>!curl https://raw.githubusercontent.com/zwarshavsky/DS-Unit-1-Sprint-1-Dealing-With-Data/master/module3-databackedassertions/persons.csv | head -n 10
# !curl https://raw.githubusercontent.com/zwarshavsky/DS-Unit-1-Sprint-1-Dealing-With-Data/master/module3-databackedassertions/persons.csv
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt


#function for dataframe stats

def df_stats(dataframe):
    try:
        display(dataframe.shape,dataframe.head(),dataframe.isna().sum(),dataframe.dtypes,dataframe.count(),dataframe.describe(),dataframe.describe(exclude="number"))
    except:
        display(dataframe.shape,dataframe.head(),dataframe.isna().sum(),dataframe.dtypes,dataframe.count(),dataframe.describe())



# TODO - your code here
# Use what we did live in lecture as an example

# HINT - you can find the raw URL on GitHub and potentially use that
# to load the data with read_csv, or you can upload it yourself
df = pd.read_csv("https://raw.githubusercontent.com/zwarshavsky/DS-Unit-1-Sprint-1-Dealing-With-Data/master/module3-databackedassertions/persons.csv")


df = df.drop(columns=["Unnamed: 0"])
df_stats(df)<jupyter_output><empty_output><jupyter_text>*Try to predict person's weight. In data set it is not super clear what is the most interesting thing. *Exercise time is in minutes/week of exercise *Do some research on pivot tables in this assignment.<jupyter_code>from collections import namedtuple

User = namedtuple('User', ['age','weight', 'exercise_time'])

example_user = User(18, 140, 65)
print(example_user)
pd.__version__
# !pip install pandas==0.23.4
age_bins = pd.cut(df['age'], 4)  # 4 equal-sized bins
exercise_bins = pd.cut(df['exercise_time'], 4)  # 4 equal-sized bins
weight_bins = pd.cut(df['weight'], 4)  # 4 equal-sized bins


crosstab = pd.crosstab(exercise_bins,weight_bins, normalize='columns')
df_stats(crosstab)
crosstab.plot(kind = "bar");

#the line chart does an excellent job of revealing the relationship between exercise time and weight. As weight increases, exercise time decreases. 
#the counding variable could tell a different story
crosstab.plot();
crosstab2 = pd.crosstab(age_bins,weight_bins, normalize='columns')
df_stats(crosstab2)
crosstab2.plot();
crosstab3 = pd.crosstab(exercise_bins,age_bins, normalize='columns')
df_stats(crosstab3)
crosstab3.plot();
#weight appears to be the outcome given it's uneven distribution. 

display(df["weight"].plot.hist());<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1032219570405728, 'fraction_numerical': 0.011634844868735084, 'mean_word_length': 5.435700575815739, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '87496', 'license': 'MIT', 'n_tokens_mistral': 1092, 'n_tokens_neox': 996, 'n_words': 336, 'path': 'module3-databackedassertions/Zhenya_Warshavsky_LS_DS_113_Making_Data_backed_Assertions_Assignment.ipynb', 'repo_name': 'zwarshavsky/DS-Unit-1-Sprint-1-Dealing-With-Data', 'size': '3352'}