Linear Regression

 

Download Dataset from here

https://drive.google.com/file/d/1xeSIzo_6IO_yiNmekaSVN1-4XpO55c_l/view?usp=sharing

or 

https://drive.google.com/file/d/16km6djOKYuFcWYnR6Jem74ZgeP9XHQ7J/view?usp=sharing

_____________________________________________________________________________________

1.    import numpy as np

2.    data = np.loadtxt("income_data.csv", delimiter=",")

3.    data.shape

4.    x = data[: , 0].reshape(-1,1)

5.    y = data[: , 1].reshape(-1,1)

6.    from sklearn import model_selection

X_train, X_test, Y_train, Y_test = model_selection.train_test_split(x , y)

7.    from sklearn.linear_model import LinearRegression

alg1 = LinearRegression()

alg1.fit(X_train , Y_train)

8.    alg1.coef_

9.    alg1.intercept_

10.    import matplotlib.pyplot as plt

    m = alg1.coef_[0]

    c = alg1.intercept_

    x_line = np.arange(0,10,0.1)

    y_line = m * x_line + c

    plt.plot(x_line,y_line)

    plt.scatter(X_train,Y_train)

    plt.show()

11.

Comments