import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

df=pd.read_csv("incident_reports.csv")
cats=["Hardware","Software","Network"]
terms=["laptop computer keyboard monitor printer screen","application software program operating installation graphics","internet wifi network server connection vpn"]
keys=dict(zip(cats,map(lambda x:set(x.split()),terms)))
words=df["report"].str.lower().str.split().map(set)
scores=pd.DataFrame({c:words.map(lambda w:len(w&k)) for c,k in keys.items()})
actual=df["category"].str.title()
predicted=scores.idxmax(axis=1)
result=np.where(actual.eq(predicted),"Correct","Incorrect")
score=scores.apply(lambda r:f"{r.Hardware}/{r.Software}/{r.Network}",axis=1)
view=pd.DataFrame({"ID":df["id"],"Incident Report":df["report"],"Actual":actual,"H/S/N":score,"Predicted":predicted,"Result":result})
fig,ax=plt.subplots(figsize=(14,9))
ax.axis("off")
table=ax.table(cellText=view.values,colLabels=view.columns,cellLoc="left",loc="center",colWidths=[.05,.40,.11,.10,.12,.10])
table.auto_set_font_size(False)
table.set_fontsize(8)
table.scale(1,1.5)
ax.set_title("Incident Report Classification: Actual vs Predicted",fontsize=14,pad=15)
plt.tight_layout()
plt.show()