20.03.2021 Views

Deep-Learning-with-PyTorch

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

88 CHAPTER 4 Real-world data representation using tensors

4.4.1 Adding a time dimension

In the source data, each row is a separate hour of data (figure 4.5 shows a transposed

version of this to better fit on the printed page). We want to change the row-per-hour

organization so that we have one axis that increases at a rate of one day per index increment,

and another axis that represents the hour of the day (independent of the date).

The third axis will be our different columns of data (weather, temperature, and so on).

Let’s load the data (code/p1ch4/4_time_series_bikes.ipynb).

Listing 4.4

code/p1ch4/4_time_series_bikes.ipynb

# In[2]:

bikes_numpy = np.loadtxt(

"../data/p1ch4/bike-sharing-dataset/hour-fixed.csv",

dtype=np.float32,

delimiter=",",

skiprows=1,

converters={1: lambda x: float(x[8:10])})

bikes = torch.from_numpy(bikes_numpy)

bikes

# Out[2]:

tensor([[1.0000e+00, 1.0000e+00,

[2.0000e+00, 1.0000e+00,

...,

[1.7378e+04, 3.1000e+01,

[1.7379e+04, 3.1000e+01,

..., 1.3000e+01, 1.6000e+01],

..., 3.2000e+01, 4.0000e+01],

..., 4.8000e+01, 6.1000e+01],

..., 3.7000e+01, 4.9000e+01]])

For every hour, the dataset reports the following variables:

Converts date strings to

numbers corresponding to the

day of the month in column 1

• Index of record: instant

• Day of month: day

• Season: season (1: spring, 2: summer, 3: fall, 4: winter)

• Year: yr (0: 2011, 1: 2012)

• Month: mnth (1 to 12)

• Hour: hr (0 to 23)

• Holiday status: holiday

• Day of the week: weekday

• Working day status: workingday

• Weather situation: weathersit (1: clear, 2:mist, 3: light rain/snow, 4: heavy

rain/snow)

• Temperature in °C: temp

• Perceived temperature in °C: atemp

• Humidity: hum

• Wind speed: windspeed

• Number of casual users: casual

• Number of registered users: registered

• Count of rental bikes: cnt

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!