# Path: libact/base/interfaces.py
# class Model(with_metaclass(ABCMeta, object)):
# 
#     """Classification Model
# 
#     A Model returns a class-predicting function for future samples after
#     trained on a training dataset.
#     """
#     @abstractmethod
#     def train(self, dataset, *args, **kwargs):
#         """Train a model according to the given training dataset.
# 
#         Parameters
#         ----------
#         dataset : Dataset object
#              The training dataset the model is to be trained on.
# 
#         Returns
#         -------
#         self : object
#             Returns self.
#         """
#         pass
# 
#     @abstractmethod
#     def predict(self, feature, *args, **kwargs):
#         """Predict the class labels for the input samples
# 
#         Parameters
#         ----------
#         feature : array-like, shape (n_samples, n_features)
#             The unlabeled samples whose labels are to be predicted.
# 
#         Returns
#         -------
#         y_pred : array-like, shape (n_samples,)
#             The class labels for samples in the feature array.
#         """
#         pass
# 
#     @abstractmethod
#     def score(self, testing_dataset, *args, **kwargs):
#         """Return the mean accuracy on the test dataset
# 
#         Parameters
#         ----------
#         testing_dataset : Dataset object
#             The testing dataset used to measure the perforance of the trained
#             model.
# 
#         Returns
#         -------
#         score : float
#             Mean accuracy of self.predict(X) wrt. y.
#         """
#         pass
# 
# class ContinuousModel(Model):
# 
#     """Classification Model with intermediate continuous output
# 
#     A continuous classification model is able to output a real-valued vector
#     for each features provided.
#     """
#     @abstractmethod
#     def predict_real(self, feature, *args, **kwargs):
#         """Predict confidence scores for samples.
# 
#         Returns the confidence score for each (sample, class) combination.
# 
#         The larger the value for entry (sample=x, class=k) is, the more
#         confident the model is about the sample x belonging to the class k.
# 
#         Take Logistic Regression as example, the return value is the signed
#         distance of that sample to the hyperplane.
# 
#         Parameters
#         ----------
#         feature : array-like, shape (n_samples, n_features)
#             The samples whose confidence scores are to be predicted.
# 
#         Returns
#         -------
#         X : array-like, shape (n_samples, n_classes)
#             Each entry is the confidence scores per (sample, class)
#             combination.
#         """
#         pass
# 
# class ProbabilisticModel(ContinuousModel):
# 
#     """Classification Model with probability output
# 
#     A probabilistic classification model is able to output a real-valued vector
#     for each features provided.
#     """
#     def predict_real(self, feature, *args, **kwargs):
#         return self.predict_proba(feature, *args, **kwargs)
# 
#     @abstractmethod
#     def predict_proba(self, feature, *args, **kwargs):
#         """Predict probability estimate for samples.
# 
#         Parameters
#         ----------
#         feature : array-like, shape (n_samples, n_features)
#             The samples whose probability estimation are to be predicted.
# 
#         Returns
#         -------
#         X : array-like, shape (n_samples, n_classes)
#             Each entry is the prabablity estimate for each class.
#         """
#         pass


