Day 4 In-class Assignment: Data and Algorithmic Bias, Academic Integrity, and Coding Best Practices#

✅ Put your name here.#

✅ Put your group member names here.

Learning Goals:#

By the end of this assignment you should be able to:

  • Identify how bias occurs in data and algorithms

  • Understand the impact data and algorithmic bias has on people

  • Apply practices to look for bias in your work and others, and minimize it

  • Search on google for snippets of code and compose solutions with integrity

  • Construct variable names following best coding practices

Part 1: Discussing Data and Algorithmic Bias#

In the Pre-class you explored the concepts of Data and Algorithmic Bias by watching videos and reading an article.

✅  Activity:

Go around the group and take about 2 minutes per person for each person to summarize their thoughts/reflections from the pre-class assignment. Record the results of your group discussion below. Make sure to include any observations made by your classmates that perhaps you didn’t think about when you did the pre-class assignment.

Write your response here

✅  Activity:

Below there are several short articles that discuss examples of data or algorithmic bias.

Each group member should choose a different article.

Take 10-15 minutes to read your article and prepare answers to the questions below.

Then, take 1-2 minutes each to share your answers to the questions with your group members.

Finally, identify 1-2 things from your discussion that you will share out to the class.

Examples here:#

Questions for Discussion:#

  • How is data being used?

  • How does the actual usage of data relate to its intended usage?

  • Who owns and/or controls the data?

  • Who benefits from the data usage?

  • How is the data usage related to bias?

Write your response here


Part 2: Practice searching for snippets of code and constructing your own code#

As stated in the pre-class, we want you to learn how to use the internet as a resource in your coding. In general, you should practice taking problems and breaking them into sub-problems. Searching on the internet for solutions to sub-problems is an important skill. It is also important to make sure that you do not take credit for someone else’s work as your own.

Guidelines for Using Code You Didn’t Write: If you are using content to solve problems that has not been covered in our pre-class or in class assignments, you MUST cite your work. This includes any use of the resources reviewed today. We have not yet discussed responsible and effective use of generative AI tools (and you are still learning the necessary basics!), so you are not encouraged to use it at this time (wait for Day 7!). However, if you do use generative AI tools, you must indicate which tool you used (e.g. chatGPT, Co-Pilot, Claude, etc.) and what lines of code were produced by generative AI and which ones were produced by you. Failure to properly cite your work may result in loss of points on the problem.

When you find helpful code from peers or the internet, you should write this code in your words and, when appropriate, indicate where your original code originated from. Specifically:

  1. Rename all variables using variable names that make sense to you.

  2. Use your own structure (i.e. order the code in a way that makes the most sense to you)

  3. Add comments to help clarify complicated syntax

  4. If you received substantive value from another source (for example, complicated syntax or > 5 lines of content), cite the source (Author, URL, and Date Accessed)

✅  2.1 Question: Construct a list of items and quantities for a grocery list. Using the following two lists that have been provided, make a new list that contains all string-type variables such that the value at each index i in the new list should be the concatenation of the values for index i from list1 and list2. When complete, the final list should be

['apples_5', 'oranges_2', 'bananas_4', 'kiwi_1', 'rambutan_10']

Remember, do not place this exact question into google. We do not want you to find the whole solution to a whole problem because a) you will not learn how to code on your own, b) you may feel tempted to plagiarize someone else’s complete work, and c) you likely will waste time because the answer for this specific problem is not out there.

Instead, break this into smaller problems and search for those. Potential google search phrases:

python construct a list

python loop through a list

python concatenate values

Notice that when searching for ways to accomplish this task using Python, it is important to include “python” in your search phrase!

Talk with your group about other useful search phrases and share the resources you locate!

# Remember, if you use a source, 
# 1) Rename the variables, 
# 2) Use your own structure, 
# 3) Add comments to help clarify complicated syntax
# 4) Cite the source if it provides substanative value
list1 = ['apples','oranges','bananas','kiwi','rambutan']
list2 = [5,2,4,1,10]

# Put your code here

Part 3: Python Coding Conventions#

Code is read much more often than it is written. ~Guido van Rossum, Author of PEP8

There are several proposed Python Enhancement Proposals (PEP), with the goal to improve the readability and consistency of Python code. PEP 8 is a document that provides guidelines and best practices on how to write Python code. In your studies and career, you may spend a few minutes, or a whole day, writing a piece of code. Once it is written, you will likely not need to write it again, but you will likely need to read it. And, others will need to read it and understand what you have written. Readability matters, motivating the effort to write code following certain consistency rules.

There are numerous conventions for Python coding. For now, we do not want to bog you down with all the details. For now, we will focus on best practices for naming data types (variables, functions,etc) and for commenting code.

Name Conventions

Choosing sensible names will save you time and energy later. The best way to name your objects in Python is to use descriptive names to make it clear what the object represents.

Type

PEP8 Naming Convention

Examples

Variable

Use a lowercase single letter, word, or words. Separate words with underscores to improve readability.

length_inches, list_groceries, my_variable

Function

Use a lowercase word or words. Separate words by underscores to improve readability.

multiple_by_three, my_function

Tips:

  • Never use spaces in your names (use underscores instead so that each name is a string of characters)

  • Avoid single character names unless it is clear what it means (ex: growth_rate is preferred to g)

  • If variable contains a value with units, include units in the name (ex: weight_kg, height_ft)

  • Avoid capitalizing variable and function names (capitals will be used for naming classes/constants/others objects, that come later)

Comment Conventions

Especially when learning to code, feel free to use comments often! This will help you understand your code and make it easier for you to review later. If you are tasked with a challenging task, use a comment block at the beginning to describe in your own words the goal of your code.

For more information on the PEP8 Python Style Guide, visit How to Write Beautiful Python Code With PEP 8

Now let’s apply these to a real world example!


Part 4: Real World Example: Retirement#

You are interested in saving for retirement and don’t know where to start. Online, you find a website to calculate how much you will save with compound interest given your current savings, monthly contributions, and interest rate. As you poke around the website, you find the Python code used to generate your total retirement savings in this account. Below is the code snippet:

Hint: You may want to check out Day 3 on compound interest.

a= 1000.0
aa =     0.055
B=65-18

tot = []
cs = 0.0
os = 0

for moneymakingYEARZ in range(18,65,1):


    cs= (os) + os**aa + a
    tot.append(cs)

    os = cs

RMONEYZ = tot[-1]
print   (RMONEYZ)
47078.94453057854

✅  4.1 Question: It is pretty clear that the code above does not follow coding conventions. Take some time to go through the code and understand what it is doing. If you saw this code on a website, would you trust it? Was the code hard to read? Why or why not?

Write your response here

✅  4.2 Question: Now that you have an idea of what the code is doing, rewrite the code following the Python coding conventions. Make sure to include comments to explain what the code is doing.

Feel free to look back at Day 3 for help, but use your own explanatory variable names that make the most sense to you and fit the conventions.

#Put your code here.

✅  4.3 Question: You notice that the code is not working as expected, now that the code is in a more readable form. Find the error and fix it. Did you notice the error in the original code provided? Was it easier to find the error in the original code or the new code?

What is the mistake in the code? Did you notice the error in the original code provided? Was it easier to find the error in the original code or the new code?

#Fix the code you wrote above by correcting the mistake.

✅  4.4 Question: Given this example, discuss the importance of coding conventions and commenting code. How do these practices help you and others understand your code? What are the potential consequences of not following these practices?

Your answer here

Let’s take a step back and think about the pre-class assignment for today. We learned about bias and assumptions in data and algorithms. These may not always be harmful, but they do affect the outcomes of our results and are important to be aware of.

Assume that the website only allows you to edit your current savings and monthly contributions.

✅  4.5 Question: What variables from the code are fixed?

Your answer here.

✅  4.6 Question: How do these fixed variables affect the outcome of the code? What assumptions are being made?

Your answer here.

✅  4.7 Question: If I retired at age 70 and started saving at 20, would the code still be relevant, as presented on the website? Why or why not?

Your answer here.

Part 5: Coding Conventions, Open Science, and Code of Ethics#

As you noticed, coding conventions are really important for readability. This is especially important in open science, where the goal is to make scientific research transparent and reproducible.

Open science is an international movement and has recommended guidelines by UNESCO, the United Nations Educational, Scientific, and Cultural Organization.

✅  5.1 Task: Read the short article here.

✅  5.2 Question: Identify two values and guiding principles from the article and discuss how they relate to coding conventions and commenting code.

Your answer here.

The ACM or Association for Computing Machinery has a code of ethics and professional conduct that is important to follow as a computer scientist or data scientist. For more information, you can check out their code of ethics here. You’ll notice the continued emphasis on transparency and accountability.


Part 6: Experimenting with Python dictionaries (time permitting)#

One of the goals of CMSE 201 is for you to develop the skills necessary to learn new Python techniques on the fly by reading pieces of code and searching google for useful information when necessary – let’s give that a shot!

Hopefully you’re starting to feel comfortable with Python lists at this point, but this isn’t the only tool available for storing information in Python. Another useful Python object for storing information is called a “dictionary”. Rather than using integer numbers as the indices for accessing the information contained within the dictionary, a Python dictionary uses words, called “keys”, to access the information.

Take a look at the code below. This code creates a simple dictionary that stores information about CMSE 201 this semester and then prints out a bit of information about the course.

# Create a dictionary to store information about CMSE 201
course = {"course_title": "Computational Modeling and Data Analysis I",
           "course_code": "CMSE",
           "course_number": 201,
           "section_numbers": [1,2,3,4,5,6,7,8],
           "instructors": ['Yadav','Nnadi', 'Termuhlen','Termuhlen','Christlieb','Bao','Bhattacharya','Khasawneh']}

# print some information about the course
print('The instructors for '+course['course_code']+str(course['course_number'])+' are:\n')
for name in course['instructors']:
    print(name)
            
The instructors for CMSE201 are:

Yadav
Nnadi
Termuhlen
Termuhlen
Christlieb
Bao
Bhattacharya
Khasawneh

✅  Review the above code and talk with your group to ensure that you understand what the code is doing. In a new Markdown cell below this one, write down everything you notice about how a Python dictionary is created when compared to a Python list and how information stored in the dictionary is accessed. Also comment on anything else you noticed about the code that you find interesting or new to you.

✅  Practice creating your own python dictionary. In a new code cell, create a Python dictionary that stores a bit of information about yourself:

  • Your name as a string

  • Your major as a string

  • The year that your favorite song, movie, or book was first released or published as an integer

  • The courses you’re currently taking this semester as a list

Once you’ve created the dictionary, try printing out some of the information from the dictionary to make sure you set it up correctly.


🛑 STOP#

Check in with an instructor before you leave class!


Assignment wrapup#

Please fill out the form that appears when you run the code below. You must completely fill this out in order to receive credit for the assignment!

from IPython.display import HTML
HTML(
"""
<iframe 
	src="https://cmse.msu.edu/cmse201-ic-survey" 
	width="800px" 
	height="600px" 
	frameborder="0" 
	marginheight="0" 
	marginwidth="0">
	Loading...
</iframe>
"""
)

Congratulations, you’re done!#

Submit this assignment by uploading it to the course Desire2Learn web page. Go to the “In-class assignments” folder, find the appropriate submission link, and upload it there.

See you next class!

Copyright © 2025, Department of Computational Mathematics, Science and Engineering at Michigan State University, All rights reserved.