Wonderful.
Where we left off is we had just created the Get Features function, which builds our features dictionary
with our four features.
Let's look at one so we can call get features for let's say our initial training point.
And what we get back is this nice little this little dictionary.
Apparently it's £2.2 in its weight.
That's its average rank.
That's the length of the text.
And it is not a top electronics brand.
So these become the rather meager features that we have engineered.
You can do better and I challenge you to do so.
All right.
Now it's time for some machine learning.
There's this little utility function that's going to take a list of items and convert it into a dataframe.
A pandas dataframe.
Not going to go through this in detail, because this is not a course about traditional machine learning.
If you know DataFrames and you'll be familiar with this, and we use this to make a training dataframe
and a test dataframe, just picking the top 250 points in our test data set.
So there we go.
We've made our conversion and now this is the business.
This is where we run traditional linear regression.
We set our features.
Um we specify the names of the columns of our features.
This is where all the action happens.
Model equals linear regression is saying we want a linear regression model.
And then we fit that model to our x values, our features and our y values is the actual prices of our
training data set.
And that this this is where the action happens and where the model is actually fit.
Then going to print the the features and their coefficients or how much weight they got.
So we can see that and get a sense of how important were each of our features.
And then we will actually run a prediction on that test set and get things like the, the MSE, the
mean squared error and the r squared for for the data scientists amongst you that want to have a look
at that.
But never fear, we're about to see it of course Using the framework that we built before.
That's going to show it on the same graph.
So make your guess where you think this is going to come out compared to the average model.
Let's quickly look back at the average model to remind ourselves what we're trying to beat.
So an average guess has an error of 145 $146.
So hopefully linear regression can do better than average.
Let's see.
Let's first run it.
It's quick.
Uh, so the different uh, um coefficients, the weights that it gave things, you can see that how
heavy something is gets a small uh, positive weight.
How it ranks gets a larger one.
The text length is very small signal very low.
Is it a top electronics brand?
Makes a big difference.
Things that are top electronics brands get a lot.
Um, okay, so now, uh, we simply wrap this in a function because this is what we're going to use
in our cool test visualizer.
We wrap it in a function called linear regression Pricer.
And we will then just use we will it passes in an item.
We will get the features for that item.
We will then convert that to a data frame.
And then we will call our linear regression model to predict where that comes.
And let's see what happens.
Tester dot test.
Linear regression Pricer.
Are you ready for this.
Remember what the average number was.
Here we go.
Oh, uh, execute the cell before.
Uh, how many times have I done that now?
Bam!
Well, we can see the colors.
We can see that it's got a lot of reds in there, but maybe some more greens than before.
Maybe it hasn't done terribly.
It's getting some things right.
Let's see.
Well, there we have it.
It's only done a little bit better than the average.
Only a little bit better.
And indeed if you look at the results you can see that basically there's a small increase here, but
it's clustered Stood around the average kind of point, with some of the points coming in about $200
more.
And guess what?
Those are going to be the ones where is electronics brand is is is true is top electronics brand.
Uh, and so they got a little uplift which did well for this one point here.
But otherwise uh, didn't particularly work out well for the model.
Uh, so it tried its best.
It got a, uh, 139, um, uh, error.
And it, it it had a hit.
It was green, uh, almost 16% of the time.
So that's our linear regression model.
You can do better.
Come on in.
Now, engineer some features.
I know it's not new.
Uh, great.
LM data science, but it's really good to build this foundational knowledge and doing some old school
feature engineering.
And besides, it's going to make it all the more satisfying when we start working with LMS and see how
they do.
So come on in there, build some features, see how you do.
But next time we're going to, uh, look at some more sophisticated baseline models.
I will see you then.