LukeMathWalker / LukeMathWalker/ndarray-koans

Visualisation of the Kmean generated cluster

未关闭
#5 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Jupyter Notebook
星标
116
派生
20
PR 合并指标
30 天内没有已合并 PR

描述

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(())
}

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

检查 Cargo.toml 和 main.rs 中的 Rust 示例,包括 clustered_points.csv 输入和 Vega-Lite 图表构建。使用提供的聚类数据运行该示例,并确定预期的可视化效果;当生成的聚类点正确显示时,工作即告完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
rust
领域
data-visualization
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。