cleanlab--cleanlab
a6d1319327
Preleminary work to ensure that default task (classification) will work smoothly. Minimal implementation of label issue manager for regression - issue_finder.py list_possible_issue_types, list_default_issue_types no longer a static methods as they depend on task and modification of get_available_issue_types for regression * DataIssues with strategy pattern - moving list_possible_issue_types and list_default_issue_types from the IssueFinder class to cleanlab/datalab/internal/issue_manager_factory.py * make different strategies for getting available issue types add test class for the IssueFinder when the task is regression * apply black formatter * avoid mapping labels column for regression in Datalab * Pass in features to LabelIssueManager for regression --------- Co-authored-by: Elías Snorrason <eliassno@gmail.com>
94 行
3.0 KiB
Python
94 行
3.0 KiB
Python
# Copyright (C) 2017-2023 Cleanlab Inc.
|
|
# This file is part of cleanlab.
|
|
#
|
|
# cleanlab is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as published
|
|
# by the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# cleanlab is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with cleanlab. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
from typing import Optional, Type
|
|
|
|
from cleanlab.datalab.internal.adapter.imagelab import (
|
|
ImagelabDataIssuesAdapter,
|
|
ImagelabIssueFinderAdapter,
|
|
ImagelabReporterAdapter,
|
|
)
|
|
from cleanlab.datalab.internal.data import Data
|
|
from cleanlab.datalab.internal.data_issues import (
|
|
DataIssues,
|
|
_ClassificationInfoStrategy,
|
|
_RegressionInfoStrategy,
|
|
)
|
|
from cleanlab.datalab.internal.issue_finder import IssueFinder
|
|
from cleanlab.datalab.internal.report import Reporter
|
|
|
|
|
|
def issue_finder_factory(imagelab):
|
|
if imagelab:
|
|
return ImagelabIssueFinderAdapter
|
|
else:
|
|
return IssueFinder
|
|
|
|
|
|
def report_factory(imagelab):
|
|
if imagelab:
|
|
return ImagelabReporterAdapter
|
|
else:
|
|
return Reporter
|
|
|
|
|
|
class _DataIssuesBuilder:
|
|
"""A helper class for constructing DataIssues instances.
|
|
It uses the builder pattern to allow users to specify the desired
|
|
configuration of the DataIssues instance.
|
|
It uses the `set_X` naming convention for methods that set the
|
|
desired configuration, before calling the `build` method to
|
|
construct the DataIssues instance.
|
|
"""
|
|
|
|
def __init__(self, data: Data):
|
|
self.data = data
|
|
self.imagelab = None
|
|
self.task: Optional[str] = None
|
|
|
|
def set_imagelab(self, imagelab):
|
|
self.imagelab = imagelab
|
|
return self
|
|
|
|
def set_task(self, task):
|
|
self.task = task
|
|
return self
|
|
|
|
def build(self) -> DataIssues:
|
|
data_issues_class = self._data_issues_factory()
|
|
strategy = self._select_info_strategy()
|
|
return data_issues_class(self.data, strategy)
|
|
|
|
def _data_issues_factory(self) -> Type[DataIssues]:
|
|
"""Factory method that selects the appropriate class for
|
|
constructing the DataIssues instance.
|
|
"""
|
|
if self.imagelab:
|
|
return ImagelabDataIssuesAdapter
|
|
else:
|
|
return DataIssues
|
|
|
|
def _select_info_strategy(self):
|
|
"""The DataIssues class takes in a strategy class
|
|
for processing info dictionaries. This method selects
|
|
the appropriate strategy class based on the task during
|
|
the `build` method-call.
|
|
"""
|
|
if self.task == "regression":
|
|
return _RegressionInfoStrategy
|
|
else:
|
|
return _ClassificationInfoStrategy
|