Hello everyone and welcome to the regression plot's lecture for seaborne Seaborn has many built in capabilities
for aggression and plots.
However we won't really discuss regression until the machine learning section of this course.
So for now will only cover the L and plot function L.M. plot allows you to display linear models with
Seaborn.
Also learn how to size and change the aspect ratio for seaborne plots.
Let's go ahead and jump to Jupiter notebook to get started.
All right here I am at the Jupiter notebook.
I want to head an imported seaborne called Matt plotless in line and I have loaded up the tips data
set that we've been working with.
Go and show you how to use L-M plot to make a very simple linear model plot you just call Esson this
L.M. plots and then what feature you want on the x axis versus the y axis going in plot total bill and
on the y axis will go ahead and call it in our datasource will be tips.
Now if you go ahead and run that we see we basically have a scatterplot with a linear fit on top of
it and you can actually specify hewe as well if you want some separation based off a categorical feature
.
For instance we can specify Huie to sex.
And now you have essentially two scatter plots and two linear fits on top of this and this basically
is far something to infer out of this plot is that male and female essentially have the same linear
fit as far as total bill vs tip.
Something to note here is they can actually begin to pass in that plot live style parameters such as
you want it to affect the markers or marker types here.
You could begin to say something like this will go in and say markers is equal to.
As we're dealing with a hue here we have two separate markers we're in need.
She can pass any list of markers type so I can go in and say little O for one marker and then lowercase
V for another and these markers these symbols come from the map plus lib marker symbols.
So go to and run that and then we see we have upside then triangles for females and circles for males
.
Now if that's actually not large enough for you to see you can go ahead and begin to add in what's known
as a scatter underscore k s parameter and basically what that means is I'm can actually passen map plot
lib parameters even more directly into the Piel t that scatter call.
So what seaborne is doing with this.
S and s l m plot is it's actually calling map plot lib very much under the hood.
And if you want to effect map plot lived directly from seaborne what you end up doing and this kind
of on a case by case basis so you have to reference the documentation as necessary.
But if you want to for this case affect the scatterplot you're going to pass any dictionary so I can
go ahead and say s dictionary and change the size to something like 100.
And this will actually affect the size of these markers.
You're going to run that show you and I have made the markers a lot bigger.
So this is actually just a call to map plot lib and what's going on underneath the hood of Seaborn.
In other words you're just passing any dictionary with base map plot lib arguments and in this case
it's.
As for size of a scatterplot in general you probably won't remember this kind of thing off the top of
your head but is that reference the documentation.
And you probably won't be customizing to this degree that often with Seaborn.
You'll go ahead and customize your data first before doing this sort of action.
Let's go ahead and show you a couple of more options here.
In case you don't want to mess around with marker sizing you can actually use a grid instead of separating
by Hugh so you can add more by saying Asinus thought Ellen plot.
Let's go ahead and copy and paste the bill tip and data and we're going to go ahead and do it.
After seeing this instead of specifying something like Heugh equals sex which changes the color hue
you can actually start calling factor or grid plot's like saying call equal sex for columns.
And now you have to separate column plots here separated by the sex category.
So male versus female.
So instead of separating it by color separated by columns and you can continue this sort of logic on
rows as well.
If you want to add in another variable to see you can say row is equal to something like the time column
and now you have rows and times and this is essentially just doing the grid calls and the Fassett group
calls that we learned about earlier in the grid lecture.
But it's a little more automatic because we're just adding call and row to the L-M plot call.
So it makes it a lot easier.
Now we don't have to deal Fassett great all the time.
Now if for some reason you still want to plot more variables you can add the hugh back end so you could
say Heugh is equal to let's say another column.
I want to go in and say column is day that we have Thursday Friday Saturday and Sunday is column.
It's going to change the hue back to sex.
So this going to give us quite informative plot but it's going to be a lot of information here so you
can see there's a lot going on here and a lot of information.
So you probably just want to go ahead and eliminate row right off the bat and only get one column back
or one Roback excuse me and then we have kind of a nice looking plot here but the problem is that the
aspect and size look wrong.
So Seaborn figures going to have their size and aspect ratio adjusted with size and aspect parameters
.
So you go into your seaborne call and then you can change the aspect ratio with aspect so it's good
and give it an aspect ratio of 0.6.
And this is the ratio between the height and the width of each of these separate grids.
And then you can specify size to change the sizes to specify size 8.
And here he began to affect the aspect and size ratio of this.
And now you're probably wondering well how do I change the font size is still too small to read or how
do I control the aesthetics even more.
Well we're going to do is lead this into our style and color lecture which is coming up next where we're
going to show you how to control these more basic features of the plot such as font size style coloring
etc..
As far as this lecture is concerned we're pretty much done.
The main thing I want you to get out of this is that in order to call a linear model plot you just call
s and s l m plot passen your x y column and set your data and then you can passen Hugh for these more
advanced features such as setting the marker size or changing the marker type.
Go ahead and reference the note book and the link to the documentation in the notebook.
All right.
If you have any questions feel free to post the Q&A forum and I'll be happy to help you out.
Thanks and I'll see you at the next lecture.