You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已知层级数量的一维单属性传感器数据层级识别

Got it, let's tackle this one. You've got a single-value sensor dataset and know exactly how many levels (5 in your example) you need to split it into—here's a practical, step-by-step approach to do that without needing prior info on sample counts per level:

一维传感器数据层级识别方案(已知层级数量)

方法1:K-Means聚类(最适配已知层级数的方案)

K-Means was built for scenarios where you know the exact number of clusters (or levels, in your case). It works purely off the data's distribution, so you don't need any pre-existing info on how many samples per level. Here's how to implement it:

  • First, convert your 1D data into a 2D array format (most K-Means libraries expect this—just wrap each value in a list, e.g., [x] instead of x)
  • Initialize the K-Means model with n_clusters=5 (matching your 5-level requirement)
  • After fitting the model, every sample gets a cluster label—samples with the same label belong to the same level
  • Optional: Sort the cluster centers to get a clear low-to-high order of your levels

Here's a Python example using scikit-learn:

import numpy as np
from sklearn.cluster import KMeans

# Your sample sensor data
sensor_data = np.array([199, 200, 205, 209, 217, 224, 239, 498, 573, 583, 583, 590, 591, 594, 703, 710, 711, 717, 719, 721, 836, 840, 845, 849, 855, 855, 856, 857, 858, 858, 928, 935, 936, 936, 942, 943, 964, 977]).reshape(-1, 1)

# Initialize K-Means with 5 clusters
kmeans_model = KMeans(n_clusters=5, random_state=42)
level_labels = kmeans_model.fit_predict(sensor_data)

# Print labels for each sample (0-4 correspond to your 5 levels)
print("Sample-level assignments:", level_labels)
# Sort cluster centers to get a clear low-to-high level order
sorted_centers = sorted(kmeans_model.cluster_centers_.flatten())
print("Low-to-high level center values:", sorted_centers)

方法2:突变点检测+层级划分(贴合传感器阶跃特性)

Looking at your sample data, there are clear jumps between levels (like 239 → 498 or 594 → 703). For this kind of step-change sensor data, you can find these breakpoints first, then split into the required 5 levels:

  • Calculate the difference between each adjacent pair of data points
  • Pick the top 4 largest difference positions (since 5 levels need 4 split points)
  • Use these positions to slice your original data into 5 distinct groups

Here's a Python example for this approach:

import numpy as np

sensor_data = [199, 200, 205, 209, 217, 224, 239, 498, 573, 583, 583, 590, 591, 594, 703, 710, 711, 717, 719, 721, 836, 840, 845, 849, 855, 855, 856, 857, 858, 858, 928, 935, 936, 936, 942, 943, 964, 977]

# Calculate differences between consecutive samples
diffs = [sensor_data[i+1] - sensor_data[i] for i in range(len(sensor_data)-1)]
# Get indices of the 4 largest differences (our split points)
top_diff_indices = sorted(np.argsort(diffs)[-4:])

# Split data into levels
levels = []
start_idx = 0
for split_idx in top_diff_indices:
    levels.append(sensor_data[start_idx:split_idx+1])
    start_idx = split_idx + 1
levels.append(sensor_data[start_idx:])

# Print each level
for num, level in enumerate(levels, 1):
    print(f"Level {num} data: {level}")

Quick Notes

  • If your sensor data has gradual transitions instead of sharp jumps, stick with K-Means—mutation point detection might misidentify splits
  • For K-Means, set random_state to get reproducible results (no random label shuffling between runs)
  • You can always sort the resulting levels by their average/center value to align with a logical low-to-high order

内容的提问来源于stack exchange,提问作者asker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:05:41