rust-ml / rust-ml/linfa

Request for improved/updated beginner examples

Open
#378 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
4.7k
Forks
334
Avg merge
39m
Merged PRs (30d)
1

Description

I'm looking to use linfa for k-means clustering, and the current k-means example is pretty incomprehensible to a newbie. It may be that this makes perfect sense to someone steeped in this API or even in ndarray, but to me, the issues are:

  • The current version of rand (0.9.0 as of Feb 2025) appears to be incompatible with the version used in the example
  • Generating random data from a PRNG doesn't help when my goal is to load data from somewhere else. How can I create a mutable data structure that I can push new vectors onto?
  • DatasetBase indicates that it contains records and maybe targets, weights, and feature names. I have no clue what the target/weights are when I'm trying to create input.
  • Not having expected centroids, I'd like to lean on the API to either generate something random, something evenly distributed, or a use some quick heuristic otherwise.

Ultimately, my ideal is to do something like:

let mut records = Dataset::with_capacity(100_000); // expected number of input rows
for row in load_my_data("file.tsv") {
    // where 'row' is, say, a [f64; 5] or a Vec<f32>?
    records.push(row);
}

let initial_state = kmeans::generate_random_centroids(10 /* # clusters */, &records);

let clusters = kmeans::params_with(...).fit(&records);

for (id, cluster) in clusters.iter().enumerate() {
    // presumably cluster is [f64; 5] or &[f32]
    println!("Cluster {id} located @ {cluster:?}");
}

I realize this may diverge drastically from what currently exists, but I'd like to determine how to bridge this gap. Thanks!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with algorithms/linfa-clustering/examples/kmeans.rs and review the linked DatasetBase documentation. Run the existing example, then define a beginner-oriented example that explains loading rows, the meaning of targets and weights, centroid initialization, and the resulting clusters; done means the example is understandable without prior linfa or ndarray knowledge.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation, machine-learning
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.