Function Repository Resource:

RandomPetName

Source Notebook

Generate random pet names

Contributed by: Anton Antonov

ResourceFunction["RandomPetName"][]

gives a random pet name.

ResourceFunction["RandomPetName"][n]

gives a list of n random pet names.

ResourceFunction["RandomPetName"][species]

gives a random pet name of the specified species.

ResourceFunction["RandomPetName"][species,n]

gives n random pet names of the specified species.

ResourceFunction["RandomPetName"][All]

gives an association of associations of species and names with frequencies.

Details and Options

The pet names are taken from publicly available data of pet license registrations in the years 2015–2020 in Seattle, WA, USA.
The following species are supported:
"Cat"cat pet names
"Dog"dog pet names
"Goat"goat pet names
"Pig"pig pet names
The option "Weighted" controls whether the random choice of pet names are weighted based on their popularity or not. By default, "Weighted" is set to False.

Examples

Basic Examples (4) 

Random pet name:

In[1]:=
SeedRandom[5];
ResourceFunction["RandomPetName"][]
Out[2]=

A list of four random pet names:

In[3]:=
ResourceFunction["RandomPetName"][4]
Out[3]=

A random dog name:

In[4]:=
ResourceFunction["RandomPetName"]["Dog"]
Out[4]=

A list of five cat names:

In[5]:=
ResourceFunction["RandomPetName"]["Cat", 5]
Out[5]=

Scope (2) 

All pet names with their weights per species can be obtained with the argument All:

In[6]:=
Length /@ ResourceFunction["RandomPetName"][All]
Out[6]=

The weights are integers that correspond to number of occurrences in pet license registration data. Here are the most popular names per species:

In[7]:=
TakeLargest[#, 3] & /@ ResourceFunction["RandomPetName"][All]
Out[7]=

Options (2) 

Weighted (2) 

The option "Weighted" can be used to specify random pet name choice based on known real-life number of occurrences:

In[8]:=
ResourceFunction["RandomPetName"][20, "Weighted" -> True]
Out[8]=

Here are the number of occurrences of the twelve most frequent pet dog names in a large generated sample:

In[9]:=
SeedRandom[7];
TakeLargestBy[
 Tally[ResourceFunction["RandomPetName"]["Dog", 10000, "Weighted" -> True]], #[[2]] &, 12]
Out[10]=

Applications (4) 

Pet name classifier (4) 

Classify pet names into species. Make the training data:

In[11]:=
SeedRandom[44];
data =
  Join[
   Thread[
    ResourceFunction["RandomPetName"]["Dog", 6000, "Weighted" -> True] -> "Dog"],
   Thread[
    ResourceFunction["RandomPetName"]["Cat", 6000, "Weighted" -> True] -> "Cat"]
   ];
data = Map[Characters[ToLowerCase[#[[1]]]] -> #[[2]] &, data];
{trainingData, testData} = TakeDrop[RandomSample[data], Round[0.7*Length[data]]];

Create (train) the classifier:

In[12]:=
cl = Classify[trainingData, Method -> "NearestNeighbors"]
Out[12]=

Here we create a ClassifierMeasurements object:

In[13]:=
cm = ClassifierMeasurements[cl, testData]
Out[13]=

Here are the Receiver Operating Characteristic (ROC) curves:

In[14]:=
cm["ROCCurve"]
Out[14]=

We can conclude that there are some patterns in the pet names that can be used to distinguish cat names from dog names.

Properties and Relations (2) 

Typical Pareto principle adherence is observed when applying weighted generation of pet names:

In[15]:=
SeedRandom[32]; Association@
 Map[# -> ResourceFunction["ParetoPrinciplePlot"][
     Tally[ResourceFunction["RandomPetName"][#, 10000, "Weighted" -> True]][[All, 2]], ImageSize -> Medium] &, {"Cat", "Dog"}]
Out[15]=

Here are plots for the Pareto principle adherence for the data on which RandomPetName is based:

In[16]:=
Association@
 Map[# -> ResourceFunction["ParetoPrinciplePlot"][
     Values[ResourceFunction["RandomPetName"][All][#]], ImageSize -> Medium] &, {"Cat", "Dog"}]
Out[16]=

We can see the similarity of those Pareto principle plots with ones for generated pet names.

Possible Issues (1) 

There are too few goat and pig names:

In[17]:=
KeyTake[ResourceFunction["RandomPetName"][All], {"Goat", "Pig"}]
Out[17]=

Neat Examples (1) 

Make a dataset of typical pet names for cats and dogs:

In[18]:=
SeedRandom[15];
Dataset[Map[<|"Specie" -> #, "Name" -> ResourceFunction["RandomPetName"][#, "Weighted" -> True]|> &, RandomChoice[{"Cat", "Dog"}, 12]]]
Out[19]=

Publisher

Anton Antonov

Version History

  • 1.0.0 – 04 March 2021

Source Metadata

Related Resources

License Information