-
Notifications
You must be signed in to change notification settings - Fork 2
Fixes sklearn pickling issues #103
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
Draft
merschformann
wants to merge
8
commits into
develop
Choose a base branch
from
merschformann/fixing-pickling-issue
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+67
−3
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
90c6a8f
Define defaults, bumping nextmv dependency
merschformann b9f31f4
Bump nextmv-scikit-learn version to v0.3.1-dev.0
nextmv-bot ccf539c
Changing default to 1
merschformann df15949
Merge remote-tracking branch 'origin/merschformann/fixing-pickling-is…
merschformann 3124162
Bump nextmv-scikit-learn version to v0.3.1-dev.1
nextmv-bot 7acee93
Merge branch 'develop' into merschformann/fixing-pickling-issue
merschformann 5ac5f2e
Merge remote-tracking branch 'origin/develop' into merschformann/fixi…
merschformann 5ab6e58
Adding test that pickles a model
merschformann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "v0.3.0" | ||
__version__ = "v0.3.1.dev1" |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import os | ||
import unittest | ||
|
||
from nextmv_sklearn.linear_model import LinearRegression, LinearRegressionOptions | ||
|
||
import nextmv | ||
|
||
|
||
class MLRegressorModel(nextmv.Model): | ||
def solve(self, input: nextmv.Input) -> nextmv.Output: | ||
if input.options.mode == "linear": | ||
model = LinearRegression(input.options) | ||
_ = model | ||
return nextmv.Output(solution={}, options=input.options) | ||
else: | ||
raise ValueError(f"Unsupported mode: {input.options.mode}") | ||
|
||
|
||
class TestPickle(unittest.TestCase): | ||
def tearDown(self): | ||
"""Removes the mlflow elements created during the test.""" | ||
model_configuration = nextmv.ModelConfiguration( | ||
name="reg", | ||
) | ||
nextmv.model._cleanup_python_model(model_dir="export", model_configuration=model_configuration) | ||
|
||
def test_options(self): | ||
model = MLRegressorModel() | ||
# Define options (custom and sklearn). | ||
sklearn_opts = LinearRegressionOptions().to_nextmv() | ||
custom_options = nextmv.Options( | ||
nextmv.Option( | ||
name="mode", | ||
option_type=str, | ||
default="linear", | ||
description="ML mode (linear or xgboost).", | ||
required=False, | ||
) | ||
) | ||
options = custom_options.merge(sklearn_opts) | ||
# Create a model configuration so that we can pickle the model. | ||
model_configuration = nextmv.ModelConfiguration( | ||
name="reg", | ||
requirements=[ | ||
"nextmv", | ||
"nextmv-scikit-learn", | ||
], | ||
options=options, | ||
) | ||
|
||
# Run the model with some input data. | ||
input = nextmv.Input(data={}, options=options) | ||
output = model.solve(input) | ||
self.assertIsInstance(output, nextmv.Output) | ||
|
||
# Save (pickle) the model to a directory. | ||
os.makedirs("export", exist_ok=True) | ||
model.save("export", model_configuration) | ||
# Assert that the "export" directory is not empty | ||
self.assertTrue(len(os.listdir("export")) > 0) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable assignment
_ = model
serves no purpose and should be removed. If the intent is to instantiate the model for testing, use the model directly in the return statement or assign it to a meaningful variable name.Copilot uses AI. Check for mistakes.