Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for the classifier to be roughly the same as sklearn #118

Merged
merged 7 commits into from
Mar 9, 2023

Conversation

thejaminator
Copy link
Collaborator

No description provided.

@thejaminator thejaminator changed the title Add test for the classifier to be roughly the same as skleaer Add test for the classifier to be roughly the same as sklearn Mar 9, 2023
model = LogisticRegression(penalty="none", solver="lbfgs")
model.fit(features, truths)
# train a classifier on the data
classifier = Classifier(input_dim=input_dims, device="cpu")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

classifier doesn't expose the dtype used. by default the torch linear layer is float32.
so we'll turn the sklearn features from float64 to float32

# check that the weights are roughly the same
sklearn_coef = model.coef_
torch_coef = classifier.linear.weight.detach().numpy()
assert np.allclose(sklearn_coef, torch_coef, atol=1e-2)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as a sanity check i also passed random features to torch to make the test fails. it works.

@norabelrose norabelrose self-requested a review March 9, 2023 18:10
Copy link
Member

@norabelrose norabelrose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

@norabelrose norabelrose merged commit 5070afb into main Mar 9, 2023
@norabelrose norabelrose deleted the add-classifier-tests branch March 9, 2023 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants