Skip to content

Instantly share code, notes, and snippets.

@jgoodie
Created June 1, 2024 05:39
Show Gist options
  • Save jgoodie/46bd67a29fe85101a0a91bd1ca2c4419 to your computer and use it in GitHub Desktop.
Save jgoodie/46bd67a29fe85101a0a91bd1ca2c4419 to your computer and use it in GitHub Desktop.
# recombine training and validation data
X_tv = torch.cat((X_train.cpu(), X_val.cpu()))
y_tv = torch.cat((y_train.cpu(), y_val.cpu()))
np.random.seed(101)
sample_weights = compute_sample_weight(class_weight='balanced',y=y_tv)
model = XGBClassifier()
model.fit(X_tv, y_tv, sample_weight=sample_weights)
# make predictions for test data
y_pred = model.predict(X_test.cpu())
# evaluate predictions
accuracy = accuracy_score(y_test.cpu(), y_pred)
print("Accuracy: %.2f%%" % (accuracy * 100.0))
print(confusion_matrix(y_test.cpu(), y_pred))
print(classification_report(y_test.cpu(), y_pred, digits=4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment