def __init__(self, cm: "metrics.ConfusionMatrix" = None): self.cm = metrics.ConfusionMatrix() if cm is None else cm self.accuracy = metrics.Accuracy(cm=self.cm) self.kappa = metrics.CohenKappa(cm=self.cm) self.kappa_m = metrics.KappaM(cm=self.cm) self.kappa_t = metrics.KappaT(cm=self.cm) self.recall = metrics.Recall(cm=self.cm) self.micro_recall = metrics.MicroRecall(cm=self.cm) self.macro_recall = metrics.MacroRecall(cm=self.cm) self.precision = metrics.Precision(cm=self.cm) self.micro_precision = metrics.MicroPrecision(cm=self.cm) self.macro_precision = metrics.MacroPrecision(cm=self.cm) self.f1 = metrics.F1(cm=self.cm) self.micro_f1 = metrics.MicroF1(cm=self.cm) self.macro_f1 = metrics.MacroF1(cm=self.cm) self.geometric_mean = metrics.GeometricMean(cm=self.cm)
def __init__(self, step, name): self.name = name self.optimizer = SynchronousSGD(0.01, name, None) self.model = compose.Pipeline( preprocessing.StandardScaler(), linear_model.LogisticRegression(self.optimizer)) self.metrics = [ metrics.Accuracy(), metrics.MAE(), metrics.RMSE(), metrics.Precision(), metrics.Recall() ] self.count = 0 if step is None: self.step = 50 else: self.step = int(step)
from river import compose from river import preprocessing from river import linear_model from river import metrics from river import datasets from river import optim optimizer = optim.SGD(0.1) model = compose.Pipeline(preprocessing.StandardScaler(), linear_model.LogisticRegression(optimizer)) metric = metrics.ROCAUC() precision = metrics.Precision() for x, y in datasets.Phishing(): y_pred = model.predict_proba_one(x) model.learn_one(x, y) metric.update(y, y_pred) precision.update(y, y_pred) print(metric) print(precision)
np.random.dirichlet(np.ones(3)).tolist() for _ in range(n) ] yield y_true, y_pred, sample_weights if isinstance(metric, base.RegressionMetric): yield ([random.random() for _ in range(n)], [random.random() for _ in range(n)], sample_weights) def partial(f, **kwargs): return functools.update_wrapper(functools.partial(f, **kwargs), f) TEST_CASES = [ (metrics.Accuracy(), sk_metrics.accuracy_score), (metrics.Precision(), sk_metrics.precision_score), (metrics.MacroPrecision(), partial(sk_metrics.precision_score, average='macro')), (metrics.MicroPrecision(), partial(sk_metrics.precision_score, average='micro')), (metrics.WeightedPrecision(), partial(sk_metrics.precision_score, average='weighted')), (metrics.Recall(), sk_metrics.recall_score), (metrics.MacroRecall(), partial(sk_metrics.recall_score, average='macro')), (metrics.MicroRecall(), partial(sk_metrics.recall_score, average='micro')), (metrics.WeightedRecall(), partial(sk_metrics.recall_score, average='weighted')), (metrics.FBeta(beta=.5), partial(sk_metrics.fbeta_score, beta=.5)), (metrics.MacroFBeta(beta=.5), partial(sk_metrics.fbeta_score, beta=.5, average='macro')), (metrics.MicroFBeta(beta=.5),
if isinstance(metric, base.RegressionMetric): yield ( [random.random() for _ in range(n)], [random.random() for _ in range(n)], sample_weights, ) def partial(f, **kwargs): return functools.update_wrapper(functools.partial(f, **kwargs), f) TEST_CASES = [ (metrics.Accuracy(), sk_metrics.accuracy_score), (metrics.Precision(), partial(sk_metrics.precision_score, zero_division=0)), ( metrics.MacroPrecision(), partial(sk_metrics.precision_score, average="macro", zero_division=0), ), ( metrics.MicroPrecision(), partial(sk_metrics.precision_score, average="micro", zero_division=0), ), ( metrics.WeightedPrecision(), partial(sk_metrics.precision_score, average="weighted", zero_division=0), ),
def __init__(self, beta: float, cm=None, pos_val=True): super().__init__(cm, pos_val) self.beta = beta self.precision = metrics.Precision(self.cm, self.pos_val) self.recall = metrics.Recall(self.cm, self.pos_val)