-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiple_regression.py
More file actions
50 lines (37 loc) · 1.35 KB
/
multiple_regression.py
File metadata and controls
50 lines (37 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#Multiple Regression
# Importing the libraries
import pandas as pd
import seaborn as sns
# Importing the dataset
dataset = pd.read_csv('/home/deepak/analytics/wine.csv') #you may need to change the data set
print(type(dataset))
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:,2].values
# Splitting the dataset into the 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 = 1/3, random_state = 0)
#Data Visualization:
sns.heatmap(dataset)
# Fitting Linear Regression to the Training set
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train, y_train)
#Calculating the coefficients:
print(regressor.coef_)
#Calculating the intercept:
print(regressor.intercept_)
# Predicting the Test set results
y_pred = regressor.predict(X_test)
# Accuracy of the model
#Calculating the r squared value:
from sklearn.metrics import r2_score
r2_score(y_test,y_pred)
#Score for training dataset and test dataset.
print('Train Score:', regressor.score(X_train, y_train))
print('Test Score:', regressor.score(X_test, y_test))
#Create a DataFrame
df1 = {'Actual Applicants':y_test,
'Predicted Applicants':y_pred}
df1 = pd.DataFrame(df1,columns=['Actual Applicants','Predicted Applicants'])
print(df1)
#------------------------------