Contents

MLDataTable.Aggregator.Operations.argmin(outputColumn:)

An operation that retrieves the value in the given column that’s in the same row as the minimum value of the aggregator’s column.

Declaration

case argmin(outputColumn: String)

Discussion

Use this operation to find a value in the given outputColumn that’s in the same row as the minimum value in the aggregator’s column. For example, take the following data table of drink ratings.

let teaVsCoffee = try! MLDataTable(dictionary: [
    "userName" : ["Sara", "Sara", "James", "James"],
    "drink"    : ["tea", "coffee", "tea", "coffee"],
    "rating"   : [5.0, 3.5, 3.1, 4.9]
])

print(teaVsCoffee)

Prints ...
 Columns:
    ratingfloat
    drinkstring
    userNamestring
Rows: 4
Data:
+----------------+----------------+----------------+
| drink          | userName       | rating         |
+----------------+----------------+----------------+
| tea            | Sara           | 5              |
| coffee         | Sara           | 3.5            |
| tea            | James          | 3.1            |
| coffee         | James          | 4.9            |
+----------------+----------------+----------------+
[4 rows x 3 columns]

To find out which person gave the lowest rating for any particular beverage, use the argmin operation with the "userName" string. Then use the group(columnsNamed:aggregators:) function group the "drink" column.

var lowestRater = MLDataTable.Aggregator(operations: .argmin(outputColumn: "userName"),
                                         of: "rating")
let lowestDrinkRatings = teaVsCoffee.group(columnsNamed: "drink",
                                            aggregators: [lowestRater])
print(lowestDrinkRatings)

Prints ...
+----------------+----------------+
| drink          | ratingArgmin   |
+----------------+----------------+
| tea            | James          |
| coffee         | Sara           |
+----------------+----------------+
[2 rows x 2 columns]

In this example, the drinks column only has two distinct drinks, tea and coffee, which result in a data table with two rows.

  • outputColumn: The name of the column that holds the values associated with the minimum values of the aggregator’s designated column.

See Also

Aggregation operations