SafetyForecast

class s3l.ensemble.SafetyForecast.SafetyForecast(C1=1.0, C2=0.01, estimators=None)[source]

Bases: s3l.base.SaferEnsemble

Provide a safer prediction when given a set of training models or predict results. Judge the quality of prediction with large-margin model.

Parameters:
  • C1 (float (default=1.0)) – weight for the hinge loss of labeled instances. It was set as 1 in our paper.
  • C2 (float (default=0.01)) – weight for the hinge loss of unlabeled instances. It was set as 0.01 in our paper.
  • pred_values (predict values) –
  • fallback_ind (fallback indexs of unsafe prediction.) –
  • estimators (list of estimators,optional (default=None)) – When ‘estimators’ is none, it means user should provide predictive results. When ‘estimators’ is a list,each member of list is a tuple. Each tuple is an initialization of a estimator and a description of its parameters [(estimator,fit_params)].

Examples

When the ‘estimators’ parameter is initialized, the calling method is roughly as follows:

>>> from s3l.classification.TSVM import TSVM
>>> from s3l.model_uncertainty.S4VM import S4VM
>>> estimator_list = [(TSVM(),False), (S4VM(),True)]
>>> model = SafetyForecast(estimators=estimator_list)
>>> model.fit(x, y, l_ind)
>>> model.predict(u_ind)

It can be used like this when the ‘estimators’ is None:

>>> model = SafetyForecast()
>>> model.fit(prediction, y, l_ind)
>>> model.predict(u_ind, baseline_pred)
fit(X, y, l_ind)[source]

Provide an interface that can pass in multiple learners or predictive results.

Parameters:
  • X (array-like) – Data matrix with [n_samples, n_features] or a set of prediction.
  • y (array-like) – Each element is +1 or -1 for labeled instances. For unlabeled instances, this parameter could be used for computing accuracy if the ground truth is available.
  • l_ind (array-like) – a row vector with length l, where l is the number of labeled instance. Each element is an index of a labeled instance.
fit_estimators(X, y, l_ind, u_ind)[source]

Provide a training interface that trains multiple models and give a safer prediction of these models.

Parameters:
  • X (array-like) – Data matrix with [n_samples, n_features].The data will be used to train models.
  • y (array-like) – Each element is +1 or -1 for labeled instances. For unlabeled instances, this parameter could be used for computing accuracy if the ground truth is available.
  • l_ind (array-like) – a row vector with length l, where l is the number of labeled instance. Each element is an index of a labeled instance.
  • u_ind (array-like) – a row vector with length l, where l is the number of unlabeled instance. Each element is an index of a unlabeled instance.
fit_pred(prediction, label, l_ind, u_ind)[source]

Predict a safer result from predictions, train method judge the quality of prediction with large-margin model

Parameters:
  • prediction (array-like) – A set of prediction.Each row is a set of predictive values of an instance.Each col is a prediction result.
  • label (array-like) – Each element is +1 or -1 for labeled instances. For unlabeled instances, this parameter could be used for computing accuracy if the ground truth is available.
  • l_ind (array-like) – a row vector with length l, where l is the number of labeled instance. Each element is an index of a labeled instance.
  • u_ind (array-like) – a row vector with length l, where l is the number of unlabeled instance. Each element is an index of a unlabeled instance.
predict(u_ind, baseline_pred=None)[source]

Predict method replace the unsafe prediction with the baseline_pred to improve the safeness.

Parameters:
  • u_ind (array-like) – a row vector with length l, where l is the number of unlabeled instance. Each element is an index of a unlabeled instance.
  • baseline_pred (array-like) – Each element is a baseline predictive result of the corresponding instance. LEAD will replace the result of S3VM with this if the instance locates in the margin of S3VM.
Returns:

pred – the label of the instance, including labeled and unlabeled instances, even though for labeled instances the prediction is consistent with the true label.

Return type:

a column vector with length n. Each element is a prediction for

predict_proba()[source]

Compute probabilities of possible labels for samples in W.

Parameters:None
Returns:pred – Each line is the probability of possible labels of a sample involved in the calculation of the prediction [n_samples, n_labels].
Return type:array-like
set_params(param)[source]

Parameter setting function.

Parameters::dict (param) – Store parameter names and corresponding values {‘name’: value}.