Skip to content

Instantly share code, notes, and snippets.

@cj2001
Last active November 2, 2021 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cj2001/db4a100d5960a215575f2ee1ea3d87b6 to your computer and use it in GitHub Desktop.
Save cj2001/db4a100d5960a215575f2ee1ea3d87b6 to your computer and use it in GitHub Desktop.
CORA basic word embedding SVC model
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