5.1. Exercises

Fit or Predict

Do the following statements correspond to the fit or the predict stage:

First Step in Building a Model

Question 1

Below is the output of y.value_counts().

Position
Forward     13
Defense      7
Goalie       2
dtype: int64

In this scenario, what would a DummyClassifier(strategy='most_frequent') model predict on the observation:

   No.  Age  Height  Weight  Experience     Salary
1   83   34     191     210          11  3200000.0

Building a Model

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.

Let’s start by building a baseline model using DummyClassifier() on the candybars dataset.

Tasks:

  • Build a baseline model using DummyClassifier() and most_frequent for the strategy argument. Save this in an object named model.
  • Fit your model and then predict on the target column.
  • What is the accuracy of the model to 2 decimal places? Save this in the object accuracy.
Hint 1
  • Are using DummyClassifier(strategy="most_frequent")?
  • Are you using the model named model?
  • Are you calling .fit(X,y) on your model?
  • Are you using model.score(X,y) to find the accuracy?
Fully worked solution: