import javafx.scene.chart.NumberAxis import tornadofx.* import java.time.LocalDate import java.time.temporal.ChronoUnit data class Patient(val firstName: String, val lastName: String, val gender: Gender, val birthday: LocalDate, val whiteBloodCellCount: Int) { val age get() = ChronoUnit.YEARS.between(birthday, LocalDate.now()) } enum class Gender { MALE, FEMALE } val patients = listOf( Patient("John", "Simone", Gender.MALE, LocalDate.of(1990, 1, 7), 4500), Patient("Sarah", "Marley", Gender.FEMALE, LocalDate.of(1971, 2, 5), 6700), Patient("Jessica", "Arnold", Gender.FEMALE, LocalDate.of(1973, 3, 9), 3400), Patient("Sam", "Beasley", Gender.MALE, LocalDate.of(1992, 4, 17), 8800), Patient("Dan", "Forney", Gender.MALE, LocalDate.of(1985, 9, 13), 5400), Patient("Lauren", "Michaels", Gender.FEMALE, LocalDate.of(1986, 8, 21), 5000), Patient("Michael", "Erlich", Gender.MALE, LocalDate.of(1993, 12, 17), 4100), Patient("Jason", "Miles", Gender.MALE, LocalDate.of(1991, 11, 1), 3900), Patient("Rebekah", "Earley", Gender.FEMALE, LocalDate.of(1975, 2, 18), 4600), Patient("James", "Larson", Gender.MALE, LocalDate.of(1974, 4, 10), 5100), Patient("Dan", "Ulrech", Gender.MALE, LocalDate.of(1992, 7, 11), 6000), Patient("Heather", "Eisner", Gender.FEMALE, LocalDate.of(1994, 3, 6), 6000), Patient("Jasper", "Martin", Gender.MALE, LocalDate.of(1971, 7, 1), 6000) ) class MyApp: App(MyView::class) class MyView : View() { override val root = scatterchart("WBCC Clustering by Age", NumberAxis(), NumberAxis()) { patients.fuzzyKMeansCluser(k = 3, fuzziness =50.0, xSelector = { it.age.toDouble() }, ySelector = { it.whiteBloodCellCount.toDouble() } ) .forEachIndexed { index, centroid -> series("Group ${index + 1}") { centroid.points.forEach { data(it.age, it.whiteBloodCellCount) } } } } }