Last active
November 2, 2021 19:41
-
-
Save cj2001/db4a100d5960a215575f2ee1ea3d87b6 to your computer and use it in GitHub Desktop.
CORA basic word embedding SVC model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def modeler(k_folds=5, model='linear', show_matrix=True): | |
acc_scores = [] | |
df = create_df() | |
X, y = create_X_y(df) | |
for i in range(0, k_folds): | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25) | |
clf = svm.SVC(kernel='linear', class_weight='balanced') | |
clf.fit(X_train, y_train) | |
pred = clf.predict(X_test) | |
acc = accuracy_score(pred, y_test) | |
acc_scores.append(acc) | |
print('Accuracy scores: ', acc_scores) | |
print('Mean accuracy: ', np.mean(acc_scores)) | |
if show_matrix: | |
matrix = plot_confusion_matrix(clf, X_test, y_test, cmap=plt.cm.Blues, normalize='true') | |
plt.show(matrix) | |
plt.show() | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment