Our first piece of code

Let’s try to take our Excel data about house prices and get machine learning to make some predictions for us, using linear regression. Let’s get Spyder going!

Setting the environment

After you see Spyder loaded up, take your time to set up the interface as per your preference. Personally, I have the “Variable explorer” and the “IPython console” displaying all the time on the right side. Just play around with the settings in the “View” menu to find what works for you. Don’t forget that you can move around the panes as you please as well.

Once you are happy with the environment, you are now ready to run some code! Before we move forward with that, I want to point out very clearly here that I won’t be teaching you Python but I will try to make the code as easy as possible with plenty of comments.

Gimme the codes!

With that out of the way, just copy over the code below into Spyder. Remember, you can also run the code below by clicking the green play button. The chart, however, won’t be visible unless you open in repl.it.

Quick tip here, if you plan on using repl.it for the code, the line plt.show() won't work, so use something like plt.savefig('plot.png') instead.

Now run the code by hitting the play button or pressing the F5 key. After Spyder has done it’s thing in the background, it will spit out a couple of things in the console.

The first thing you will see would be a scatter chart with the original prices in blue and the new prices drawn as a line in red. This red line is basically the trendline that you saw in Excel.

After the chart, you will see the predicted prices for 475, 700 and 750 sqm houses respectively.

[[506732.12263931]
 [568229.39683295]
 [581895.45776486]]

Congratulations, you just made some predictions using machine learning!

Leave a comment