from sklearn.base import clone
from libact.base.interfaces import Model, ContinuousModel, ProbabilisticModel
       from libact.models import SklearnAdapter

       iris = datasets.load_iris()
       X = iris.data
       y = iris.target
       X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)

       adapter = SklearnAdapter(LogisticRegression(random_state=1126))

       adapter.train(Dataset(X_train, y_train))
       adapter.predict(X_test)
    """

    def __init__(self, clf):
        self._model = clf

    def train(self, dataset, *args, **kwargs):
        return self._model.fit(*(dataset.format_sklearn() + args), **kwargs)

    def predict(self, feature, *args, **kwargs):
        return self._model.predict(feature, *args, **kwargs)

    def score(self, testing_dataset, *args, **kwargs):
        return self._model.score(*(testing_dataset.format_sklearn() + args),
                                **kwargs)

    def clone(self):
        return SklearnProbaAdapter(clone(self._model))



# Path: libact/base/interfaces.py
# class Model(with_metaclass(ABCMeta, object)):
# 
#     """Classification Model
# 
#     A Model returns a class-predicting function for future samples after
#     trained on a training dataset.
#     """
#     @abstractmethod
#     def train(self, dataset, *args, **kwargs):
#         """Train a model according to the given training dataset.
# 
#         Parameters
#         ----------
#         dataset : Dataset object
#              The training dataset the model is to be trained on.
# 
#         Returns
#         -------
#         self : object
#             Returns self.
#         """
#         pass
# 
#     @abstractmethod
#     def predict(self, feature, *args, **kwargs):
#         """Predict the class labels for the input samples
# 
#         Parameters
#         ----------
#         feature : array-like, shape (n_samples, n_features)
#             The unlabeled samples whose labels are to be predicted.
# 
#         Returns
#         -------
#         y_pred : array-like, shape (n_samples,)
#             The class labels for samples in the feature array.
#         """
#         pass
# 
#     @abstractmethod
#     def score(self, testing_dataset, *args, **kwargs):
#         """Return the mean accuracy on the test dataset
# 
#         Parameters
#         ----------
#         testing_dataset : Dataset object
#             The testing dataset used to measure the perforance of the trained
#             model.
# 
#         Returns
#         -------
#         score : float
#             Mean accuracy of self.predict(X) wrt. y.
#         """
#         pass
# 
# class ContinuousModel(Model):
# 
#     """Classification Model with intermediate continuous output
# 
#     A continuous classification model is able to output a real-valued vector
#     for each features provided.
#     """
#     @abstractmethod
#     def predict_real(self, feature, *args, **kwargs):
#         """Predict confidence scores for samples.
# 
#         Returns the confidence score for each (sample, class) combination.
# 
#         The larger the value for entry (sample=x, class=k) is, the more
#         confident the model is about the sample x belonging to the class k.
# 
#         Take Logistic Regression as example, the return value is the signed
#         distance of that sample to the hyperplane.
# 
#         Parameters
#         ----------
#         feature : array-like, shape (n_samples, n_features)
#             The samples whose confidence scores are to be predicted.
# 
#         Returns
#         -------
#         X : array-like, shape (n_samples, n_classes)
#             Each entry is the confidence scores per (sample, class)
#             combination.
#         """
#         pass
# 
# class ProbabilisticModel(ContinuousModel):
# 
#     """Classification Model with probability output
# 
#     A probabilistic classification model is able to output a real-valued vector
#     for each features provided.
#     """
#     def predict_real(self, feature, *args, **kwargs):
#         return self.predict_proba(feature, *args, **kwargs)
# 
#     @abstractmethod
#     def predict_proba(self, feature, *args, **kwargs):
#         """Predict probability estimate for samples.
# 
#         Parameters
#         ----------
#         feature : array-like, shape (n_samples, n_features)
#             The samples whose probability estimation are to be predicted.
# 
#         Returns
#         -------
#         X : array-like, shape (n_samples, n_classes)
#             Each entry is the prabablity estimate for each class.
#         """
#         pass


# Path: libact/models/sklearn_adapter.py
from sklearn.base import clone
from libact.base.interfaces import Model, ContinuousModel, ProbabilisticModel

       from libact.models import SklearnAdapter

       iris = datasets.load_iris()
       X = iris.data
       y = iris.target
       X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)

       adapter = SklearnAdapter(LogisticRegression(random_state=1126))

       adapter.train(Dataset(X_train, y_train))
       adapter.predict(X_test)
    """

    def __init__(self, clf):
        self._model = clf

    def train(self, dataset, *args, **kwargs):
        return self._model.fit(*(dataset.format_sklearn() + args), **kwargs)

    def predict(self, feature, *args, **kwargs):
        return self._model.predict(feature, *args, **kwargs)

    def score(self, testing_dataset, *args, **kwargs):
        return self._model.score(*(testing_dataset.format_sklearn() + args),
                                **kwargs)

    def clone(self):
        return SklearnProbaAdapter(clone(self._model))



class SklearnProbaAdapter(ProbabilisticModel):