Skip to content
Snippets Groups Projects
Commit a5c9fbc8 authored by XIAOYING DENG's avatar XIAOYING DENG
Browse files

Upload New File

parent 64a5926f
No related branches found
No related tags found
No related merge requests found
test.py 0 → 100644
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment