End-to-End ML Project- Beginner friendly

52 / 95

Generating test set- Locating data

Finally, we use the loc() method of the DataFrame object to access the DataFrame by training and testing index. Its syntax is-


where df_name is the name of our DataFrame object and indices can be a single index or an array-like. In our case it is array-like.


Call the loc() method on our DataFrame housing providing train_ind and test_ind as indices for generating the training and testing dataset. Store the training data in a variable strat_train_set and testing data in a variable strat_test_set.

Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...