-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentperformance.py
More file actions
60 lines (45 loc) · 1.66 KB
/
Copy pathStudentperformance.py
File metadata and controls
60 lines (45 loc) · 1.66 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
51
52
53
54
55
56
57
58
59
60
#importing necessary libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression,LogisticRegression
from sklearn.metrics import r2_score,mean_squared_error,accuracy_score,confusion_matrix
#load the dataset
df=pd.read_csv('Student.csv')
X = df[['study_hours','attendance','previous_score','sleep_hours','test_score','extracurricular']]
y=df[['final_score']]
z=df[['pass_fail']]
print(df.head())
#Split the data set
X_trainlin,X_testlin,y_trainlin,y_testlin = train_test_split(X,y,test_size=0.25)
X_trainlog,X_testlog,z_trainlog,z_testlog = train_test_split(X,z,test_size=0.25)
#Train the model Linear reg
model1 = LinearRegression()
model1.fit(X_trainlin,y_trainlin)
y_pred=model1.predict(X_testlin)
#Train the model for Logistic reg
model2=LogisticRegression()
model2.fit(X_trainlog,z_trainlog)
z_pred = model2.predict(X_testlog)
#evaluate model1
print("//// Performance of Model 1 ////")
print("R2 Score:",r2_score(y_pred,y_testlin))
print("Mean Squared Error:",np.sqrt(mean_squared_error(y_pred,y_testlin)))
#Evaluate model2
print("//// Performance of Model 2 ////")
print("Accuracy:",accuracy_score(z_testlog,z_pred))
print("Confusion Matrix",confusion_matrix(z_testlog,z_pred))
#visualize the graph
plt.scatter(y_testlin,y_pred)
plt.xlabel("Actual Score")
plt.ylabel("Predicted Score")
plt.title("Final Score")
plt.show()
#visualize the model2
plt.scatter(z_testlog,z_pred)
plt.xlabel("Actual Pass/Fail")
plt.ylabel("Predicted Pass/Fail")
plt.title("Pass/Fail")
plt.show()