Link Search Menu Expand Document

A5—Altair basic charts

Due F 2022-02-25, 11:59pm EST 16pts

Follow all the instructions below.

Please post any questions about this assignment on Canvas in Discussion: A5—Altair basic charts.

Warning: This is an individual assignment.

Table of contents

Change log

  • 2022-02-22: Clarified how many charts to make.

Aim of the assignment

Altair is a declarative statistical visualization library for Python, based on Vega and Vega-Lite. In this assignment, you are going to learn to create two basic visualizations using Altair.

Instructions

If you run into problems see the tips, tricks, and troubleshooting section below.

Please look through all the materials below so you understand the setup instructions; how to run, organize, and submit your code; and our requirements for the visualization.

Setup instructions

  1. Accept the GitHub Classroom assignment invitation by clicking this link to get your repository:

    https://classroom.github.com/a/WOuLKA-e

    For reference, this is the template repository your repository is being created from: https://github.com/NEU-DS-4200-S22/A5--Altair_basic_charts.

    Recall our general instructions and policies on GitHub Classroom assignments.

  2. Clone your GitHub-Classroom-generated repository to your local machine.

    E.g., in your terminal / command prompt CD to where you want the folder for this activity to be. Then run: git clone <YOUR_REPO_URL>

  3. CD or open a terminal / command prompt window into the cloned folder.
  4. Create and activate a virtual environment for this project. You may need to modify the code you use depending on what Python you have installed and how your machine is configured. To do so, run the setup commands below.

    • On macOS or Linux, run these three commands separately in case there are errors:

        python3 -m venv env
      
        source env/bin/activate
      
        which python
      
    • On Windows, run these three commands separately in case there are errors:

        python -m venv env
      
        .\env\Scripts\activate.bat
      
        where.exe python
      

    Check the path(s) provided by which python or where.exe python—the first one listed should be inside the env folder you just created.

  5. Install necessary packages.

     pip install -r requirements-noversions.txt
    

    This may take a few minutes.

    Note that we also include requirements.txt which pins the exact versions of the packages we used at the time of assignment creation. You are welcome to use that instead in case library changes have made the assignment problematic.

Run Jupyter Lab and create a notebook

  1. Run jupyter lab. It should open Jupyter Lab in your default browser.
  2. Create a new Jupyter Notebook named netflix.ipynb.

Once you have written code in a cell you can run it with ctrl+enter. In the menu you can run all cells and restart the kernel to clear variables.

Load the dataset

The data we will be using is included in your template repository in the file netflix_titles.csv. It contains the Netflix Movies and TV Shows dataset from Kaggle. This dataset includes all the TV Shows and Movies that have been uploaded on Netflix before January 17, 2020.

  1. In your notebook, load the CSV file.

Create and discuss two interesting visualizations

  1. Using Altair, create two visualizations to display interesting insights in the Netflix Movies and TV Shows dataset and accompanying prose to discuss them. You will use a Pandas DataFrame. See the documentation on specifying data in Altair.

    Here are some possible questions you can answer:

    • Does the distribution of movie lengths appear gaussian?
    • Who are the directors with the highest average movie rating?
    • Has the rate at which Netflix adds new movies changed through the years?

    Here are the requirements:

    • Each of the two visualizations must be created by a separate code cell in the notebook.
    • Each visualization must be followed by a Markdown cell that explains the visualization, your choices, and the point you are trying to convey.
    • You are free to create any visualization that you like. However, you must explain the reasoning behind your choices, and the visualization must be appropriate for the information you are attempting to learn or convey. (See readings and lecture slides for more details.)

Include your visualizations in README.md

  1. Include both of your images in the README.md file so that they will be displayed when we browse to your GitHub repo. (Not a GitHub Pages site.) If we are unable to run your notebook, at least we can see the output.

    Please see the GitHub Markdown documentation for how to include an image. Note that Altair lets you save a PNG (recommended) or SVG file directly using the menu in the top-right of a visualization. It will likely be easier to include a PNG file correctly than an SVG. However, SVGs are advantageous for publication as they allow further editing using Inkscape or Illustrator.

When you are done…

Clear your output

  1. Before you commit a Jupyter Notebook .ipynb file, you should clear the outputs of all cells. This decreases file size, removes unnecessary metadata, and makes diffs easier to understand. In Jupyter Lab you can use the GUI: Edit->Clear All Outputs.

Quit Jupyter Lab and the virtual environment

  1. Make sure to save your .ipynb file and shutdown Jupyter Lab properly through the file menu. Otherwise, you need to use jupyter notebook stop. ​
  2. Deactivate the venv to return to your terminal using deactivate.

Commit and push your code (but first…)

  1. Only if you have made any changes to the required packages (you probably didn’t), first export a list of all installed packages and their versions:

    pip freeze > requirements.txt
    
  2. Make sure to add all your required files, including the .ipynb file and any images to the git repo.

  3. Finally, commit all your local files and push them to the remote repository on GitHub.

Submission instructions

  1. Ensure that:

    1. Both visualizations and prose are present in your notebook and both visualizations are present in README.md.
    2. You cleared all cell outputs.
    3. All of your required files including netflix.ipynb and any images are committed and pushed to the remote repository on GitHub which was generated by GitHub Classroom. We will grade based on what is available in that repository.
  2. Submit the URL of your repository to the assignment A5—Altair basic charts in GradeScope.

    Warning: Do not put a link to a personal repository. It must be within our class GitHub organization.

    Note: There is no GitHub Page for Altair assignments.

Grading

CriteriaPoints
Visualization 1 & associated prose8 pts
Visualization 2 & associated prose8 pts
 16 pts

Like usual, the visualizations should follow our the best practices and everything you’ve learned in class up to this point. E.g., include axis labels, appropriate scales, titles, legends, annotations, be neat and clean (not cluttered). Points will be deducted for poor quality or confusing visualizations. Likewise, points will be deducted for spelling and grammar mistakes or not following the directions.

Tips, tricks, & troubleshooting

If you run into trouble, first look at our relevant tutorials which have tips & tricks:


© 2022 Cody Dunne. Released under the CC BY-SA license