LukeMathWalker / LukeMathWalker/ndarray-koans

Visualisation of the Kmean generated cluster

Open
#5 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
116
Forks
20
PR merge metrics
No merged PRs in 30d

Description

Hello,
This is the code for the visulalisation of the workshop using rust and vega_lite_3.

Cargo.toml

[dependencies]
vega_lite_3 = {version = "0.1", features = ["show_vega"]}
serde = {version = "1.0", features = ["derive"]}
serde_json = "1.0.39"
derive_builder = "0.9.0"
showata =  "0.1.0"
failure = "0.1.5"
csv = "1.1.1"

main.rs

use csv;
use failure;
use serde::{Deserialize, Serialize};
use showata::Showable;
use std::path::Path;
use vega_lite_3::*;

#[derive(Serialize, Deserialize, Debug)]
pub struct Item {
    pub x: f64,
    pub y: f64,
    pub idx: usize,
}

macro_rules! build {
    ($s:expr ) => {
        $s.build().map_err(|s| failure::format_err!("{}", s))?
    };
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Read in the data using the csv crate
    // The data are organised this way:
    //
    // Point_ID ,Point_x,Point_y, Cluster_idx
    // 0, 9.887634 , 10.700742, 3
    // 1, 10.895053 , 9.602507, 3
    // ...
    // 1475, 1.959400, 13.254207, 1
    let mut rdr = csv::Reader::from_path(Path::new("clustered_points.csv"))?;
    let values = rdr
        .deserialize()
        .into_iter()
        .collect::<Result<Vec<Item>, csv::Error>>()?;
    // Create the plot
    let chart = build!(VegaliteBuilder::default()
        .title("Dataset Points")
        .width(800.0)
        .height(800.0)
        .description("Plot of the clustered dataset generated in by ndarray workshop.")
        .data(&values)
        .mark(Mark::Point)
        .encoding(build!(EncodingBuilder::default()
            .x(build!(XClassBuilder::default()
                .field("x")
                .def_type(StandardType::Quantitative)))
            .y(build!(YClassBuilder::default()
                .field("y")
                .def_type(StandardType::Quantitative)))
            .color(ValueDefWithConditionMarkPropFieldDefStringNull {
                aggregate: None,
                bin: None,
                condition: None,
                field: Some(Field::String("idx".to_string())),
                legend: None,
                scale: None,
                sort: None,
                time_unit: None,
                title: None,
                value: None,
                value_def_with_condition_mark_prop_field_def_string_null_type: None
            }))));
    chart.show()?;
    Ok(())
}

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

Review the Rust example in Cargo.toml and main.rs, including the clustered_points.csv input and the Vega-Lite chart construction. Run the example with the provided clustered data and determine the expected visualization; the work is done when the generated cluster points are displayed correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
data-visualization
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.