From a5c9fbc83e20c6094e689d2de991d4dfbacfa052 Mon Sep 17 00:00:00 2001
From: XIAOYING DENG <xd2u22@soton.ac.uk>
Date: Thu, 8 Jun 2023 02:06:23 +0000
Subject: [PATCH] Upload New File

---
 test.py | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 test.py

diff --git a/test.py b/test.py
new file mode 100644
index 0000000..5fc69a9
--- /dev/null
+++ b/test.py
@@ -0,0 +1,42 @@
+import pandas as pd
+from sklearn.ensemble import RandomForestClassifier
+
+# Step 1: Load the training data
+train_data = pd.read_csv('/Users/rebecca_dxy/Downloads/Machine/TrainingDataBinary.csv')
+
+# Step 2: Prepare the data
+train_features = train_data.iloc[:, 0:128]
+train_labels = train_data.iloc[:, 128]
+
+# Step 3: Train the Random Forest model
+model = RandomForestClassifier(n_estimators=100, random_state=42)
+model.fit(train_features, train_labels)
+
+# Step 4: Load and preprocess the testing data
+test_data = pd.read_csv('/Users/rebecca_dxy/Downloads/Machine/TestingDataBinary.csv')
+
+# Step 5: Match column names with training data
+test_data.columns = train_features.columns
+
+# Step 6: Make predictions on the testing data
+test_predictions = model.predict(test_data)
+train_error = 1 - model.score(train_features, train_labels)
+train_accuracy = model.score(train_features, train_labels)
+
+print("Training Error: {:.2f}%".format(train_error * 100))
+print("Training Accuracy: {:.2f}%".format(train_accuracy * 100))
+
+# Step 7: Create a DataFrame with computed labels for each trace
+results_df = pd.DataFrame(test_predictions, columns=['129'])
+
+# Step 8: Save the results to a file
+results_df.to_csv('TestingResultsBinary.csv', index=False)
+
+
+# Step 9: Display the contents of the TestingResultsBinary.csv file
+for i, label in enumerate(test_predictions):
+    print("Trace {}: Computed Label: {}".format(i+1, label))
+    
+results_data = pd.read_csv('TestingResultsBinary.csv')
+print("Results of TestingResultsBinary.csv:")
+print(results_data)
-- 
GitLab