Project 7: Data Visualization

The goals of this project are to practice:


Tasks

0. Setup

Create a Project07 folder on your computer where you store CS151 projects and labs, hopefully somewhere that is backed up (e.g. in Dropbox, Google Drive, Microsoft OneDrive, etc.)

Open up a Terminal and change the directory (cd) to the Project07 folder.

Create a new file called data_transforms.py.

Download the file example.csv.

PROJECT REQUIREMENT: To receive full credit for this project you can only use concepts, control structures, syntactic features, and libraries covered in class.

1. File Processing

First we need to write a function that takes a CSV file, reads it, and organizes the data into a format so that we can graph it.

Write a new function called process_file that takes in the parameter filename. The function creates and returns 2 lists, a list of headers, and a list of lists representing the data.

The function should:

TEST YOUR CODE PART 1: Download the file test_process_file.py. Put it in the same folder as data_transforms.py and example.csv. Run the script python3 test_process_file.py in your terminal. Do not move on to the next part of the project until it prints 5 tests, each test should say "True".

2. Feature Scaling

In data science and statistics, datasets often contain columns with vastly different units or scales (e.g., age vs. annual income). Min-Max Normalization rescales features so that every value falls between 0.0. and 1.0. The mathematical formula for min-max normalization on a value x in column X is: x norm = x − min ( X ) max ( X ) − min ( X )

2a. Find the minimum and maximum

Add the minmax function to data_transforms.py:

def minmax(data):

    '''Finds the minimum and maximum values for each column across a 2D data list.
    
    PARAMETERS:
        data - list of lists (2D list of floats/ints)
        
    RETURNS:
        minimum - list containing the minimum value of each column
        maximum - list containing the maximum value of each column
    '''
    pass

Your function should perform the following operations:

TEST YOUR CODE: Add a main function that calls process_file("example.csv"). Call minmax with the data returned from process_file(). Print the minimum list and the maximum list. Call your main function in your main guard. Compare the values printed to the expected outputs below.


Minimum [0.0, 0.0, 2.0]
Maximum [1.0, 49.0, 99.0]

2b. Normalize Columns

Add the normalizeColumns function to data_transforms.py:

def normalizeColumns(data):

    '''Normalizes all values in a 2D list to the range [0.0, 1.0].
    
    PARAMETERS:
        data - list of lists (2D list of floats/ints)
        
    RETURNS:
        normalizedData - 2D list of scaled float values
        minimum - list of minimum values per column (from minmax)
        maximum - list of maximum values per column (from minmax)
    '''
    pass

Your function should perform the following operations:

TEST YOUR CODE: In your main function call normalizeColumns with the data returned from process_file() as the argument. In main print the first row and the last row of normalizeColumns. Call your main function in your main guard. Compare the values printed to the expected outputs below. Do they look similar?


First Row [1.0, 0.0, 0.26804123711340205]
Last Row [0.0, 1.0, 0.6494845360824743]

3. Graphing

The goal of this portion of the code is to be able to graph the data.

3a. Setup

Create a new file called data_visualization.py.

Import data_transforms.py.

Import only the Turtle class and Screen class from the turtle library.

Copy your goto function from Project 4, as well as the rectangle function from Project 3. Update your rectangle function to have an additional parameter turt (a turtle object), and modify the function to draw using the turt parameter.

3b. Create Screen and Turtle

Create a main function that:

TEST YOUR CODE: Call your main function in your main guard. If you run your code you should have a screen appear that is 550 x 550, which stays open until you click on it.

3c. Create a Scatterplot

Create a scatterplot function that has the following parameters:

The scatter plot should:

TEST YOUR CODE: Call your scatter plot function inside of your main function, after you normalized the data, but before you call update. Test your scatter plot function using "example.csv" as your csv file, "x_axis" for x (index 1), "y_axis" for y (index 2), and "color" for color (index 0). Take a screen shot of your plot. This is required image 1.

3d. Add Command Line Arguments

Modify your code so that it uses command line arguments and then use them to control aspects of the plot. The file should expect the following command line arguments:

Print a usage statement if there aren't enough command line arguments.

TEST YOUR CODE: Download breast-cancer.csv. Call your code with the following command. python3 data_visualization.py breast-cancer.csv 2 3 1 This should produce a new plot. Take a screen shot of your plot. This is required image 2.


Check reproducibility

In order to grade your project, we need to be able to run your code and get the same results as you do! In your project submission ZIP file, please include any PPM images that are needed run your code (including example.csv and breast-cancer.csv).

Here is a summary of the expected outputs from each of the source code files that you created:

PROJECT REQUIREMENT: To receive full credit for this project you can only use concepts, control structures, syntactic features, and libraries covered in class.

If you use command-line arguments, please explain what they are and provide an example way to run your code in your report.


AI Usage Statement

Document your AI usage in the format described here under "AI Usage Statement" OR if you didn't use AI answer the following question. The question should be answered in a short paragraph (100-250 words total) without using AI and take approximately 10-20 minutes to complete, including researching and writing.

Alternative Assignment: Find a specific example of Dynamic Pricing and a company that provides the service. Research and explain an underlying component of the technology, computational method or machine learning model used, be as specific as possible. Describe a potential issue for a company with using dynamic pricing, and how your specific example does or does not address it. Include at least one cited credible source (academic paper, official tech documentation, or reputable technical news outlet).


Extensions

Congratulations on completing the core tasks! If your code and report meet the above expectations, you’ve already earned up to 27/30 points for this project.

The remaining 3/30 are a chance for you to earn credit for exploring parts of this project and digging deeper to express your creativity! This is entirely optional; 27/30 is an A- and is a perfectly respectable place to stop. Extensions are open-ended and exist to compliment the structured core project. Explore and learn something new that interests you! Concentrating your energy on 1-2 "deep" extensions that challenge you will earn you more points than many small, "shallow" extensions.

You can pick your own topics that interest you. Here are a few examples:

  1. Add x and y axis ticks. (.5pt each axis)
  2. Add a legend to your plot. (.5pt)
  3. Adjust your code so your plot can be drawn at any location at any scale. Write a function that draws multiple plots, each showing different data. (1-1.5pts)
  4. Write a function that draws a histogram plot, using data from a csv file. (1.5pts)
  5. Write a function that draws a line graph with multiple lines of data, using data from a csv file. (1.5pts)
  6. Explore the breast cancer dataset. Through creating more graphs and interpreting them, what can you conclude from this dataset. (.5-1pt)
  7. Find your own dataset, import it using python and graph a portion of the data. Interpret the results of the graph in your report. (1-1.5pts)

Submission checklist

To turn in your project, make sure you do all of the following:

Link to detailed turn in instructions and more information about what should be contained in the report


© 2027 Hannen Wolfe