my_project.dataset
Dataset utilities for the automobile price prediction model.
1"""Dataset utilities for the automobile price prediction model.""" 2 3import pandas as pd 4import torch 5from torch.utils.data import Dataset 6 7 8class AutomobileDataset(Dataset): 9 """PyTorch dataset for automobile price prediction. 10 11 Loads a processed Parquet dataset, separates the input features from 12 the target variable, and converts both to PyTorch tensors. 13 14 Parameters 15 ---------- 16 path : str 17 Path to the Parquet file containing the processed automobile data. 18 19 Attributes 20 ---------- 21 X : torch.Tensor 22 Input features as a two-dimensional float32 tensor. 23 y : torch.Tensor 24 Target selling prices as a one-dimensional float32 tensor. 25 26 Examples 27 -------- 28 >>> dataset = AutomobileDataset("data/processed/automobile_dataset.parquet") 29 >>> len(dataset) 30 # Number of samples in the dataset 31 """ 32 33 def __init__(self, path: str): 34 """Initialize the automobile dataset. 35 36 Parameters 37 ---------- 38 path : str 39 Path to the Parquet dataset. 40 """ 41 df = pd.read_parquet(path) 42 43 self.X = torch.tensor( 44 df.drop(columns=["Selling_Price"]).values, 45 dtype=torch.float32 46 ) 47 48 self.y = torch.tensor( 49 df["Selling_Price"].values, 50 dtype=torch.float32 51 ) 52 53 def __len__(self) -> int: 54 """Return the number of samples in the dataset. 55 56 Returns 57 ------- 58 int 59 Number of samples available in the dataset. 60 """ 61 return len(self.X) 62 63 def __getitem__(self, index: int) -> tuple[torch.Tensor, torch.Tensor]: 64 """Return a single sample from the dataset. 65 66 Parameters 67 ---------- 68 index : int 69 Index of the sample to retrieve. 70 71 Returns 72 ------- 73 tuple[torch.Tensor, torch.Tensor] 74 A tuple containing the input features and target selling price. 75 """ 76 return self.X[index], self.y[index]
class
AutomobileDataset(typing.Generic[+_T_co]):
9class AutomobileDataset(Dataset): 10 """PyTorch dataset for automobile price prediction. 11 12 Loads a processed Parquet dataset, separates the input features from 13 the target variable, and converts both to PyTorch tensors. 14 15 Parameters 16 ---------- 17 path : str 18 Path to the Parquet file containing the processed automobile data. 19 20 Attributes 21 ---------- 22 X : torch.Tensor 23 Input features as a two-dimensional float32 tensor. 24 y : torch.Tensor 25 Target selling prices as a one-dimensional float32 tensor. 26 27 Examples 28 -------- 29 >>> dataset = AutomobileDataset("data/processed/automobile_dataset.parquet") 30 >>> len(dataset) 31 # Number of samples in the dataset 32 """ 33 34 def __init__(self, path: str): 35 """Initialize the automobile dataset. 36 37 Parameters 38 ---------- 39 path : str 40 Path to the Parquet dataset. 41 """ 42 df = pd.read_parquet(path) 43 44 self.X = torch.tensor( 45 df.drop(columns=["Selling_Price"]).values, 46 dtype=torch.float32 47 ) 48 49 self.y = torch.tensor( 50 df["Selling_Price"].values, 51 dtype=torch.float32 52 ) 53 54 def __len__(self) -> int: 55 """Return the number of samples in the dataset. 56 57 Returns 58 ------- 59 int 60 Number of samples available in the dataset. 61 """ 62 return len(self.X) 63 64 def __getitem__(self, index: int) -> tuple[torch.Tensor, torch.Tensor]: 65 """Return a single sample from the dataset. 66 67 Parameters 68 ---------- 69 index : int 70 Index of the sample to retrieve. 71 72 Returns 73 ------- 74 tuple[torch.Tensor, torch.Tensor] 75 A tuple containing the input features and target selling price. 76 """ 77 return self.X[index], self.y[index]
PyTorch dataset for automobile price prediction.
Loads a processed Parquet dataset, separates the input features from the target variable, and converts both to PyTorch tensors.
Parameters
- path (str): Path to the Parquet file containing the processed automobile data.
Attributes
- X (torch.Tensor): Input features as a two-dimensional float32 tensor.
- y (torch.Tensor): Target selling prices as a one-dimensional float32 tensor.
Examples
>>> dataset = AutomobileDataset("data/processed/automobile_dataset.parquet")
>>> len(dataset)
<h1 id="number-of-samples-in-the-dataset">Number of samples in the dataset</h1>
AutomobileDataset(path: str)
34 def __init__(self, path: str): 35 """Initialize the automobile dataset. 36 37 Parameters 38 ---------- 39 path : str 40 Path to the Parquet dataset. 41 """ 42 df = pd.read_parquet(path) 43 44 self.X = torch.tensor( 45 df.drop(columns=["Selling_Price"]).values, 46 dtype=torch.float32 47 ) 48 49 self.y = torch.tensor( 50 df["Selling_Price"].values, 51 dtype=torch.float32 52 )
Initialize the automobile dataset.
Parameters
- path (str): Path to the Parquet dataset.