Project protected survey observations
Fit training PCA, preserve survey identity through projection and cluster the transformed observations.
import aner.data
import aner.ml
import aner.tensor
let table = data.scan_csv_auto("examples/fixtures/contextual/kmeans_observations.csv").collect()
let surveys = data.frame(table, row_id: "id", group: "survey", target: "",
units: List("", "", "m", "m"))
let parts = surveys.partition_groups(train: List("A", "B"), validation: List(), test: List("C"))
let projection = ml.pca(components: 1).fit(parts.train())
let training = projection.transform(parts.train())
let testing = projection.transform(parts.test())
let clusters = ml.kmeans(clusters: 2, standardize: false).fit(training)
print(projection.explained_variance_ratio().value(0, 0))
print(projection.evaluate(parts.test()))
print(clusters.predict(testing).row_id(0))
Make it your experiment.
Use Aner 0.1.0 or newer. Save this program as examples/pca_surveys.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/pca_surveys.aner
aner run examples/pca_surveys.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Requires Aner 0.1.0 or newer. Requires Aner 0.0.9 or newer. The example uses CPU Float64 and a synthetic CSV fixture. Run it from a writable project directory. Save each supplied fixture beneath the exact examples/fixtures path shown in the source and run from the project root.
aner check examples/pca_surveys.aner
aner run examples/pca_surveys.anerkmeans_observations.csv Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.
Dataset sources & attribution