Building off of what we just discussed in two dimensions. So we had our square and our circle, and we saw that 21% of our square was outside of the circle. We are now going to push that out into three dimensions and work with a sphere rather than a circle, and a cube rather than a square. Now, I want to remind you how this ties back to a data science problem. The idea here, thinking about the two dimensions is that we have for each dimension that is a different feature, so different covariant. So we have covariant A, covariant B, both had been normalized. And we can think that the values lie between -1 and 1 for each one of those, and they've been standardized so they have a mean of 0 and a standard deviation of 1. If we think about this value, and look at the square here, the idea is that to be a single unit away from that center value. That would indicate that you're one standard deviation away whether you're pointing horizontally, vertically, or diagonally. And we can see all the different values that lie one standard deviation from the mean. That's your unit circle. And then all values that are outside of that circle, are going to relate to those that are far away from the mean, aboveone standard deviation from the mean, but still within that -1 to 1 range. So we see given that we're working with values between -1 and 1 for our covariates, these are the values outside the circle that will be in a sense outliers. Now, in that same sense, if we were to add on a third dimension covariat C, and that's what we're planning to do here. The idea is we're still working from -1 to 1. Still our sphere now, we'll indicate one standard deviation away in any direction. Now, not just diagonally, but diagonally within space. And then anything outside that sphere, we can then again think of it in the same sense that we just did with the circle and the square. That this is more than one standard deviation away, still between -1 and 1, and see how many outliers we have. So again with the square we had 21%. Now we're moving to plotting in three dimensions. I'm going to show you step by step how you can plot some of these values in three dimensions, so that you can go home or leave this notebook, and then be able to plot in three dimensions yourself as well. So the first thing that we do, is we are going to have to import this Axes3D library. Now if we don't do this, and we try to create our figure, and then from that figure we get our current axes and make them 3D projections, we'll see that we're getting there. We will have to first import that library, the Axes3D to give us that option. So we pull this in, and I'm going to run through just as we did before, had the cell above, so we can see the step by step. But now, that I've imported Axes3D, we see that now rather than working in two dimensions, you can see how we can start to work within three dimensions. So hopefully this is exciting to see that we have values for x, y-axis, and then now a z-axis as well. We're then going to draw our cube. Now, we have here this idea of combinations and taking the products. I don't want to walk too much into it, I'll show you quickly how the product works. And I would suggest you can look at the combinations and see how it works as well, built off of this product that I'm about to create. But, right now we're taking the product of 3r's, and now r is just defined as -1 and 1. In order to make this a little clear, we're going to use three different lists of 2 rather than -1 and 1, though we're going to use (1, 2), (3, 4), and (5, 6). And when I take the product I'll take the list so that we can see this output, otherwise it's just a generator object. We also have to make sure that we import that library. You see that it comes up with every possible combination, not accounting for ordering. So 1, 3 and 5, taking the first value from each of the lists, then 1, 3 and 6, so first, first, and second, and then (1, 4, 5), (1, 4, 6) (2, 3, 5). So you can see how it's going through each one of these different values and ensuring that it covers all the different possible combinations. So it does that with -1, 1, and then the combinations of value of 2 will give you values of 2 for each one different combinations. Now I wouldn't worry too much about it. That point here is given again that we're pulling out an s and an e, it's going to output two different values when we get that combination. We're going to take the sum of s- e, and that has to be equal to, this is using our r1, [r1]- [r0] in order for it to be an edge on our cube. So that's all it's trying to do, it's trying to find where each of our edges lie. Now I'm going to pull out this portion of code just to show you how one line is drawn in three-dimensional space. Let me, Hold this. We copy this, we're going to move it above. And we're saying for s and e we don't care too much about that, but what we do care about is this zip of s and e, and then plotting that. So in order to see what that, well the star is going to ensure that it unpacks it. So rather than just creating generate object, we'll see that actual output. And I'll actually print here so we can see what this output looks like. So we're zipping s and e, and then I'm going to break. So we're just going to plot one line. So I'm going to run this, r is not defined yet. I forgot to copy that in, say r = [-1,1]. And we see that we plotted this one line. Now the zip(s, e), this is going to be our x-values of our two points, the y-values of our two points and the z-values of our two points. So we're plotting from (-1, -1, -1), up to (-1, -1, 1). So that's the idea that we're seeing here. And it's hard to see in three-dimensional space, but we are going from (-1, -1, -1), up to (1, 1, 1). Now when we run through all the different lines, all we're doing is using this plot 3d, which will work exactly the same as just plot in two-dimensional space. That is just creating those lines connecting those two dots. The same way you would do in two dimensional space, calling ax.plot. So if I don't run the break here and let the for loop run all the way through, you see here that we now have our cube connecting each one of these points that we have here. The next step that we want to do in order to draw our sphere, is we're first going to create this mesh grid. So I'm going to copy this above into a different cell. And in order to make this a little clear, this is going to be the number of points if you were to do without the j, the j just in general, so you know within Python means a complex number. We are working here with the j, not because we're working with complex numbers, but the complex numbers just let us know that rather than counting by 20, we want 20 points in between 0 and 2 times pi. That's all we're doing here by using the complex number. But we're going to reduce this just for example to 3 and 2, so we'll have 3 values and 2 values. And the idea is that one we want to plot along many different points, and we want to cover, so here's supposed to go from 0 to 2 times pi, and we want to have three different values. So it goes 0, then pi, then 2 times pi. And then we're also going from 0 to pi with just 2 values, so 0 to pi. And the idea is that we want to plot all the possible combinations of these points. In order to do that, we have to create this mesh grid so that we have 0, 0, as well as 0 and pi. And then pi coming from our count from 0 through to 2 pi. We then have pi and 0 and then pi and pi for our second axis, and so on and so forth. So that's the idea of the mesh grid to allow you to plot on each one of these multiple points. Now it has two outputs for each one the different grids, those are both equal in shape. So you have 0 and 1, that's supposed to be your x and y. Here we're plotting in three dimensions, and all we're doing is taking that two-dimensional graph. And we're expanding that to create our sphere by using each one of those different points and taking the cosine of each of these values ranging from, from u, you go from 0 to 2pi, and then from v from 0 to pi, multiplying them together and then first z, we just get cosine of v. And that will create our sphere. So we're going to have our three points, all these multiple points, and right now they're just points out in space. And in order to connect all those spaces into one final sphere, we're going to use this plot wireframe which will connect all those dots together. So we call ax.plot_wireframe on the x, y, and z, and we run this. And then we see all these different points that were created in three dimensional space, all being connected by this wireframe. And ultimately, we saw here how to plot in 3D, and maybe difficult to visualize how much extra empty space there is. But if we think about it, in terms of the equations, the volume of the sphere is given by 4 over 3 pi r cubed. And since we're working with a cube with a radius of 2r, it's going to have 2r cubed in terms of volume. And when we calculate the percent of that cube, again, thinking of this as three different covariates, we can see that the volume outside the sphere is going to be 1 minus that volume of the sphere, 4 over 3 times pi r cubed over 2r cubed. You do some cross multiplication, you end up with 1 minus pi over six, and approximately 48% of your values being outside the cube. So working with that same range of -1 to 1, and that same radius being described as your standard deviation, and being beyond that being a bit of an outlier. We see that 48% of our values are now outliers, now that we've moved up to three-dimensional space. So that closes out this video. In the next video, we will continue and show you how you can actually generalize these to even higher dimensional space, and see those percentages as we continuously increase the number of dimensions.