python implementation in this examplewe will be using boston housing dataset from scikit learnfirstwe will start with importing necessary packages as follows%matplotlib inline import matplotlib pyplot as plt import numpy as np from sklearn import datasetslinear_modelmetrics nextload the dataset as followsboston datasets load_boston(return_x_y=falsethe following script lines will define feature matrixx and response vectoryx boston data boston target nextsplit the dataset into training and testing sets as followsfrom sklearn model_selection import train_test_split x_trainx_testy_trainy_test train_test_split(xytest_size= random_state= nowcreate linear regression object and train the model as followsreg linear_model linearregression(reg fit(x_trainy_trainprint('coefficients\ 'reg coef_print('variance score{}format(reg score(x_testy_test))plt style use('fivethirtyeight'plt scatter(reg predict(x_train)reg predict(x_trainy_traincolor "green" label 'train data'plt scatter(reg predict(x_test)reg predict(x_testy_test