Contents

Note about Labs 5 and 6

Due to a scheduling mixup (my fault), I need to combine Labs 5 and 6 together. Do not worry, it is not “twice” the amount of work - the lab is almost the same length (maybe a little longer) but it is about two disparate topics: advanced git and data visualizations.

Accept Lab 5/6: https://classroom.github.com/a/kBZ7_9T-

Lab 5

After many years of searching, I have found the PERFECT tutorial to help you get more familiar with git commands, particularly branching, and merging - things you will start encountering when you start collaboratively working on the projects. Rather than make this a milestone task though, I will be including it as part of Lab 5. It’s included here so you know that you should do this part of the lab before proceeding to Task 3 onwards. You are responsible for completing the following modules (at minimum):

  • “Main: Introduction Sequence” <- This should mostly be review.

    • Exercise 1

    • Exercise 2

    • Exercise 3

    • Exercise 4

  • “Remote: Push & Pull – Git Remotes” <- This is new stuff and you should spend time working through the tutorial.

    • Exercise 1

    • Exercise 2

    • Exercise 3

    • Exercise 4

    • Exercise 5

    • Exercise 6

    • Exercise 7

    • Exercise 8

Please include screenshots for your Git Tutorial here:

notes/week09/images/ notes/week09/images/

Lab 6

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

A: Setting the Aesthetics for the plots (2 marks)

A1: Set the Seaborn figure theme and scale up the text in the figures (2 marks)

There are five preset Seaborn themes: darkgrid, whitegrid, dark, white, and ticks. They are each suited to different applications and personal preferences. You can see what they look like here.

Hint: You will need to use the font_scale property of the set_theme() function in Seaborn.

# Your Solution Here

B: Exploratory Data Analysis (40 marks)

B1. Describe your dataset (2 marks)

Consider the following questions to guide you in your exploration:

  • Who: Which company/agency/organization provided this data?

  • What: What is in your data?

  • When: When was your data collected (for example, for which years)?

  • Why: What is the purpose of your dataset? Is it for transparency/accountability, public interest, fun, learning, etc…

  • How: How was your data collected? Was it a human collecting the data? Historical records digitized? Server logs?

Hint: The pokemon dataset is from this Kaggle page.

Hint: You probably will not need more than 250 words to describe your dataset. All the questions above do not need to be answered, it’s more to guide your exploration and think a little bit about the context of your data. It is also possible you will not know the answers to some of the questions above, that is FINE - data scientists are often faced with the challenge of analyzing data from unknown sources. Do your best, acknowledge the limitations of your data as well as your understanding of it. Also, make it clear what you’re speculating about. For example, “I speculate that the {…column_name…} column must be related to {….} because {….}.”

B2. Load the dataset from a file, or URL (1 mark)

This needs to be a pandas dataframe. Remember that others may be running your jupyter notebook so it’s important that the data is accessible to them. If your dataset isn’t accessible as a URL, make sure to commit it into your repo. If your dataset is too large to commit (>100 MB), and it’s not possible to get a URL to it, you should contact your instructor for advice.

You can use this URL to load the data: https://github.com/firasm/bits/raw/master/pokemon.csv

# Your solution here

B3. Explore your dataset (3 marks)

Which of your columns are interesting/relevant? Remember to take some notes on your observations, you’ll need them for the next EDA step (initial thoughts).

B3.1: You should start with df.describe().T (2 marks)

