# importing the libraries
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import pandas as pd
from sklearn import preprocessing
# Importing the data set and extracting the dependent and Independent variables
data=pd.read_excel("Amina.xls")
print(data)
x=data.drop(columns=['GWDepth'])
y=data['GWDepth']
#Standardisation
X=preprocessing.scale(x)
Y=preprocessing.scale(y)
# Data Visualisation
# Building the Correlation Matrix
print(sns.heatmap(data.corr()))
#plt.show()
# Splitting the dataset into training set 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=0.2, random_state=0)
# Fitting Multiple Linear Regression to the Training set
from sklearn.linear_model import LinearRegression
regressor=LinearRegression()
regressor.fit(X_train,Y_train)
# Predicting the Test set results
Y_pred=regressor.predict(X_test)
#print(Y_pred)
#Calculating the Coefficients
print(regressor.coef_)
#Calculating the Intercept
print(regressor.intercept_)
# Calculating R-squared value
from sklearn.metrics import r2_score
print(r2_score(Y_test, Y_pred))
regressor.fit(data[['Rainfall','Temp.','PET']],data['GWDepth'])
print(regressor.predict([[564.071642, 27 , 1640.5535560 ]]))
Comments
Post a Comment