Radoslaw Smigielski

29 December 2018

Simple example of linear regression with Scikit-learn

by Radosław Śmigielski

Why?

  1. Most of existing examples, tutorials use some pre-existing datasets which are not very clear for begginers.
  2. Linear regression is the most basic model and it’s the easiest to understand.
  3. This example shows how to implement simple LinearRegression mode and manipulate the data sets needed for the regression model.

  4. This article is going to help you to understand how to do simple machine learning and understand what you doing, not just blindly copy/paste staff from some randomly found tutorial.
  5. Next to Google Tensorflow, the most popular machine learning library.
  6. Easiest to start with than Tensorflow. The problem I can see with latest Tensorflow versions is that it assumes you, everybody are going to process Google scale amount of data which makes things more complicated than it needs to be.

Scikit-learn basics

Things you should know before you start.

Naming conventions

  1. X features
  2. y labels

Scikit-learn LinearRegression model

This is working example of linear regressions for two functions

  1. y = a*x + b
  2. y = a * log(b * x)

linear regression visualizations

And the code is here: https://gist.github.com/radeksm/7a3c352049f3faabdcb48d921d2d602d

tags: linear regression - LinearRegression - sklearn