This repository was archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Enable scoring of ML.NET models saved with new TransformerChain format #230
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| from scipy.sparse import csr_matrix | ||
| from sklearn.utils.validation import check_X_y, check_array | ||
| from sklearn.utils.multiclass import unique_labels | ||
| from zipfile import ZipFile | ||
|
|
||
| from .internal.core.base_pipeline_item import BasePipelineItem | ||
| from .internal.entrypoints.data_customtextloader import \ | ||
|
|
@@ -40,6 +41,8 @@ | |
| from .internal.entrypoints.models_summarizer import models_summarizer | ||
| from .internal.entrypoints.transforms_datasetscorer import \ | ||
| transforms_datasetscorer | ||
| from .internal.entrypoints.transforms_datasettransformscorer import \ | ||
| transforms_datasettransformscorer | ||
| from .internal.entrypoints.transforms_featurecombiner import \ | ||
| transforms_featurecombiner | ||
| from .internal.entrypoints.transforms_featurecontributioncalculationtransformer import \ | ||
|
|
@@ -1816,22 +1819,43 @@ def _predict(self, X, y=None, | |
| isinstance(X, DataFrame) and isinstance(y, (str, tuple))): | ||
| y = y_temp | ||
|
|
||
| model_zip = ZipFile(self.model) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| is_transformer_chain = any('TransformerChain' in item | ||
| for item in model_zip.namelist()) | ||
|
|
||
| all_nodes = [] | ||
| inputs = dict([('data', ''), ('predictor_model', self.model)]) | ||
| if isinstance(X, FileDataStream): | ||
| importtext_node = data_customtextloader( | ||
| input_file="$file", | ||
| if is_transformer_chain: | ||
| inputs = dict([('data', ''), ('transform_model', self.model)]) | ||
| if isinstance(X, FileDataStream): | ||
| importtext_node = data_customtextloader( | ||
| input_file="$file", | ||
| data="$data", | ||
| custom_schema=schema.to_string( | ||
| add_sep=True)) | ||
| all_nodes = [importtext_node] | ||
| inputs = dict([('file', ''), ('transform_model', self.model)]) | ||
|
|
||
| score_node = transforms_datasettransformscorer( | ||
| data="$data", | ||
| custom_schema=schema.to_string( | ||
| add_sep=True)) | ||
| all_nodes = [importtext_node] | ||
| inputs = dict([('file', ''), ('predictor_model', self.model)]) | ||
|
|
||
| score_node = transforms_datasetscorer( | ||
| data="$data", | ||
| predictor_model="$predictor_model", | ||
| scored_data="$scoredVectorData") | ||
| all_nodes.extend([score_node]) | ||
| transform_model="$transform_model", | ||
| scored_data="$scoredVectorData") | ||
| all_nodes.extend([score_node]) | ||
| else: | ||
| inputs = dict([('data', ''), ('predictor_model', self.model)]) | ||
| if isinstance(X, FileDataStream): | ||
| importtext_node = data_customtextloader( | ||
| input_file="$file", | ||
| data="$data", | ||
| custom_schema=schema.to_string( | ||
| add_sep=True)) | ||
| all_nodes = [importtext_node] | ||
| inputs = dict([('file', ''), ('predictor_model', self.model)]) | ||
|
|
||
| score_node = transforms_datasetscorer( | ||
| data="$data", | ||
| predictor_model="$predictor_model", | ||
| scored_data="$scoredVectorData") | ||
| all_nodes.extend([score_node]) | ||
|
|
||
| if (evaltype in ['binary', 'multiclass']) or \ | ||
| (hasattr(self, 'steps') | ||
|
|
@@ -1889,6 +1913,10 @@ def _predict(self, X, y=None, | |
| self._run_time = time.time() - start_time | ||
| raise e | ||
|
|
||
| if is_transformer_chain: | ||
| out_data['PredictedLabel'] = out_data['PredictedLabel']*1 | ||
|
|
||
|
|
||
| if y is not None: | ||
| # We need to fix the schema for ranking metrics | ||
| if evaltype == 'ranking': | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
are you unpacking zip file? #ByDesign
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.
its actually doesnt unpack the content, just reads the list of directories/entries,so it should not be intensive operation
In reply to: 314144315 [](ancestors = 314144315)