So this lecture is going to answer the question, why do we care about shapes?
Well, this is an important question because all of the libraries, we will use work under the assumption
that your data has a specific shape.
If you store your data in any way you want without conforming to the API of those libraries, well then
they just won't work as expected.
So getting your shapes right is a must.
Furthermore, I find that understanding shapes helps you visualize the data.
Time series are generally very easy to visualize.
In fact, you are probably visualizing a time series right now, such as the power of words.
However, this becomes a bit more difficult when the time series is multidimensional.
So considering the shapes of things helps you think about the data in a more real and physical way.
So the Simplest Time series is a one dimensional time series, for example, the daily temperature over
time.
In this case, your data would be a one dimensional array.
So if you have a time series of length T, then you would have an array of size t.
You can think of this as an array that goes from left to right or from top to bottom.
However, this is actually an illusion because in one dimension there is no concept of left and right
or top and bottom.
This only happens because we're representing a one dimensional thing on a two dimensional screen.
In Pandas, data frames are two dimensional, while series objects are one dimensional.
In either of these can be used to store a one dimensional time series.
If you use a series, then your series would be a series of length T, but if you use the data frame,
then it would be a table with T rows and one column.
In other words, T by one.
Now, this is where things might get tricky because technically this isn't required.
You might ask why not store it as a one by T instead of a T by one?
The answer is because it's typically our convention and it works nicely with the libraries we will use.
Now, of course, the data frame is capable of holding multiple columns.
So now suppose that you have a multidimensional time series, for example, the daily temperature in
multiple cities.
And suppose that you have the temperature for cities over a period of t days.
Then your data frame would have the shape T by d.
So again, y, t by d and not d by t.
And again, the answer is because this is what works nicely with the libraries we use.
And note that this might actually go against your intuition because when we plot a time series, we
typically think of it as going from left to right.
But in this case, we store the Time series going from top to bottom.
So just remember that T by D is the convention.
Now things can become even more tricky.
Suppose that we have multiple time series, each with multiple dimensions.
For example, suppose we're reading accelerometer data from your smartphone.
You'd like to use this data to predict whether the user is walking, sitting or lying down.
In this case, you might record acceleration in the X, Y, and Z dimensions.
So you have D equals three.
And suppose that each recording you take lasts two seconds and you sample at 50Hz.
So each recording has 100 samples in total, which means T equals 100.
And of course, this is machine learning.
So you're going to have multiple training samples.
Suppose that you collect 1 million samples of users walking, sitting or lying down.
In this case, we introduce a new letter N which by convention we will use for the number of samples
in a dataset.
So n equals 1 million.
We have 1 million samples of users walking, sitting or lying down.
In this case, our convention is to organize our data in an array of size.
N by T by.
So it's a number of samples by number of time, steps by number of dimensions.
Now, again, you might be wondering why not a D, by T, by N or T, by n, by D.
And again, the answer is because this is what our libraries expect in other libraries and other languages,
things might work a different way.
So it's always good to be cognizant of what convention is being used.
And that's just part of your job as a data scientist.
So when we say n by T by D recognize that this has three dimensions.
In other words, you can think of it like a box in 3D space.
I always try to encourage students to automatically think of a box whenever they hear n by ID.
This is because just saying n by t by can be a bit abstract, but a box is clearly very physical and
easy to visualize.
So try to make this a reflex in your life will become much easier.
So another reason this is useful is because your computer screen is only two dimensional.
So suppose you had a three dimensional array in your computer and then you printed it out.
Well, what would happen?
The answer is that you would lose this 3D structure because your screen is only 2D.
So you can see here that it just looks like nonsense.
The printout doesn't give me any insight because it flattens a 3D object onto a 2D screen.
This is unlike a 1D array and a 2D array where printing things out can be very useful.
And I always have this motto that I tell students when in doubt, print it out.
This usually always helps, but when you have a 3D array, not so much.
But in any case, I hope you agree that thinking of shapes is very helpful both for intuition and also
to prevent you from making errors when writing code.