>> Okay. So let's pop into our code,
and see what we've already got done.
We have imported our Pandas library
and the model we want to use to train our data.
We have gone through read our data.
We have gone through split it into training and test data.
We have trained our model,
and we've even tested our model by passing in a set of test data.
Now, when we're done this,
you might have actually noticed when we were
comparing the results for predicted and actual values,
that when you actually display
the values that were predicted by the model and
compare that to the values that
were in the actual values for the test data,
but they displayed differently.
I'm guessing some of you out there were like,
"I wonder why those are showing up differently."
There is a reason for it.
Because these two objects are not actually the same type.
If you take a closer look,
and we can use the type method
to ask for the data type of an object,
very useful anytime you're not sure what you're working with.
If you look at the type of y predict,
it says it's a Numpy array,
whereas y_test is a Pandas DataFrame.
Now, up until now,
we've been very focused on working with Pandas DataFrames,
so what is this Numpy array thing?
It's very similar to a DataFrame,
and it's got a lot of similarities,
but its functionality is not the same,
they are actually different classes.
So what does this mean in terms of our code?
Well, it means if we try and do
something like call the head function
to display the first few rows of the array,
well, that's actually going to fail.
Because Numpy arrays do not support that method.
That's a DataFrame method,
so it's not available on the Numpy array class.
So let's just take a little closer look at these.
So the Numpy library in general, just so you know,
it's basically a library that's designed for
mathematical calculations and matrix calculations.
So since it does matrix calculations,
it has to support arrays.
A one-dimensional Numpy array
is very similar to creating a series in Panda.
So if you look at the code,
it's very similar to create an array verse series.
But really only the big difference
is I'm using a different constructor,
the array constructor versus the Pandas series constructor.
But aside from that, all the syntax is the same,
except that they do have slightly different functionality.
If you want a two-dimensional array,
which we do with the DataFrame in Pandas,
you can create a two-dimensional array using a Numpy array,
and you'll see it come back.
Again, very similar to what we have with the Pandas DataFrame.
The biggest difference between the two really is,
when you're working with Pandas,
the index is explicit,
you see the index numbers displayed.
Each row does have
an implicit index when you're working with Numpy arrays,
but it's not displayed when you're printing out the values,
but you can still use it to reference a particular row.
For example, up here when I was querying my series,
I said give me the value
that's with row index number two, which is Narita.
Well, you can see in
the Pandas series that row index number two goes with Narita.
That same index value is implicitly there for the array,
it's just not displayed.
So one of the biggest differences is that
implicit versus explicit index,
that does allow some extra functionality with
Pandas DataFrames when you get further into them.
When you have an array again, two dimensional,
you can still specify by index position the row,
column position of a particular value you want to return,
just like you can using Iloc on a dataframe.
The difference, again, here being these
are explicit index positions.
With a dataframe, they're implicit on a Numpy array.
There might be times where you
want that functionality of a dataframe.
Maybe you want to call the head function,
or you want to call the tail function,
or maybe you have data in a Numpy array,
in a dataframe, and you want to
take a column from one and move it to the other.
You're going to get errors if you try to
merge together a Pandas DataFrame and a Numpy array,
a column from one and the other.
You're going to get errors if you try to call
head or tail on an Numpy array.
So there might be times when you
need to move it from one to the other.
So there's lots of different methods you can use to
switch something from being a Numpy array
to becoming a Pandas DataFrame,
or to change a Pandas DataFrame into a Numpy array and so on.
I won't go through all of them, but I'll just
give you one nice little example.
If you want to convert our predicted values into a dataframe,
you just pass that Numpy array into
the Pandas DataFrame constructor
and it will create a DataFrame for you.
So now, I can actually have that same wonderful functionality,
the Pandas DataFrame on my predicted values.
So you're going to end up going back and forth a lot
between Numpy objects and Pandas objects.
So just be prepared.
When that happens, you can use type to figure out what they are.
There's lots of great methods out there,
but I'll let you switch back and forth between Numpy and Pandas.