Message Boards Message Boards

Facing your data with Chernoff faces

Posted 8 years ago
POSTED BY: Anton Antonov
6 Replies

Here are links to the related Python package "ChernoffFace" at:

Here is a plot of the "USA arrests" data using that Python package:

enter image description here

Remark: Because of the way the Python matplotlib library is designed the faces in the plot above are wide instead of being long as in the corresponding WL plot.

POSTED BY: Anton Antonov

Here is a link to the recently approved Wolfram Function Repository function ChernoffFace.

There are some important extensions of the original ChernoffFace scope described above:

  • allowing for auto-coloring with the option "ColorFunction", and

  • allowing a list of records to be visualized.

The latter is not done just with a Map call -- if the data argument can be interpreted as a full array, then the columns are rescaled first. (Each column is rescaled separately.)

An example illustrating that follows.

Get the "USArrests" data:

data = ExampleData[{"Statistics", "USArrests"}];
Dimensions[data]
(* {50, 5} *)

Get the corresponding column names:

dataColumnNames = ExampleData[{"Statistics", "USArrests"}, "ColumnHeadings"]    
(* {"StateName", "Murder", "Assault", "UrbanPopulation", "Rape"} *)

Here is a summary of the dataset:

ResourceFunction["RecordsSummary"][data, dataColumnNames]

enter image description here

Visualize with Chernoff faces:

Block[{data = data[[All, 2 ;; -1]], recNames = data[[All, 1]], dataColumnNames = dataColumnNames[[2 ;; -1]], imgs},
 imgs = ResourceFunction["ChernoffFace"][data, ColorFunction -> "Rainbow", ImageSize -> 100];
 imgs = MapThread[Append[#1, PlotLabel -> #2] &, {imgs, recNames}];
 Legended[
  Grid[Partition[imgs, 8], Dividers -> All],
  Placed[Framed[
    Grid[Thread[{Take[Keys@ResourceFunction["ChernoffFace"]["FaceParts"], Length[dataColumnNames]], dataColumnNames}], 
     Alignment -> {{Right, Left}}]], "Top"]]
 ]

enter image description here

POSTED BY: Anton Antonov

The MathematicaVsR at GitHub project BrowsingDataWithChernoffFaces compares Mathematica and R codes for interactive data browsers that utilize Chernoff faces.

Here is an image (based on the built-in USA arrests data) from the album of screenshots of the Mathematica-made browser:

enter image description here

POSTED BY: Anton Antonov

Here is a combination of Chernoff faces and SectorChart plots:

facesGrid =
 Grid[ArrayReshape[#, {3, 4}, ""], Dividers -> All, Alignment -> {Left, Top}] &@
  MapThread[
   (asc = 
      AssociationThread[
       Take[Keys@ChernoffFace["FacePartsProperties"], 
         Length[#3] + 1] -> Append[#3, #4]];
     Grid[{
       {Row[{"row:", #1, ", x=", #2}], SpanFromLeft},
       {ChernoffFace[Join[asc, <|"FaceColor" -> Blend[{White, Lighter[Yellow]}, #4]|>], 
         ImageSize -> 150, AspectRatio -> Automatic], 
        SectorChart[Transpose@{ConstantArray[1, Length[#3]], #5}]}}]) &
   , {Range[Length[data]], First /@ data, 
    Transpose[Rescale /@ Transpose[Rest /@ data]], 
    PearsonChiSquareTest[Standardize[Rest[#]], NormalDistribution[0, 1]] & /@ data, 
    Rest /@ data}]

enter image description here

POSTED BY: Anton Antonov
POSTED BY: Anton Antonov

enter image description here - another post of yours has been selected for the Staff Picks group, congratulations !

We are happy to see you at the tops of the "Featured Contributor" board. Thank you for your wonderful contributions, and please keep them coming!

POSTED BY: Moderation Team
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract