4.1. Exercises

Pipeline Questions

Pipeline True or False

Applying Pipelines

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.

Using our trusty basketball letโ€™s impute, scale and fit a model using a pipeline to see the results.

Tasks:

  • Build a pipeline named bb_pipe it should impute using SimpleImputer and a โ€œmedianโ€ strategy, scale using StandardScaler and build a KNeighborsClassifier.
  • Cross-validate on bb_pipe using X_train and y_train and save the results in an object named cross_scores.
  • Transform cross_scores to a dataframe, take the mean of each column and save the result in an object named mean_scores.
Hint 1
  • Are you using SimpleImputer(strategy="median") as the first step in the pipeline?
  • Are you using StandardScaler() as a second step in the pipeline?
  • Are you using KNeighborsClassifier() as the third step in the pipeline?
  • Are you using cross_validate(bb_pipe, X_train, y_train, return_train_score=True) to cross-validate?
  • Are you using pd.DataFrame(cross_scores).mean() to see your results?
Fully worked solution: