Nov 16, 2026 | 835 words | 8 min read
12.3.1. PY: Regression#
Task #1: Wabash River Health - Dissolved Oxygen Analysis#
Background#
Dissolved Oxygen (DO) is one of the most critical indicators of river health. Fish and aquatic organisms need adequate DO to survive. DO levels are strongly influenced by water temperature: warmer water holds less dissolved oxygen (an inverse relationship).
As a junior environmental engineer at the fictional Wabash River Authority, you have been given 20 water quality measurements collected over a summer monitoring campaign. For this task you will:
Visualize the relationship between temperature and DO
Build a linear regression model to predict DO from temperature
Evaluate your model’s performance
Use your model to make engineering decisions
Required Files#
Download the template
ENGR131_Python_Template.pyand save as 12_3_1_username.py.Download the CSV file
river_data.csvfor analyzing the Wabash river dissolved oxygen data. Do not submit this file to GradescopeCreate and save your figures as PNG files:
Figure 1: 12_3_1_do_temp_plot_username.png
Figure 2: 12_3_1_do_temp_regression_plot_username.png
Download the
report template, complete it, and save it as 12_3_1_report_username.pdf.
Reminder
Review and reference the Python Style Guide to create a professionally formatted code file. For example, remember to provide detailed comments throughout your code so anyone can read them and understand what your program does!
Program Requirements#
Dataset Description
You are provided with a CSV file named: river_data.csv. The dataset contains water quality measurements collected at three Wabash River monitoring sites.
Dataset Columns
Column |
Description |
|---|---|
sample_id |
Unique sample identifier |
site |
Monitoring site (A = upstream, B = midstream, C = downstream) |
temp_c |
Water temperature (\(^\circ\text{C}\)) |
do_mg_l |
Dissolved oxygen concentration (mg/L) |
ph |
Water pH |
Required Libraries
numpy
pandas
matplotlib
Part 1: Load and Explore the Dataset#
Import the required libraries
Load the CSV file into a pandas DataFrame
Display all rows in the DataFrame.
Print:
A formatted assignment header
Summary statistics for:
temperature
dissolved oxygen
pH
See the sample output below to review formatting of program output.
Hint
Use the describe() function to generate summary statistics.
Part 2: Exploratory Scatter Plot#
Create a scatter plot showing the relationship between water temperature (x-axis) and dissolved oxygen concentration. Use a separate color and marker shape for each monitoring site. Be sure to follow the professional plotting guidelines to ensure readability.
Save Figure 1 as a PNG using the file name specified in the Required Files section.
Part 3: Linear Regression Analysis#
Fit a linear regression model to the temperature and dissolved oxygen data:
Define the independent variable (x, temperature) and dependent variable (y, dissolved oxygen concentration).
Use the
polyfit()function to fit a linear model to the data.Compute predicted y-values for the regression model.
Calculate Sum of Squared Errors (SSE), Sum of Square Total (SST), and \(r^2\) value. Equations for SSE, SST, and \(r^2\) can be found in the Linear Regression Excel materials.
Display your results in the following order (see sample output) and format values to 3 decimal places.
Slope
Intercept
SSE
SST
\(r^2\)
Part 4: Regression Line Plot#
Plot the linear regression model on the same figure as the scatter plot. The data markers should overlay the regression line so they are visible. Ensure the plot has an informative title and a legend with labels for the data markers and regression line. The regression label should display both the model equation and \(r^2\) value.
Save Figure 2 as a PNG using the file name specified in the Required Files section.
Sample Output#
Sample Output
Task #2: Analysis Questions#
Complete the analysis questions in the report template downloaded from the Required Files section. Use specific examples from your program to support your responses and use clear, professional language.
Save the completed report using the file name specified in the Required Files section.
Gradescope Submission#
Attention
Before submitting your python file, comment all lines with plt.show() for autograding purposes.
Save Deliverables: Ensure all required assignment files are saved and named exactly as specified in the assignment instructions. If a template file name contains the word
template, replace only that word with your Purdue username. When a task lists more than one deliverable, such as a workbook and a report, submit each deliverable to its own matching Gradescope assignment instead of combining them into one upload.Navigate to Gradescope: Log in to Gradescope. From your Dashboard, open the assignment.
Upload your work: Select the Upload submission method. Drag and drop all required files (or a compressed
.zipfolder) into Gradescope, and select Upload.Confirm Submission: When your upload is successful, you will see a confirmation message on your screen and receive an automated email receipt.
Add Team Members (if applicable): If this is a team assignment, add all team members to the submission. Each teammate should confirm they can see the submission in their own Gradescope account. For help, visit Gradescope’s documentation on adding team members.
Review Autograder Results: Wait a few minutes for the autograder to evaluate the relevant files. Scroll down to view any failed test cases. If you need assistance interpreting the output or errors, ask your teaching team.
Resubmit if Necessary: You can edit your files and select Resubmit as many times as you need before the assignment deadline. Only your final, active submission is graded. (Note: If you need to resubmit, you must upload all required files for the assignment again).
For a detailed walkthrough, review the official Gradescope Submission Guide.