TEC-DATA85-11 · Lesson 6 · 12 clock hours · lab
Statistical Analysis or Machine Learning Model for the Urban Question
Objective. Students apply at least one appropriate statistical test or supervised/unsupervised machine-learning model to their analysis-ready dataset and report evaluation metrics and practical significance in the context of their urban research question.
⚠ Pending professional review
This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.
VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.
Choosing the Right Analytical Method
Before writing a single line of code, you must match your method to your urban research question. The wrong method produces misleading results, no matter how clean your data is. Use the decision-tree flowchart your instructor provides as a checklist, then write a short justification in a Markdown cell explaining why the chosen method fits your variable types, sample size, and research goal.
A few common mappings:
- Predicting a continuous outcome (e.g., permit wait time in days, median rent): use linear regression. Check that your residuals are roughly normally distributed and that predictors are not perfectly correlated with each other (multicollinearity).
- Classifying neighborhoods into groups with no pre-existing labels: use k-means clustering or another unsupervised method. You supply the number of clusters k and evaluate cohesion with the silhouette score.
- Testing whether two categorical variables are independent (e.g., transit access level vs. income bracket): use a chi-square test of independence. Confirm that expected cell counts are at least 5 before trusting the result.
- Comparing means across two or more groups: consider a t-test (two groups) or ANOVA (three or more groups), checking normality and equal-variance assumptions first.
Your justification should name the method, state the outcome variable, state the predictor(s) or grouping variable(s), and explain why the assumptions are likely satisfied by your dataset.
Implementing the Model or Test
Once your method is chosen, implement it in Python (scikit-learn, statsmodels, or scipy) or R (caret or tidymodels). Keep all code in clearly labeled cells inside your Jupyter Notebook so the instructor can re-run it from top to bottom without errors.
For supervised learning (e.g., linear regression):
1. Split your data into training and test sets using `train_test_split` or an equivalent.
2. Fit the model on training data only.
3. Compute evaluation metrics on the test set: R-squared tells you the proportion of variance explained; RMSE (root mean square error) tells you average prediction error in the original units.
For unsupervised learning (e.g., k-means):
1. Scale your features first — k-means is sensitive to units.
2. Run the algorithm across a range of k values and plot the elbow curve or silhouette scores to select k.
3. Report the silhouette score for your chosen k; values above 0.50 generally indicate reasonable cluster separation, though this is data-dependent.
For hypothesis tests (e.g., chi-square):
1. State your null hypothesis (H₀: the variables are independent) and your significance level (commonly α = 0.05) before looking at results.
2. Compute the test statistic and p-value.
3. Report effect size alongside the p-value. For chi-square, Cramér's V is a standard effect-size measure. A statistically significant result with a tiny effect size may not matter practically for city policy.
Interpreting Results in Plain Language
Every metric must be translated back into the context of your urban question. A p-value of 0.03 means nothing to a city planner without a sentence like: "Neighborhoods in the lowest transit-access tier were significantly more likely to be in lower-income brackets (χ² = 14.2, df = 4, p = 0.03, Cramér's V = 0.18), suggesting a small but consistent association that warrants further investigation."
Avoid claims of causation unless your study design supports it. Observational city data almost never supports causal language — use words like associated with, predicts, or differs across.
The Peer-Review Stand-Up
In the two-minute stand-up you will state: (1) your urban question, (2) the method you chose and why, and (3) one key metric with a plain-language sentence. Peers will ask at least one question about assumptions or limitations. This is deliberate practice for the workplace, where data professionals must defend their choices clearly and concisely.
After the session, add a Limitations section to your notebook. Common limitations include: small or non-random sample, data collected for administrative rather than research purposes, unobserved confounders, or the temporal mismatch between datasets joined from different years.
Data and Computational Safety
Always work on a copy of your cleaned dataset, never overwrite the analysis-ready file you spent hours preparing. Use version control (Git commits or dated file names) so you can roll back if a transformation produces unexpected results. If your dataset contains any personally identifiable information (PII), confirm with your instructor that it has been appropriately de-identified before sharing your notebook during peer review. Do not upload raw city data containing PII to public repositories.
Key terms10
R-squared (R²)A metric for regression models that expresses the proportion of variance in the outcome variable explained by the predictors; ranges from 0 to 1, with higher values indicating better fit.
RMSE (Root Mean Square Error)The square root of the average squared difference between predicted and actual values; reported in the same units as the outcome variable and reflects average prediction error.
Silhouette scoreA metric for clustering that measures how similar each data point is to its own cluster compared with other clusters; ranges from -1 to 1, with values closer to 1 indicating well-separated clusters.
p-valueThe probability of observing a test statistic at least as extreme as the one computed, assuming the null hypothesis is true; a small p-value (commonly below 0.05) leads to rejection of the null hypothesis.
Effect sizeA quantitative measure of the practical magnitude of a finding, independent of sample size; examples include Cramér's V for chi-square tests and Cohen's d for t-tests.
Cramér's VAn effect-size statistic for chi-square tests of independence that ranges from 0 (no association) to 1 (perfect association) between two categorical variables.
Null hypothesis (H₀)The default assumption in a hypothesis test — typically that there is no effect or no association — which is either rejected or not rejected based on the test statistic and p-value.
Train-test splitThe practice of partitioning a dataset into a training portion (used to fit the model) and a test portion (used only to evaluate out-of-sample performance) to provide an honest estimate of model accuracy.
MulticollinearityA condition in regression where two or more predictor variables are highly correlated with each other, making it difficult to isolate their individual effects on the outcome and inflating standard errors.
Unsupervised learningA class of machine-learning methods that find patterns or groupings in data without using labeled outcome variables; k-means clustering is a common example used in neighborhood typology studies.
Worked examples4
1. A student runs a simple linear regression predicting permit wait time (days) from the number of inspection staff assigned to a district. On the test set of 80 records, the sum of squared residuals is 3200 and the total sum of squares is 8000. What is R-squared, and what does it mean in plain language?
- Write the R-squared formula: R² = 1 − (SS_res / SS_tot).
- Substitute the values: R² = 1 − (3200 / 8000) = 1 − 0.40 = 0.60.
- Interpret: 60% of the variation in permit wait times across districts is explained by the number of inspection staff assigned.
Answer: R² = 0.60. The model explains 60% of the variance in permit wait times; inspection staffing level is a moderately strong predictor, though 40% of variation is due to other factors not captured in this model.
2. The same student computes RMSE. The test set has 4 residuals (for simplicity): 6, −4, 8, and −2 days. Calculate RMSE.
- Square each residual: 6² = 36, (−4)² = 16, 8² = 64, (−2)² = 4.
- Sum the squared residuals: 36 + 16 + 64 + 4 = 120.
- Divide by the number of observations (n = 4): 120 / 4 = 30.
- Take the square root: √30 ≈ 5.48 days.
Answer: RMSE ≈ 5.48 days. On average, the model's predictions miss actual permit wait times by about 5.5 days, which is meaningful context for a city office managing workloads.
3. A student runs a chi-square test of independence to examine whether transit-access tier (Low, Medium, High) is associated with neighborhood income bracket (Below median, Above median). The chi-square statistic is 12.6 with 2 degrees of freedom and a total sample of 200 neighborhoods. Calculate Cramér's V.
- Write the Cramér's V formula: V = √(χ² / (n × (k − 1))), where n is total sample size and k is the smaller of the number of rows or columns.
- Identify values: χ² = 12.6, n = 200, k = 2 (income bracket has 2 categories, the smaller dimension).
- Compute the denominator inside the square root: 200 × (2 − 1) = 200 × 1 = 200.
- Divide: 12.6 / 200 = 0.063.
- Take the square root: √0.063 ≈ 0.251.
Answer: Cramér's V ≈ 0.25. This is a small-to-medium effect. Although the chi-square test is statistically significant (p < 0.05 at df = 2), the association between transit-access tier and income bracket is modest in practical terms.
4. A student evaluates k-means clustering (k = 3) on a neighborhood dataset. Three clusters contain 60, 90, and 50 neighborhoods respectively, with individual silhouette scores summing to 117.5 across all 200 neighborhoods. What is the mean silhouette score, and how should the student interpret it?
- Mean silhouette score = total silhouette score / total number of data points.
- Mean silhouette = 117.5 / 200 = 0.5875.
- Round for reporting: approximately 0.59.
Answer: Mean silhouette score ≈ 0.59. This value is above 0.50, suggesting the three clusters are reasonably well-separated and the k = 3 solution provides a meaningful neighborhood typology, though the student should also review whether the clusters make substantive sense for the urban question.
The math in this lesson1
Learners compute R-squared from residual and total sums of squares and interpret explained variance.
S-ID.6
In class: Students select and justify their analytical method (e.g., linear regression for predicting permit wait times, k-means clustering for neighborhood typology, chi-square test for transit-access disparity) using a decision-tree flowchart provided by the instructor; justification is written in the project notebook as a Markdown cell. · Students implement the model or test in Python or R, compute evaluation metrics appropriate to the method (R-squared, RMSE, silhouette score, p-value with effect size), and interpret results in plain language tied to the city question. · Instructor-led peer-review session: each student presents their method choice and one key metric in a two-minute stand-up; peers ask at least one question about assumptions or limitations; student adds a 'limitations' section to the notebook before final submission.
Materials: Python 3 with scikit-learn, statsmodels, scipy; R with caret or tidymodels (optional); Jupyter Notebook; IBM Data Science Professional Certificate — machine learning module; CompTIA Data+ domain 3 (data analysis) study guide.
Check: Instructor reviews notebook for method justification, correct metric computation (verified by re-running the notebook), and a plain-language interpretation linked to the research question; all three present with no major computational errors = pass.
Practice check8
Answer each question, then check it. Nothing is recorded; this is your own practice.
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.