Changeset 10740:efdd4d5af0de in orange


Ignore:
Timestamp:
04/04/12 11:15:18 (2 years ago)
Author:
Miran@…
Branch:
default
Message:

Added two new multi-target method scorers, mt_global_accuracy and mt_mean_accuracy

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/evaluation/scoring.py

    r10633 r10740  
    26682668    return score(res2) 
    26692669 
     2670def mt_global_accuracy(res): 
     2671    """ 
     2672    \emph{Global accuracy} (accuracy per example) over \emph{d}-dimensional class variable. 
     2673    :math:`Acc = \frac{1}{N}\sum_{i=1}^{N}\delta(\mathbf{c_{i}'},\mathbf{c_{i}})` 
     2674    :math:'\delta (\mathbf{c_{i}'},\mathbf{c_{i}} )=\left\{\begin{matrix}1:\mathbf{c_{i}'}=\mathbf{c_{i}}\\ 0: otherwise\end{matrix}' 
     2675    """ 
     2676    results = [] 
     2677    for l in xrange(res.number_of_learners): 
     2678        n_results = len(res.results) 
     2679        n_correct = 0. 
     2680 
     2681        for r in res.results: 
     2682            if list(r.classes[l]) == r.actual_class: 
     2683                n_correct+=1 
     2684 
     2685        results.append(n_correct/n_results) 
     2686    return results 
     2687 
     2688def mt_mean_accuracy(res): 
     2689    """ 
     2690    \emph{Mean accuracy} (accuracy per class or per label) over \emph{d} class variables. 
     2691    :math:`\overline{Acc_{d}} = \frac{1}{d}\sum_{j=1}^{d}Acc_{j} = \frac{1}{d}\sum_{j=1}^{d} \frac{1}{N}\sum_{i=1}^{N}\delta(c_{ij}',c_{ij} )` 
     2692    :math:'\delta (c_{ij}',c_{ij} )=\left\{\begin{matrix}1:c_{ij}'=c_{ij}\\ 0: otherwise\end{matrix}' 
     2693    """ 
     2694    results = [] 
     2695    for l in xrange(res.number_of_learners): 
     2696        n_classes = len(res.results[0].actual_class) 
     2697        n_results = len(res.results) 
     2698        n_correct = 0. 
     2699 
     2700        for r in res.results: 
     2701            #n_correct+=sum((1 if r.classes[l][i] == r.actual_class[i] else 0 for i in xrange(n_classes))) 
     2702            for i in xrange(n_classes): 
     2703                if r.classes[l][i] == r.actual_class[i]: 
     2704                    n_correct+=1 
     2705        results.append(n_correct/n_classes/n_results) 
     2706    return results 
    26702707 
    26712708################################################################################ 
Note: See TracChangeset for help on using the changeset viewer.