Skip to content

Commit aedb983

Browse files
committed
Reapply "Update link and minor edits"
This reverts commit 42f2672.
1 parent 42f2672 commit aedb983

1 file changed

Lines changed: 26 additions & 26 deletions

File tree

notebooks/v2/analyzing_obesity_prevalence.ipynb

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"id": "view-in-github"
88
},
99
"source": [
10-
"<a href=\"https://colab.research.google.com/github/datacommonsorg/api-python/blob/master/notebooks/analyzing_obesity_prevalence.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
10+
"<a href=\"https://colab.research.google.com/github/datacommonsorg/api-python/blob/master/notebooks/v2/analyzing_obesity_prevalence.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
1111
]
1212
},
1313
{
@@ -57,7 +57,7 @@
5757
"id": "7SnIECsk7Csw"
5858
},
5959
"source": [
60-
"# 1. Setup Environment\n"
60+
"## 1. Set up environment\n"
6161
]
6262
},
6363
{
@@ -66,7 +66,7 @@
6666
"id": "pysygfoq43NF"
6767
},
6868
"source": [
69-
"### 1.1 Install Libraries\n",
69+
"### 1.1 Install libraries\n",
7070
"\n",
7171
"Install the [datacommons-client](https://pypi.org/project/datacommons-client/) library."
7272
]
@@ -92,7 +92,7 @@
9292
}
9393
],
9494
"source": [
95-
"!pip install datacommons-client --upgrade --quiet"
95+
"!pip install \"datacommons-client[Pandas]\" --upgrade --quiet"
9696
]
9797
},
9898
{
@@ -101,7 +101,7 @@
101101
"id": "BtLVyFoN5AiI"
102102
},
103103
"source": [
104-
"### 1.2 Import Dependencies\n",
104+
"### 1.2 Import dependencies\n",
105105
"\n",
106106
"Import required libraries for data manipulation, modeling, and plotting.\n"
107107
]
@@ -134,7 +134,7 @@
134134
"id": "ZXzO6qSc5Xk0"
135135
},
136136
"source": [
137-
"### 1.3 Initialize Data Commons Client\n",
137+
"### 1.3 Initialize Data Commons client\n",
138138
"\n",
139139
"Initialize the client using your Data Commons API key. Obtain a key from [apikeys.datacommons.org](https://apikeys.datacommons.org/) if you don't have one.\n"
140140
]
@@ -158,7 +158,7 @@
158158
"id": "Ccy9-czCfVTn"
159159
},
160160
"source": [
161-
"## 2. Data Acquisition\n",
161+
"## 2. Data acquisition\n",
162162
"\n",
163163
"Fetch statistical observations for the specified variables for all US counties for the year 2021 using the [Python Data Commons API](https://docs.datacommons.org/api/python/v2/)."
164164
]
@@ -567,15 +567,15 @@
567567
"id": "z191ImVmrdds"
568568
},
569569
"source": [
570-
"## 3. Data Preparation\n",
570+
"## 3. Data preparation\n",
571571
"\n",
572572
"Process the fetched data for modeling:\n",
573573
"\n",
574574
"1. **Filter:** Keep only relevant observations based on their `measurementMethod`. For CDC data, this is typically `AgeAdjustedPrevalence`. For Census, `CensusACS5YearSurvey`, and for BLS, `BLSSeasonallyUnadjusted`.\n",
575-
"1. **Select Columns:** Keep only essential columns: `entity`, `entity_name`, `variable`, `value`.\n",
575+
"1. **Select columns:** Keep only essential columns: `entity`, `entity_name`, `variable`, `value`.\n",
576576
"1. **Pivot:** Reshape the dataframe so each variable becomes a column, indexed by county `entity` and `entity_name`.\n",
577-
"1. **Calculate Poverty Rate:** Compute the poverty rate percentage using the population count and the count of people below the poverty level.\n",
578-
"1. **Handle Missing Values:** Drop rows (counties) with any missing values for the selected variables.\n"
577+
"1. **Calculate poverty rate:** Compute the poverty rate percentage using the population count and the count of people below the poverty level.\n",
578+
"1. **Handle missing values:** Drop rows (counties) with any missing values for the selected variables.\n"
579579
]
580580
},
581581
{
@@ -949,7 +949,7 @@
949949
}
950950
],
951951
"source": [
952-
"# Filter the dataframe to only include age adjusted values\n",
952+
"# Filter the dataframe to only include age-adjusted values\n",
953953
"valid_methods = ['AgeAdjustedPrevalence', 'CensusACS5yrSurvey', 'CensusACS5YearSurvey', 'BLSSeasonallyUnadjusted'] # Add all the methods you want to keep\n",
954954
"\n",
955955
"filtered_df = us_county_observations_df.loc[us_county_observations_df['measurementMethod'].isin(valid_methods), ['entity', 'entity_name', 'variable', 'value']]\n",
@@ -975,7 +975,7 @@
975975
"id": "-ZGRFaJKdHIO"
976976
},
977977
"source": [
978-
"## 4. Exploratory Data Analysis\n",
978+
"## 4. Exploratory data analysis\n",
979979
"\n",
980980
"Visualize the relationships between the target variable (Obesity Prevalence) and the predictor variables (High Blood Pressure Prevalence, Unemployment Rate, Poverty Rate) using scatter plots. This helps assess potential correlations.\n"
981981
]
@@ -1102,7 +1102,7 @@
11021102
"id": "Bp52dWJNfYSa"
11031103
},
11041104
"source": [
1105-
"## 5. Model Training\n",
1105+
"## 5. Model training\n",
11061106
"\n",
11071107
"Train a linear regression model to predict obesity prevalence based on the selected predictors.\n",
11081108
"\n",
@@ -1111,7 +1111,7 @@
11111111
"$$f_\\theta(x) = \\theta_0 + \\theta_1 (\\text{high blood pressure}) + \\theta_2 (\\text{unemployment}) + \\theta_3(\\text{poverty rate})$$\n",
11121112
"<br>\n",
11131113
"\n",
1114-
"### 5.1 Prepare Features and Target Variable\n",
1114+
"### 5.1 Prepare features and target variable\n",
11151115
"Define the feature matrix `X` (predictors) and the target vector `Y` (obesity prevalence).\n",
11161116
"\n",
11171117
"Let's start by creating our training and test sets. We'll then train a linear regression model using Scikit learn's [LinearRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html)"
@@ -1137,7 +1137,7 @@
11371137
"id": "rmidaLTx_6C9"
11381138
},
11391139
"source": [
1140-
"### 5.2 Split Data\n",
1140+
"### 5.2 Split data\n",
11411141
"\n",
11421142
"Split the data into training and testing sets (80% train, 20% test).\n",
11431143
"\n"
@@ -1176,7 +1176,7 @@
11761176
"id": "hu2t8OAGAGFp"
11771177
},
11781178
"source": [
1179-
"### 5.3 Train Linear Regression Model\n",
1179+
"### 5.3 Train linear regression model\n",
11801180
"\n",
11811181
"Instantiate and train the [LinearRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html) model using the training data.\n",
11821182
"\n"
@@ -1217,7 +1217,7 @@
12171217
"id": "dBmThySxaXKp"
12181218
},
12191219
"source": [
1220-
"## 6. Model Evaluation\n",
1220+
"## 6. Model evaluation\n",
12211221
"\n",
12221222
"Assess the performance of the trained model using the Mean Squared Error (MSE) metric and residual analysis.\n",
12231223
"\n",
@@ -1271,7 +1271,7 @@
12711271
"id": "VsGLliuzawPE"
12721272
},
12731273
"source": [
1274-
"### 6.2 Analyze Residuals\n",
1274+
"### 6.2 Analyze residuals\n",
12751275
"\n",
12761276
"Calculate and plot the residuals (difference between predicted and actual values) for the test set. Residuals ideally should be randomly scattered around zero."
12771277
]
@@ -1330,23 +1330,23 @@
13301330
"id": "qapl33x8fy_A"
13311331
},
13321332
"source": [
1333-
"## 7. Conclusion and Next Steps\n",
1333+
"## 7. Conclusion and next steps\n",
13341334
"This notebook demonstrated the use of Data Commons to efficiently acquire data from multiple sources (CDC, BLS, Census) and build a simple linear regression model to predict obesity prevalence in US counties. Data Commons significantly streamlines the data gathering and integration process.\n",
13351335
"\n",
13361336
"The resulting model, using high blood pressure prevalence, unemployment rate, and poverty rate, provides a baseline prediction.\n",
13371337
"\n",
1338-
"**Potential Improvements & Further Exploration:**\n",
1338+
"**Potential improvements & further exploration:**\n",
13391339
"\n",
1340-
"* Add More Variables: Incorporate other variables known or hypothesized to correlate with obesity, such as:\n",
1340+
"* Add more variables: Incorporate other variables known or hypothesized to correlate with obesity, such as:\n",
13411341
" * `Percent_Person_WithHighCholesterol`\n",
13421342
" * `Percent_Person_WithDiabetes`\n",
13431343
" * Educational attainment levels\n",
13441344
" * Access to healthy food outlets\n",
13451345
" * Physical inactivity rates\n",
1346-
"* **Feature Engineering:** Create new features from existing ones.\n",
1347-
"* **Model Selection:** Experiment with different regression models (e.g., Ridge, Lasso, tree-based models).\n",
1348-
"* **Geographic Analysis:** Explore spatial patterns in obesity prevalence and model errors.\n",
1349-
"* **Alternative Data Sources:** Compare model performance using Census unemployment data instead of BLS data.\n",
1346+
"* **Feature engineering:** Create new features from existing ones.\n",
1347+
"* **Model selection:** Experiment with different regression models (e.g., Ridge, Lasso, tree-based models).\n",
1348+
"* **Geographic analysis:** Explore spatial patterns in obesity prevalence and model errors.\n",
1349+
"* **Alternative data sources:** Compare model performance using Census unemployment data instead of BLS data.\n",
13501350
"Data Commons provides access to a wide range of variables, enabling exploration of correlations with factors like university counts, crime rates (e.g., arson), or environmental factors (e.g., snowfall), potentially leading to more comprehensive models."
13511351
]
13521352
}

0 commit comments

Comments
 (0)