Dataset: https://www.kaggle.com/datasets/youssefismail20/credit-and-smes-synth-data-credit-analysis/data
Using the synthetic credit card consumers dataset, determine an optimal clustering.
library(cluster)
library(factoextra)
library(tidyverse)
cons_data<-read.csv("https://rebelskyw.cs.grinnell.edu/wp-content/uploads/2025/03/synthetic_credit_consumers.csv")
row.names(cons_data)<-cons_data[,1]
k2 <- kmeans(cons_data[3:7], centers = 2, nstart = 1)
out_data<-data.frame(k2$cluster)
out_data$id<-row.names(out_data)
write_csv(out_data,"predicted.csv")
head(read_csv("predicted.csv")) # your dataset should look like this, make sure you don't save the row id
## Rows: 1000 Columns: 2
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): id
## dbl (1): k2.cluster
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## # A tibble: 6 × 2
## k2.cluster id
## <dbl> <chr>
## 1 1 e11fa949-37eb-4999-bdbd-5d3c401b80fa
## 2 1 416c9fe3-d43b-45a5-978e-aa8a4311b5c9
## 3 1 b1b99342-704e-449f-90f7-2c5287518e1f
## 4 1 67a301f6-c1ad-49be-92f6-36e6201c82ac
## 5 2 a90ff7c6-c1ac-4fe5-896f-dfb1685b7a3b
## 6 2 9b2239f3-8556-4c7a-acf8-03ab4f82540a