concept age in category algorithms

appears as: ge
Classic Computer Science Problems in Java

This is an excerpt from Manning's book Classic Computer Science Problems in Java.

6.3      Clustering governors by age and longitude

Every American state has a governor. In June 2017, those governors ranged in age from 42 to 79. If we take the United States from east to west, looking at each state by its longitude, perhaps we can find clusters of states with similar longitudes and similar-age governors. Figure 6.2 is a scatter plot of all 50 governors. The x-axis is state longitude, and the y-axis is governor age.

Classic Computer Science Problems in Python

This is an excerpt from Manning's book Classic Computer Science Problems in Python.

6.3. Clustering governors by age and longitude

Every American state has a governor. In June 2017, those governors ranged in age from 42 to 79. If we take the United States from east to west, looking at each state by its longitude, perhaps we can find clusters of states with similar longitudes and similar-age governors. Figure 6.2 is a scatter plot of all 50 governors. The x-axis is state longitude, and the y-axis is governor age.

Classic Computer Science Problems in Swift: Essential techniques for practicing programmers

This is an excerpt from Manning's book Classic Computer Science Problems in Swift: Essential techniques for practicing programmers.

6.3. Clustering governors by age and longitude

Every American state has a governor. In June 2017, those governors ranged in age from 42 to 79. If we take the United States from east to west, looking at each state by its longitude, perhaps we can find clusters of states with similar longitudes and similar age governors. Figure 6.1 is a scatter plot of all 50 governors. The x-axis is state longitude and the y-axis is governor age.

struct Governor: DataPoint {
    public static let numDimensions: UInt = 2
    public let longitude: Double
    public let age: Double
    public var dimensions: [Double]
    public let state: String

    public init(longitude: Double, age: Double, state: String) {
        self.longitude = longitude
        self.age = age
        self.state = state
        dimensions = [longitude, age]
    }

    public init(values: [Double]) {
        self.longitude = values[0]
        self.age = values[1]
        self.state = ""
        dimensions = values
    }

    // Implement Equatable
    public static func == (lhs: Governor, rhs: Governor) -> Bool {
        return lhs.longitude == rhs.longitude && lhs.age == rhs.age &&
         lhs.state == rhs.state
    }

    // Implement CustomStringConvertible
    public var description: String {
        return "\(state): (longitude: \(longitude), age: \(age))"
    }
}

A Governor has two dimensions—longitude and age—rather than the three in Point3D. Other than that, Governor is almost identical to Point3D in implementation. It would be pretty unreasonable to enter the following data manually, so check out the Playground that accompanies this book.