Linear Regression - crkant/Machine_Learning_024 GitHub Wiki
import numpy as nm
import matplotlib.pyplot as mtp
import pandas as pd
data_set=pd.read_csv('/kaggle/input/random-linear-regression/test.csv')
x=data_set.iloc[:,:-1].values
y=data_set.iloc[:,1].values
"# splitting the dataset into training and test set."
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=1/3,random_state=0)
"#fitting the simple lineat regression model to the "
"#training dataset"
from sklearn.linear_model import LinearRegression
regressor=LinearRegression()
regressor.fit(x_train,y_train)
#Prediction of test and training set result
y_pred=regressor.predict(x_test)
x_pred=regressor.predict(x_train)
slope = regressor.coef_
intercept = regressor.intercept_
print("Slope (Coefficient):", slope[0])
print("Intercept:", intercept)
mtp.scatter(x_train,y_train,color="green")
mtp.plot(x_train,x_pred,color="red")
mtp.title("LINEAR REGRESSION")
mtp.show()