After having defined the problem and formulated our questions, 1
the second step is gathering the data that will help us find the answers. 2
Now previously I've provided data sets for you and you've imported this data from a CSV into Jupyter 3
notebook. 4
But what if you're on your own? 5
Where would you get your data from? Well, 6
typically you'd Google away and search for one of the many datasets available online. 7
After all, what if you wanted to build this valuation tool using house price data for your own city 8
rather than for Boston? 9
In that case Google is going to be your best friend in every respect. 10
But there's a third alternative for when you're just getting started and you want to practice your data 11
science and machine learning skills and that's to use some of the popular practice data sets that come 12
directly from a Python module. 13
In other words, some Python modules actually come with sample datasets that we can use. 14
One of my favorite Python modules out there is scikit learn. 15
They've got excellent practice data sets and you could see a whole list of scikit learn's toy data sets 16
right on this Web site. Scrolling down we can see that they not only provide the Boston house price data 17
set that we're gonna use in this section, but they've also got the famous iris data set which is used 18
for flowers classification, 19
they've got a dataset on diabetes, on digits, on wine and on breast cancer. 20
So this makes the search for data sets that you can use to practice machine learning and data science 21
much, much easier. 22
And that's because the really, really neat thing about using one of these data sets is that these tend 23
to be much cleaner and user friendly than some random CSV that you download from a Web site. 24
These datasets are meant for testing and for practice. 25
So you'll encounter far fewer missing values, fewer weird data formats, less non relevant information 26
and fewer other problems. 27
In other words, somebody has already done a first pass on the data set so that you can crack on with 28
a head start. 29
Now since we're gonna be examining and predicting house prices in Boston, let's pull up the official 30
documentation for this dataset and have a look at what it has to say. 31
The information provided on the website is fairly basic. 32
We can see the total number of samples - 506. 33
We can see the dimensionality which is 13. 34
You can think of this as the number of columns in the data set. And also, down here, 35
we can see some sample code for how to use this built in data set from scikit learn. 36
We're gonna be making use of all of this information 37
and all of these things in the coming lessons. So let's crack on and get started. 38
The first thing we have to do is create a new notebook. 39
It's gonna be a Python 3 notebook. 40
I'm going to click up here where it says "Untitled" and give this notebook a name, 41
I'm going to call it "04 Multivariate Regression", click "Rename" and then let's add some section headings. For the first 42
section heading, 43
I'm going to change my cell to "Markdown", put a pound symbol there and then write "Notebook Imports". Below 44
this section heading we're gonna have all our import statements. 45
So what's the first import statement that we're gonna put in? The first import statement 46
we're gonna be putting in here is going to be loading our Boston house price data set into our Jupyter 47
notebook. From the scikit learn documentation 48
we know what this import statement should look like. 49
It should read "from sklearn.datasets 50
import load_boston". 51
So let's write that in here. We're going to say "from sklearn.datasets 52
import load_boston". 53
Now I'm going to add another markdown cell to single out the section of the notebook where we're going 54
to gather our data. 55
So I'm gonna put a pound symbol here and then write "Gather Data". 56
We're gonna try out a little bit more of the code that we saw in the documentation to get our data set 57
into our notebook. 58
I'm going to insert some cells as well, so that I'm going to be working more in the middle of the screen. And 59
here we can call the "load_boston" function because this is the function that will actually 60
return our data set. 61
So I'm going to create a variable, call it "boston_dataset" and set the value of this variable 62
equal to the return value from load_boston 63
and then two parentheses at the end. 64
So this function here will return to us our data set and we'll store it in a variable called 65
boston_dataset. 66
Let me hit Shift+Enter and let's check out the type of this variable. So I'm going to write "type( 67
boston_ 68
dataset" and hit Shift+Enter 69
and then we can see what kind of object we're actually dealing with. 70
And as per the documentation we can see that we're working with an object of type "Bunch". 71
Now usually we typically want to work with a data frame so let's make a mental note right now to convert 72
our data to a data frame for later. 73
But now let's take a look at what our data actually looks like in its raw state. 74
And to do that all we have to do is write "boston_dataset" into an empty cell and hit Shift+ 75
Enter. And what we get to see now is a whole bunch of output. 76
Now, 77
this is really, really difficult to read and it's not formatted in a way that we want to sift through 78
it. But the good news is that our data is there. 79
We've successfully imported our data set and we've got it in our Jupyter notebook and this will bring 80
us to our next step - exploring our data set, cleaning our data set and visualizing it. 81
I'll see you in the next lesson.