簡體   English   中英

在 Python 中對彼此具有不同線性關系的不同點集進行聚類

[英]Clustering different sets of points with different linear relationships to each other in Python

根據代碼和下圖,我需要對具有相同線性關系的點組進行聚類。

import numpy as np
import matplotlib.pyplot as plt

x  = np.linspace(0, 30, 100)
y1 = 3*x -50 + 20*np.random.random(size=len(x))
y2 = 3*x -20 + 20*np.random.random(size=len(x))
y3 = 3*x +10 + 20*np.random.random(size=len(x))

plt.plot(x, y1, 'o')
plt.plot(x, y2, 'o')
plt.plot(x, y3, 'o')
plt.xlim([-50,125])
plt.ylim([-50,125])

在此處輸入圖像描述

顯然,我不會那樣做。 我只需要以下 x 和 y。

x_final = np.concatenate((x,x,x))
y_final = np.concatenate((y1,y2,y3))

plt.plot(x_final, y_final, 'o')
plt.xlim([-50,125])
plt.ylim([-50,125])

在此處輸入圖像描述

注意以下幾點:這些點尊重高斜率的線性關系,它們之間呈現出輕微的分離,它們都具有相同的斜率,只是截距不同。

你會如何建議我聚集這些點? 我考慮過使用 PCA 並使用 k-means 對主要組件進行聚類,但我不知道是否會有更有效的方法。 在我的真實案例中,我有三個以上的集群,它們之間的距離不同,即使它們都具有相同的斜率。

看看scikit-learn提供的所有聚類算法: 聚類算法。

光譜聚類和高斯混合應該適用於您的用例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM