<jupyter_start><jupyter_text>Preparing datasets manualy without pytorch<jupyter_code>features = df.drop('target', axis=1).values
label = df['target'].values
X_train, X_test, y_train, y_test = train_test_split(features, label, test_size=0.2, random_state=33)
X_train = torch.FloatTensor(X_train)
X_test = torch.FloatTensor(X_test)
y_train = torch.IntTensor(y_train.int()).reshape(-1,1) # reshape to be a column vector
y_test = torch.IntTensor(y_test.int()).reshape(-1,1)
X_train[:3], y_train[:3]<jupyter_output><empty_output><jupyter_text>Preparing with pytorch<jupyter_code>from torch.utils.data import TensorDataset, DataLoader
features = df.drop('target', axis=1).values
label = df['target'].values
iris_ds = TensorDataset(torch.FloatTensor(features), torch.LongTensor(label))
type(iris_ds)
len(iris_ds)
iris_ds[1]<jupyter_output><empty_output><jupyter_text>DataLoaderDataLoader is a wrapper for datasets that adds functionalities such as batch creation, shuffling and others<jupyter_code>iris_loader = DataLoader(iris_ds, batch_size=10, shuffle=True)
# let's check batches

for i_batch, sample_batch in enumerate(iris_loader):
    print(i_batch, sample_batch)<jupyter_output>0 [tensor([[7.1000, 3.0000, 5.9000, 2.1000],
        [7.7000, 2.6000, 6.9000, 2.3000],
        [5.8000, 2.8000, 5.1000, 2.4000],
        [6.7000, 3.3000, 5.7000, 2.5000],
        [4.9000, 2.5000, 4.5000, 1.7000],
        [4.8000, 3.0000, 1.4000, 0.1000],
        [6.5000, 2.8000, 4.6000, 1.5000],
        [5.7000, 4.4000, 1.5000, 0.4000],
        [5.5000, 2.3000, 4.0000, 1.3000],
        [6.7000, 3.1000, 4.4000, 1.4000]]), tensor([2, 2, 2, 2, 2, 0, 1, 0, 1, 1])]
1 [tensor([[4.7000, 3.2000, 1.3000, 0.2000],
        [6.2000, 3.4000, 5.4000, 2.3000],
        [5.1000, 3.3000, 1.7000, 0.5000],
        [6.4000, 3.1000, 5.5000, 1.8000],
        [6.8000, 3.2000, 5.9000, 2.3000],
        [5.4000, 3.9000, 1.3000, 0.4000],
        [4.6000, 3.1000, 1.5000, 0.2000],
        [5.7000, 2.9000, 4.2000, 1.3000],
        [5.6000, 3.0000, 4.1000, 1.3000],
        [5.4000, 3.4000, 1.5000, 0.4000]]), tensor([0, 2, 0, 2, 2, 0, 0, 1, 1, 0])]
2 [tensor([[6.1000, 2.8000, 4.7000, 1.2000],
        [7.2000, 3.2000, [...]
{'fraction_non_alphanumeric': 0.18460833715071004, 'fraction_numerical': 0.21438387540082454, 'mean_word_length': 3.6766595289079227, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '411740', 'license': 'MIT', 'n_tokens_mistral': 1237, 'n_tokens_neox': 904, 'n_words': 186, 'path': 'Courses/PyTorch for Deep Learning with Python/07 ANN/042_DataSets.ipynb', 'repo_name': 'industArk/AI_learn', 'size': '2183'}