-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(sequence-scatter-background): add categorical background drawing… #3759
base: feat/sequence-scatter
Are you sure you want to change the base?
feat(sequence-scatter-background): add categorical background drawing… #3759
Conversation
const xExtent = { min: xMin - xExpand, max: xMax + xExpand }; | ||
const yExtent = { min: yMin - yExpand, max: yMax + yExpand }; | ||
|
||
const xStep = (xExtent.max - xExtent.min) / bins; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
symbolType: 'rect', | ||
x: (datum: any, ctx: any) => { | ||
// 获取region位置 | ||
// const regionStartPoint = ctx.chart.getAllRegions()[0].getLayoutStartPoint(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释的代码可以去掉
{ | ||
id: 'colorScale', | ||
type: 'ordinal', | ||
specified: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
色盘建议提出来,写成常量
|
||
const kdeResult: Array<{ x: number; y: number; kde: number; label: string }> = []; | ||
|
||
const expandRatio = 0.2; // 扩展比例 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
写成常量,const EXPAND_RATIO = 0.2,提出来放到同级目录下的constant.ts中
} | ||
] | ||
}); | ||
}); | ||
return result; | ||
} | ||
|
||
// KDE 相关的工具函数 | ||
function gaussKernel(x: number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
工具函数可以放到同级目录下的utils.ts文件中
xField: spec.xField, | ||
yField: spec.yField | ||
dataIndex: 0, | ||
xField: 'x', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
从配置中读取spec.xField, spec.yField, spec.seriesField
} | ||
density = density / (points.length * h * h); | ||
densities.push(density); // 先暂存 density 值 | ||
kdeResult.push({ x, y, kde: density, label }); // 同时也先存入 kdeResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
数据字段保持和spec统一,[spec.xField]: x, [spec.yField]: y....
} | ||
} | ||
|
||
// // 归一化每个 label 的 KDE 密度值到 [0, 1] 范围内 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…(in progress)
[中文版模板 / Chinese template]
🤔 This is a ...
🔗 Related issue link
#3574
🔗 Related PR link
🐞 Bugserver case id
💡 Background and solution
初步实现分类背景绘制功能:为了展示机器学习聚类算法的效果,动态显示不同标签的数据点在不同迭代轮次的聚集程度。
创建了 SequenceScatterChartSpecTransformer 类,将特定的序列散点图配置转换为通用的 VChart 配置。
主要包括:
效果展示


图 1 为训练集 1 的效果,图 2 为训练集 2 的效果
未来改进方向
KDE 参数调优: 未来将增加手动调节 bandwidth 的选项(调节核密度估计的平滑程度,bandwith 越高,估计的结果越平滑。每个数据点的影响范围更大,会将更多的邻近点纳入考虑范围),允许用户对 KDE 结果进行更精细的控制。
归一化策略: KDE 密度值的归一化被临时注释,当前的密度值直接映射到透明度。虽然保留了不同 label 间 KDE 值的相对大小关系,但缺乏统一的密度范围,可能导致不同数据集间的密度视觉呈现不一致。需要探索更通用的策略(目前策略是为不同标签的数据统一生成 100*100 = 10000 个图元,因此比较聚集的点的背景显示不出透明度差异,如效果展示中的图 1的紫色分组)。
性能优化: 计划优化 calculateKDE 函数的计算过程,以提高大数据集下的性能。
自定义程度提升: 将提供更多的配置项,允许用户自定义 KDE 密度图的颜色、形状等属性,满足个性化的需求。
📝 Changelog
☑️ Self-Check before Merge
🚀 Summary
copilot:summary
🔍 Walkthrough
copilot:walkthrough