Univariate Linear Regression in Python

Univariate data is the type of data in which the result depends only on one variable. For instance, dataset of points on a line can be considered as a univariate data where abscissa can be considered as input feature and ordinate can be considered as output/result.

For example:
For line Y = 2X + 3;
Input feature will be X and Y will be the result.

X Y
1 5
2 7
3 9
4 11
5 13

Concept:
For univariate linear regression, there is only one input feature vector. The line of regression will be in the form of:

Y = b0 + b1 * X
Where,
b0 and b1 are the coefficients of regression.



Hence, it is being tried to predict regression coefficients b0 and b1 by training a model.

Utility functions

  1. Predict
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

def predict(x, b0, b1):
    """Predicts the value of prediction based on 
       current value of regression coefficients when input is x"""
    # Y = b0 + b1 * X
    return b0 + b1 * x