Skip to content

Commit

Permalink
Update ML_main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
YitongXia authored Mar 25, 2022
1 parent f692586 commit 9d41976
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/ML_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def ml_RF(dataset, label):

# overall accuracy and mean accuracy
oa=e.OA(Confusion_matrix_rf)
print({}{}.format("overall accuracy of rf: ",oa))
print("{}{}".format("overall accuracy of rf: ",oa))
ma=e.mA(Confusion_matrix_rf)
print({}{}.format("mean accuracy of rf: ",ma))
print("{}{}".format("mean accuracy of rf: ",ma))

print("feature importances: ")
print(clf_rf.feature_importances_) # maybe helpful to select features
Expand Down Expand Up @@ -166,6 +166,12 @@ def plot_t_sne(dataset):
label_file = path + r"\label.txt"
dataset = np.loadtxt(dataset_file)
label = np.loadtxt(label_file)

selected_dataset_file = path + r"\dataset.txt"
selected_label_file = path + r"\label.txt"
we_selected_dataset = np.loadtxt(selected_dataset_file)
we_selected_label = np.loadtxt(selected_label_file)


# load dataset with labels
both_file = path + r"\both.txt"
Expand All @@ -183,7 +189,7 @@ def plot_t_sne(dataset):
# PCA analysis
selected_dataset = pca_analysis(dataset)

print("SVM and Random Forest for dataset with 3 selected attributes: ")
print("SVM and Random Forest for dataset with PCA selected attributes: ")
print()

# SVM
Expand All @@ -192,6 +198,14 @@ def plot_t_sne(dataset):
# RF
ml_RF(selected_dataset, label)

print("SVM and Random Forest for dataset with 3 selected attributes: ")
print()

# SVM
ml_svm(we_selected_dataset, we_selected_label)

# RF
ml_RF(we_selected_dataset, we_selected_label)
# plot dataset with 3 selected attributes
# plot_dataset(selected_dataset) # uncomment this to plot the dataset with 3 attributes in 3D space

Expand Down

0 comments on commit 9d41976

Please sign in to comment.