4.1. Exercises

Terminology

Candybars

Instructions:
Running a coding exercise for the first time could take a bit of time for everything to load. Be patient, it could take a few minutes.

When you see ____ in a coding exercise, replace it with what you assume to be the correct code. Run it and see if you obtain the desired output. Submit your code to validate if you were correct.

Make sure you remove the hash (#) symbol in the coding portions of this question. We have commented them so that the line won’t execute and you can test your code after each step.

Describing a Dataset

Let’s make sure we understand all the components we use in a dataset for machine learning. The packages you need will be loaded for you. In this example we would be attempting to predict the country availability of candy bars, which makes the column availability the target.

Task:

  • Save the dimensions of the dataframe in an object named candybar_dim.
Hint 1
  • Are you using .shape to find the dimensions?
Fully worked solution:

Separating Our Data

Let’s split up our the data in the candybars dataframe into our features and target. For this dataframe the features are the columns chocolate to multi and the target is the column availability.

Task 1:

  • Save the columns chocolate to multi in an object named X.
Hint 1
  • Are you using .loc[] to obtain the columns chocolate to multi?
Fully worked solution:

Task 2:

  • Since we are attempting to predict the country availability of candy bars, make the column availability the target and name the object y.
Hint 1
  • Are you select the column availability with single brackets?
Fully worked solution: