I saw this Python code which creates a test set. Can anyone explain to me how the last line of code works?

Viewed 37

I am currently learning machine learning and I saw this block of code. I don't understand the last line. What is data.iloc supposed to do?

import numpy as np

def shuffle_and_split_data(data, test_ratio):
    shuffled_indices = np.random.permutation(len(data))
    test_set_size = int(len(data) * test_ratio)
    test_indices = shuffled_indices[:test_set_size]
    train_indices = shuffled_indices[test_set_size:]
    return data.iloc[train_indices], data.iloc[test_indices]
0 Answers
Related