R/Metrics_by_sample.R

Defines functions matching_by_sample

#
#
# Matching:During all iterations, the most of time, the sample were allocated with the same cluster as the original.
# Total_Matching:The samples were allocated 100% in the same cluster as the original class.
# Majority_matching:Returns the percentage that the sample of class Cx was allocated in a
# cluster whose majority of the elements is of the same class Cx.
# Summary_matching:Return  the clusters that samples was allocated during the iterations and the
# percentage associated with each cluster. Example:(C1, 80), (C2, 10), (C3, 10


matching_by_sample <- function(Info_samples_)
{

  matching_table <-
    filter(Info_samples_,
           Info_samples_$Original_Label ==  Info_samples_$Cluster_Label)


  Total_Matching_table <-
    filter(Info_samples_,
           Info_samples_$Original_Label ==  Info_samples_$Cluster_Label &
             Info_samples_$Percentage==100)

  Total_Matching <-
    tibble::as_tibble(
      list(
        Id_Sample = Total_Matching_table$Id_Sample ,
        Percentage = Total_Matching_table$Percentage
      )
    )

  Majority_matching_table <- filter(
    matching_table,
    matching_table$Original_Label ==  matching_table$Cluster_Label &
      matching_table$Neuron_Label ==  matching_table$Cluster_Label
  )

  Majority_matching <-
    tibble::as_tibble(
      list(
        Id_Sample = Majority_matching_table$Id_Sample ,
        Percentage = Majority_matching_table$Percentage
      )
    )




  Summary_matching <-
    tibble::as_tibble(
      list(
        Id_Sample = matching_table$Id_Sample ,
        Neuron_Label= matching_table$Neuron_Label ,
        Percentage = matching_table$Percentage
      )
    )


  Matching <-  structure(list(
    Total_Matching = Total_Matching,
    Majority_matching = Majority_matching,
    Summary_matching = Summary_matching
  ),
  class = "SITSSA")


}


# Confusion: During all iterations, the most of time, the sample were allocated with the different
#cluster as the original.
#
# Total_confusion:  The samples were allocated 100% in #the different cluster as the original class.
#
# Majority_confusion: Returns the percentage that the sample of class Cx was allocated in a cluster
# whose majority of the elements has different class of Cx.
#
# Summary_confusion: Return the original label sample and the clusters that samples was allocated
# during the iterations and the percentage associated with each cluster. Example:  (C1, 80), (C2, 10), (C3, 10)


confusion_by_samples <-function (Info_samples_)
{


  confusion_table <-
    filter(Info_samples_,
           Info_samples_$Original_Label !=  Info_samples_$Cluster_Label)

  Total_Confusion_table <-
    filter(Info_samples_,
           Info_samples_$Original_Label !=  Info_samples_$Cluster_Label &
             Info_samples_$Percentage==100)

  Total_Confusion <-
    tibble::as_tibble(
      list(
        Id_Sample = Total_Confusion_table$Id_Sample ,
        Percentage = Total_Confusion_table$Percentage
      )
    )

  Majority_confusion_table <- filter(
    confusion_table,
    confusion_table$Original_Label !=  confusion_table$Cluster_Label &
      confusion_table$Neuron_Label ==  confusion_table$Cluster_Label
  )

  Majority_confusion <-
    tibble::as_tibble(
      list(
        Id_Sample = Majority_confusion_table$Id_Sample ,
        Percentage = Majority_confusion_table$Percentage
      )
    )


  Summary_confusion <-
    tibble::as_tibble(
      list(
        Id_Sample = confusion_table$Id_Sample ,
        Original_Label= confusion_table$Original_Label,
        Neuron_Label= confusion_table$Neuron_Label ,
        Percentage = confusion_table$Percentage
      )
    )


  Confusion <-  structure(list(
    Total_Confusion = Total_Confusion,
    Majority_confusion = Majority_confusion,
    Summary_confusion = Summary_confusion
  ),
  class = "SITSSA")

}
lorenalves/SITSSA documentation built on May 20, 2019, 11:59 a.m.