<jupyter_start><jupyter_text>Load Pytorch Dataset<jupyter_code>from src.models.pytorch import PytorchDataset

train_dataset = PytorchDataset(X=X_train, y=y_train)
val_dataset = PytorchDataset(X=X_val, y=y_val)
test_dataset = PytorchDataset(X=X_test, y=y_test)<jupyter_output><empty_output><jupyter_text>Baseline Model<jupyter_code>from src.models.null import NullModel

baseline_model = NullModel()
y_base = baseline_model.fit_predict(y_train)
y_base
from src.models.null import NullModel

base_model = NullModel(target_type="classification")
y_base = base_model.fit_predict(y_train)
y_base

X_train.shape
from src.models.performance import print_reg_perf
print_reg_perf(y_base, y_train, set_name='Training')
import torch.nn.functional as F
import torch
import torch.nn as nn
from src.models.pytorch import PytorchMultiClass

model = PytorchMultiClass(X_train.shape[1])
from src.models.pytorch import get_device

device = get_device()
model.to(device)
criterion = nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.1)
from src.models.pytorch import train_classification, test_classification

N_EPOCHS = 10
BATCH_SIZE = 32

for epoch in range(N_EPOCHS):
    train_loss, train_acc = train_classification(train_dataset, model=model, criterion=criterion, optimizer=optimizer, batch_size=BATCH_SIZE, device=device)
    valid_loss, valid_acc = test_classification(val_dataset, model=model, criterion=criterion, batch_size=BATCH_SIZE, device=device)

    print(f'Epoch: {epoch}')
    print(f'\t(train)\t|\tLoss: {train_loss:.4f}\t|\tAcc: {train_acc * 100:.1f}%')
    print(f'\t(valid)\t|\tLoss: {valid_loss:.4f}\t|\tAcc: {valid_acc * 100:.1f}%')<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup