diff --git a/test.py b/test.py new file mode 100644 index 0000000000000000000000000000000000000000..5fc69a94e2425fbe05adc695f94a2a8c97a99b7d --- /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)