# Program to collect 40 students' names and their last five years' science marks.
# Calculate future scores based on the average of last five years and display
prediction scores through a graph.
# Also, generate a confusion matrix for the program.
import matplotlib.pyplot as plt
import random
from sklearn.metrics import confusion_matrix
import numpy as np
#Initialize data for 40 students
#Generate random marks for the last five years (out of 100)
students = []
marks=[]
for i in range(3):
name=input("Enter the name of the students: ")
mark=eval(input("Enter the marks: "))
students.append(name)
marks.append(mark)
# Calculate average marks and predicted future scores
predicted_scores = []
for student_marks in marks:
avg_marks = sum(student_marks) / 5
predicted_score = avg_marks + random.choice([-5, 5]) # Add or subtract 5
predicted_scores.append(round(predicted_score, 2))
#Calculate average marks of original scores
original_scores = []
for student_marks in marks:
avg_marks = sum(student_marks) / 5
original_scores.append(round(avg_marks, 2))
# Step 3: Display the original scores through a graph
x = np.arange(len(students)) # the label locations
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, original_scores, width, label='Original Scores')
rects2 = ax.bar(x + width/2, predicted_scores, width, label='Predicted Scores')
# Add labels, title, and legend
ax.set_xlabel('Students')
ax.set_ylabel('Scores')
ax.set_title('Original vs Predicted Science Scores')
ax.set_xticks(x)
ax.set_xticklabels(students, rotation=90)
ax.legend()
fig.tight_layout()
plt.show()
threshold = 60
original_pass_fail=[]
predicted_pass_fail=[]
for score in original_scores:
if score >= threshold:
original_pass_fail.append(1)
predicted_pass_fail.append(1)
else:
original_pass_fail.append(0)
predicted_pass_fail.append(0)
conf_matrix = confusion_matrix(original_pass_fail, predicted_pass_fail,labels=[0,
1])
# Display the confusion matrix in a 2x2 format
print("Confusion Matrix:")
print(conf_matrix)