SHD-WebsiteFingerprintingLab/part3/eval.py

28 lines
915 B
Python
Raw Permalink Normal View History

2023-01-31 20:06:27 +00:00
import json
import numpy as np
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report
from sklearn.model_selection import train_test_split
def eval():
2024-02-01 21:12:05 +00:00
y_pred_full, y_test_full = [], []
2023-01-31 20:06:27 +00:00
2024-02-01 21:12:05 +00:00
# Re-train 10 times in order to reduce effects of randomness
for i in range(10):
### TODO: Exercise 2-5
### 1. Load data from traces file
### 2. Split data into X_train, X_test, y_train, y_test with train_test_split
### 3. Train classifier with X_train and y_train
### 4. Use classifier to make predictions on X_test. Save the result to a variable called y_pred
2023-01-31 20:06:27 +00:00
2024-02-01 21:12:05 +00:00
# Do not modify the next two lines
y_test_full.extend(y_test)
y_pred_full.extend(y_pred)
2023-01-31 20:06:27 +00:00
2024-02-01 21:12:05 +00:00
### TODO: Exercise 2-5 (continued)
### 5. Print classification report using y_test_full and y_pred_full
2023-01-31 20:06:27 +00:00
if __name__ == "__main__":
2024-02-01 21:12:05 +00:00
eval()