def KMeansAccuracy():
clusterer = KMeans(n_clusters=2, n_init=30)
tdm = pickle.load(open(DATASET_PATH + "BOW.p", "rb"))
predictions = clusterer.fit_predict(tdm)
true_labels = pickle.load(open(OUTFILE_STANCE, "rb"))[0]
numerical_mapped_1 = [0 if i == "Israeli" else 1 for i in true_labels]
numerical_mapped_2 = [1 if i == "Israeli" else 0 for i in true_labels]
one = f1_score(numerical_mapped_1, predictions)
two = f1_score(numerical_mapped_2, predictions)
print("The F1 score of KMeans on BOW is: " + str(max(one, two)))
clusterer = KMeans(n_clusters=2, n_init=30)
predictions = clusterer.fit_predict(tdm)
true_labels = pickle.load(open(OUTFILE_STANCE, "rb"))[0]
accuracy = predict_accuracy(true_labels, predictions)
print("The F1 score of KMeans on BOW (w/Tdidf) is: " + accuracy)
评论列表
文章目录