Introduction to Sckit Learn Module in Python

Introduction To Sckit Learn Module In Python

Python has many modules created by developers. One of the most popular is sckit-learn or sklearn. To install sklearn we need PIP program already installed in our system. To install PIP, refer to PIP installation document.

Now, we are going to install sklearn by the following command:

pip install scikit-learn

Wait until the process finish. Now, we can try the newly installed module. Go to Python interpreter:


Then, we will import sklearn module from the interpreter

>>> import sklearn
>>> from sklearn import linear_model
>>> reg = linear_model.LinearRegression()
>>>[[0, 0], [1, 1], [2, 2]], [0, 1, 2])
>>> reg.coef_
array([0.5, 0.5])


After importing, then, from the imported module, we import linear_model.

This code is to count, how many result between 0 to 1 and between 1 to 2.

More examples can be found here.

Common Error when using a module

When using any of programming languages, there will be error when executing a command or script. Here are the most common error:

  • Error regarding data type
  • Error regarding a limit of a function in a script
  • Error regarding mistake in writing a syntax

To overcome this, it is suggested to read documentation regarding function that we are using.

error regarding data type

To fix this, make sure that variable declaration is right whether it is for example string or integer. Often many people still confuse with this by treating phone number as integer. Integer is a type of data that is intended to be calculated by mathematical operation for example 1 + 2 for the result 3. However, phone number is not to be calculated so it needs to be defined in a variable as a string.

error regarding limit of a function

A function sometimes limited to count because the unlimited function can consume resource of a computer too much. For example, in looping operation and how many argument can be filled inside a function. It doesn’t matter when we are creating our own function. However, when using a function inside importing module, we need to follow if there is a limitation. In addition to limitation from declared function, the programming language itself contains general limitation. It can not understand if we are not declaring variable mentioned by us.

error regarding mistake in writing syntax

It is often to happen, when a we use a language, there is a syntax error. The error can be minimized by using IDE software that can notify us for example in color code, if there is any mistake in writing syntax. Check the script or function that we create or any variable we declare. Fix it and re-run the script.

I used to be a pilot, but ended up being just a mediocre writer.