def test_requires_probabilistic_classifier(self): """ Assert requires probabilistic classifier """ message = "requires a probabilistic binary classifier" assert is_classifier(RadiusNeighborsClassifier) assert not is_probabilistic(RadiusNeighborsClassifier) with pytest.raises(yb.exceptions.YellowbrickError, match=message): DiscriminationThreshold(RadiusNeighborsClassifier())
def test_accepts_decision_function(self): """ Will accept classifiers with decision function """ model = LinearSVC assert is_classifier(model) assert is_probabilistic(model) assert hasattr(model, "decision_function") assert not hasattr(model, "predict_proba") try: DiscriminationThreshold(model()) except YellowbrickTypeError: pytest.fail("did not accept decision function model")
def __init__( self, estimator, ax=None, n_trials=50, cv=0.1, fbeta=1.0, argmax="fscore", exclude=None, quantiles=QUANTILES_MEDIAN_80, random_state=None, is_fitted="auto", force_model=False, **kwargs ): # Perform some quick type checking to help users avoid error. if not force_model and ( not is_classifier(estimator) or not is_probabilistic(estimator) ): raise YellowbrickTypeError( "{} requires a probabilistic binary classifier".format( self.__class__.__name__ ) ) # Check the various inputs self._check_quantiles(quantiles) self._check_cv(cv) self._check_exclude(exclude) # Initialize the ModelVisualizer super(DiscriminationThreshold, self).__init__( estimator, ax=ax, is_fitted=is_fitted, **kwargs ) # Set params self.n_trials = n_trials self.cv = cv self.fbeta = fbeta self.argmax = argmax self.exclude = exclude self.quantiles = quantiles self.random_state = random_state
def test_requires_probabilistic_classifier(self): """ Assert requires probabilistic classifier """ message = "requires a probabilistic binary classifier" class RoboClassifier(ClassifierMixin): """ Dummy Non-Probabilistic Classifier """ def fit(self, X, y): self.classes_ = [0, 1] return self assert is_classifier(RoboClassifier) assert not is_probabilistic(RoboClassifier) with pytest.raises(yb.exceptions.YellowbrickError, match=message): DiscriminationThreshold(RoboClassifier())
def __init__(self, model, ax=None, n_trials=50, cv=0.1, fbeta=1.0, argmax='fscore', exclude=None, quantiles=QUANTILES_MEDIAN_80, random_state=None, **kwargs): # Perform some quick type checking to help users avoid error. if not is_classifier(model) or not is_probabilistic(model): raise YellowbrickTypeError( "{} requires a probabilistic binary classifier".format( self.__class__.__name__)) # Check the various inputs self._check_quantiles(quantiles) self._check_cv(cv) self._check_exclude(exclude) # Initialize the ModelVisualizer super(DiscriminationThreshold, self).__init__(model, ax=ax, **kwargs) # Set params self.set_params( n_trials=n_trials, cv=cv, fbeta=fbeta, argmax=argmax, exclude=exclude, quantiles=quantiles, random_state=random_state, )
def __init__(self, model, ax=None, n_trials=50, cv=0.1, fbeta=1.0, argmax='fscore', exclude=None, quantiles=QUANTILES_MEDIAN_80, random_state=None, **kwargs): # Perform some quick type checking to help users avoid error. if not is_classifier(model) or not is_probabilistic(model): raise YellowbrickTypeError( "{} requires a probabilistic binary classifier".format( self.__class__.__name__ )) # Check the various inputs self._check_quantiles(quantiles) self._check_cv(cv) self._check_exclude(exclude) # Initialize the ModelVisualizer super(DiscriminationThreshold, self).__init__(model, ax=ax, **kwargs) # Set params self.set_params( n_trials=n_trials, cv=cv, fbeta=fbeta, argmax=argmax, exclude=exclude, quantiles=quantiles, random_state=random_state, )