Lets see how we can quickly train a new model on a new dataset by using a DataSet. Let’s first look at our new Data, this example is Welding_Perceptron_data.xlsx.
import pandas as pddf = pd.read_excel(r"_dlcourse/code/Linear Models/Welding_Perceptron_data.xlsx") #You could also just open this file in Excel pd.set_option('display.colheader_justify', 'center') #pretty print optionpd.set_option('display.precision',3) #pretty print optionprint(f"Total number of samples: {len(df)}")print("Top 5 rows:")print(df.head())
Total number of samples: 480
Top 5 rows:
TrialNo Current Angle Speed Time Height
0 1 160 0 0.005 5.003 39
1 1 160 0 0.005 5.502 39
2 1 160 0 0.005 5.969 39
3 1 160 0 0.005 6.453 38
4 1 160 0 0.005 6.920 40
As you can see, we have 6 columns of data. For this experiment, I want to coorelate the Current, Angle, Speed, and Time to the Height.
Create a Dataset
Let’s first meet the requirments for creating a custom pytorch Dataset, there are three requirements: Inhereit the Dataset class, create a len function, and create a getitem function. Lets also give it a name.
from torch.utils.data import Datasetclass WeldingRegression(Dataset):def__init__(self):super().__init__() def__len__(self):def__getitem__(self, index):
Next, let’s figure out how we are going to read the relevant data in python.
We have now prepared the data for our data loader, the final thing is to include the len function needs to return the total number of samples (that will be going across axis 0). and the getitem