See [linked documentation]((https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.describe.html) for the use of include/exclude to look at numerical and categorical data.

# Your solution to output `df.describe.T` for numerical columns:
# Your solution to output `df.describe.T` for categorical columns:

B3.2 Let’s try pandas_profiling now. (1 mark)

Hint: To install the pandas_profiling package, you’ll need to use conda:

  • conda install -c conda-forge pandas-profiling

import pandas_profiling

# Your solution for `pandas_profiling`

B4. Initial Thoughts (2 marks)

B4.1. Use this section to record your observations. (2 marks)

Does anything jump out at you as surprising or particularly interesting?

Where do you think you’ll go with exploring this dataset? Feel free to take notes in this section and use it as a scratch pad.

Any content in this area will only be marked for effort and completeness.

# Your observations here:

  • Obs 1

  • Obs 2

B5. Wrangling (5 marks)

The next step is to wrangle your data based on your initial explorations. Normally, by this point, you have some idea of what your research question will be, and that will help you narrow and focus your dataset.

In this lab, we will guide you through some wrangling tasks with this dataset.

B5.1. Drop the ‘Generation’, ‘Sp. Atk’, ‘Sp. Def’, ‘Total’, and the ‘#’ columns (1 mark)

# Your solution here

B5.2. Drop any NaN values in HP, Attack, Defense, Speed (1 mark)

# Your solution here

B5.3. Reset the index to get a new index without missing values (1 mark)

# Your solution here

B5.4. A new column was added called index; remove it. (1 mark)

# Your solution here

B5.5. Calculate a new column called “Weighted Score” that computes an aggregate score comprising:

  • 20% ‘HP’

  • 40% ‘Attack’

  • 30% ‘Defense’

  • 10% ‘Speed’

(1 mark)

# Your solution here

B6. Research questions (2 marks)

B6.1 Come up with at least two research questions about your dataset that will require data visualizations to help answer. (2 marks)

Recall that for this purpose, you should only aim for “Descriptive” or “Exploratory” research questions.

Hint1: You are welcome to calculate any columns that you think might be useful to answer the question (or re-add dropped columns like ‘Generation’, ‘Sp. Atk’, ‘Sp. Def’.*

Hint2: Try not to overthink this; this is a toy dataset about Pokémon, you’re not going to solve climate change or cure world hunger. Focus your research questions on the various Pokémon attributes, and the types.

# Your solution here:

1. Sample Research Question: Which Pokemon Types are the best, as determined by the Weighted Score?

2. Your RQ 1:

3. Your RQ 2:

B7. Data Analysis and Visualizations

B7.1. Sample Research Question: Which Pokemon Types are the best, as determined by the Weighted Score? (3 marks)

To answer this question, we will first need to do wrangle the data to return the mean Weighted_Score, split by the Pokemon Type 1.

Here is the goal of this analysis:

../../_images/groupby1.png
# Your Solution here

B7.2. Create a violin plot to show the distribution of Weighted_Scores split by all the Pokémon types. (2 marks)

Here is the goal:

../../_images/violin1.png
# Your Solution here

B7.3. Create a Box Plot and overlay a strip plot (2 marks)

Here is the goal:

../../_images/BoxPlot1.png
# Your Solution here 

7.4. Create a Hexbin plot with marginal distributions (2 marks)

This plot helps you visualize large amounts of data (and its distributions) by using colours to represent the number of points in a hexagonal shape.

Here is the goal:

../../_images/jointplot1.png
# Your Solution here 

B7.5. Create a PairPlot of the quantiative features of the pokémon dataset (1 mark)

Here is the goal:

../../_images/pairplot1.png
# Your Solution here

B7.6. Create a visualization that helps you answer your first research question (2 marks)

# Your Solution here

B7.7. Create a visualization that helps you answer your second research question (2 marks)

# Your Solution here

B8. Summary and conclusions (3 marks)

B8.1. Summarize your findings and describe any conclusions and insight you were able to draw from your visualizations. (3 marks)

  • Sample Research Question: Which Pokemon Types are the best, as determined by the Weighted Score? (3 marks)

    • Summary of findings, insight, and conclusions

    • ..

  • Research Question 1: RQ here

    • Summary of findings, insight, and conclusions

    • ..

  • Research Question 2: RQ here

    • Summary of findings, insight, and conclusions

    • ..

C. Method Chaining (8 marks)

Method chaining allows you to apply multiple processing steps to your dataframe in a fewer lines of code so it is more readable. You should avoid having too many methods in your chain, as the more you have in a single chain, the harder it is to debug or troubleshoot. I would target about 5 methods in a chain, though this is a flexible suggestion and you should do what makes your analysis the most readable and group your chains based on their purpose (e.g., loading/cleaning, processing, etc…).

Note: See Milestone 2 for a more thorough description of method chaining.

C1. Use Method Chaining on the commands from sections B5.1, B5.2, B5.3, B5.4, B5.5. (4 marks)

# Your Solution here

C2. Use Method Chaining to do the tasks below. (4 marks)

  1. Remove all Pokémon 6th generation and above.

  2. Remove the Legendary column.

  3. Remove all rows that contain “Forme”, a special form of Pokémon.

  4. Remove all rows that contain “Mega”, another weird special form of Pokémon.

Hint: You will need to use the .loc in combination with the anonymous function lambda.

# Your Solution here

D. (OPTIONAL) Advanced Visualizations

D1. Create a “Ridgeline” plot fron the plots from B7.2 and B7.3 (2 marks).

Here is the goal:

../../_images/ridgeline1.png
# Your Solution Here