Hello, and welcome to a video on scatterplots and Python. This will be similar to how we've done histograms, line
graphs, and other types of visualization. First, let's load in our packages and data. As per usual,
we've got all of our libraries that we're importing here, pandas as PD,
drive from google.co lab. Of course, we're importing matplotlib.pyplot because that's what we used to actually create
our scatterplot and numpy as np. So first,
we'll mount our drive, set our file path, read in our data, and actually create our variables
here. There we go, we've got some variables created to use now.
So a scatterplot is a useful tool for visualizing the relationship between two continuous variables.
It displays individual data points on a graph, where each point represents one observation with one variable
plotted on the x-axis, and the other on the y-axis. In psychology, scatterplots are commonly
used to identify relationships, check for trends, detect outliers, and visualize data distributions.
Let's produce a scatterplot for R_IV2, and R_DV. We'll put R_IV_2 on the x-axis,
and R_DV on the y-axis.
So we'll call PLT.scatter. Our x-axis is first, our y-axis is
second, and we're going to set our color to blue, and our label to data points.
Next, we'll set x and y-axis labels in a title for our scatterplot.
Don't forget to use PLT.show or else you won't see anything at all.
Okay, that's a pretty nice looking scatterplot. What if we wanted to add a regression line, or line of best
fit to our scatterplot? First, we'll need to define a slope and
intercept. By calling np.polyfit and setting our two variables
as the variables for the linear model. You'll notice it's in the same order
as what we did above here. IV2 and then dv. Next,
we'll create a line using the poli.fit variables that we've just
created, slope and intercept. And call them here.
Finally, we'll create our scatterplot again. Except this time,
we'll plot the line dfriv2 and color it red.
Okay, so now we have our line of best fit through our scatterplot.
Feel free to play with this code and see if you can make it different colors. Come up with different variables
to use, make different lines. And see how, see how you get on.
What does our line of best fit tell us? So we can tell us trend our relationships. We can have a positive, negative or no correlation
present in our data. What kind of relationship do RDB and RIV2 have? It looks like a slightly
positive relationship here, right? We can use it to predict values for a value of
why given a value of X or vice versa. We can visually identify outliers, points that are
far from the line in our data. We can also give an idea of variability from the amount of spread across the line.
Does our data have any outliers that you've noticed? Maybe these two, we might
say these are outliers. And then we also have a strength of our relationship. The
steepness of the line tells us the strength of the relationship. A steep line is a strong relationship where
a more flat line suggests one or no relationship at all.
Okay. That's all for scatterplots. Have fun coding!