forked from automl/Auto-PyTorch
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtabular_validator.py
More file actions
55 lines (49 loc) · 2.2 KB
/
Copy pathtabular_validator.py
File metadata and controls
55 lines (49 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- encoding: utf-8 -*-
import logging
from typing import Any, Mapping, Optional, Union
from autoPyTorch.data.base_validator import BaseInputValidator
from autoPyTorch.data.tabular_feature_validator import TabularFeatureValidator
from autoPyTorch.data.tabular_target_validator import TabularTargetValidator
from autoPyTorch.utils.logging_ import PicklableClientLogger, get_named_client_logger
class TabularInputValidator(BaseInputValidator):
"""
Makes sure the input data complies with Auto-PyTorch requirements.
Categorical inputs are encoded via an Encoder, if the input
is a dataframe. This allow us to nicely predict string targets
This class also perform checks for data integrity and flags the user
via informative errors.
Attributes:
is_classification (bool):
For classification task, this flag indicates that the target data
should be encoded
feature_validator (FeatureValidator):
A FeatureValidator instance used to validate and encode feature columns to match
sklearn expectations on the data
target_validator (TargetValidator):
A TargetValidator instance used to validate and encode (in case of classification)
the target values
"""
def __init__(
self,
is_classification: bool = False,
logger_port: Optional[int] = None,
dataset_compression: Optional[Mapping[str, Any]] = None,
) -> None:
self.is_classification = is_classification
self.logger_port = logger_port
self.dataset_compression = dataset_compression
if self.logger_port is not None:
self.logger: Union[logging.Logger, PicklableClientLogger] = get_named_client_logger(
name='Validation',
port=self.logger_port,
)
else:
self.logger = logging.getLogger('Validation')
self.feature_validator = TabularFeatureValidator(
dataset_compression=self.dataset_compression,
logger=self.logger)
self.target_validator = TabularTargetValidator(
is_classification=self.is_classification,
logger=self.logger
)
self._is_fitted = False