Пример #1
0
    def __init__(self,
                 training_dataset,
                 test_dataset=None,
                 datapoints=None,
                 gamma=None,
                 multiclass_extension=None):
        self.validate(locals())
        super().__init__()
        if training_dataset is None:
            raise AquaError('Training dataset must be provided.')

        is_multiclass = get_num_classes(training_dataset) > 2
        if is_multiclass:
            if multiclass_extension is None:
                raise AquaError(
                    'Dataset has more than two classes. A multiclass extension must be provided.'
                )
        else:
            if multiclass_extension is not None:
                logger.warning(
                    "Dataset has just two classes. Supplied multiclass extension will be ignored"
                )

        if multiclass_extension is None:
            svm_instance = _SVM_Classical_Binary(training_dataset,
                                                 test_dataset, datapoints,
                                                 gamma)
        else:
            svm_instance = _SVM_Classical_Multiclass(training_dataset,
                                                     test_dataset, datapoints,
                                                     gamma,
                                                     multiclass_extension)

        self.instance = svm_instance
Пример #2
0
    def __init__(
            self,
            training_dataset: Dict[str, np.ndarray],
            test_dataset: Optional[Dict[str, np.ndarray]] = None,
            datapoints: Optional[np.ndarray] = None,
            gamma: Optional[int] = None,
            multiclass_extension: Optional[MulticlassExtension] = None
    ) -> None:
        # pylint: disable=line-too-long
        """

        Args:
            training_dataset: training dataset.
            test_dataset: testing dataset.
            datapoints: prediction dataset.
            gamma: Used as input for sklearn rbf_kernel internally. See
                `sklearn.metrics.pairwise.rbf_kernel
                <https://scikit-learn.org/stable/modules/generated/sklearn.metrics.pairwise.rbf_kernel.html>`_
                for more information about gamma.
            multiclass_extension: if number of classes > 2 then
                a multiclass scheme is needed.

        Raises:
            AquaError: If using binary classifier where num classes >= 3
        """
        super().__init__()
        if training_dataset is None:
            raise AquaError('Training dataset must be provided.')

        is_multiclass = get_num_classes(training_dataset) > 2
        if is_multiclass:
            if multiclass_extension is None:
                raise AquaError('Dataset has more than two classes. '
                                'A multiclass extension must be provided.')
        else:
            if multiclass_extension is not None:
                logger.warning(
                    "Dataset has just two classes. Supplied multiclass "
                    "extension will be ignored")

        if multiclass_extension is None:
            svm_instance = _SVM_Classical_Binary(training_dataset,
                                                 test_dataset, datapoints,
                                                 gamma)
        else:
            svm_instance = _SVM_Classical_Multiclass(training_dataset,
                                                     test_dataset, datapoints,
                                                     gamma,
                                                     multiclass_extension)

        self.instance = svm_instance