【问题标题】:Best learning algorithms concentric and not linearly separable data最佳学习算法同心且不可线性分离的数据
【发布时间】:2018-09-29 08:44:00
【问题描述】:

下面是两个散点图。第一个是针对具有 x 和 y 值的数据点,我想知道是否有一个聚类算法可以自动识别有两个聚类。它们是同心的并且不是线性可分的。 K-means 不正确有几个原因。另一个图类似,但它有 x、y 和颜色值,我想知道哪种学习算法最适合从 x 和 y 的值中分类或预测正确的颜色。

【问题讨论】:

  • 您可以使用球坐标并应用人工神经网络或任何其他线性技术。
  • 除了 Ahmed 的好评之外,还有一个很好的 overview of scikit-learn。
  • 考虑圆霍夫变换的正常聚类:en.wikipedia.org/wiki/Circle_Hough_Transform
  • k-Nearest Neighbors 对于分类问题值得尝试
  • 感谢到目前为止的答案......但我想我会在这里强调一点,我需要一个算法来自动识别有两个不能线性分离的集群。我绘制的示例显示了两个同心环,但情况可能并非总是如此。使用带有线性回归或圆霍夫变换的极坐标来检测圆对于这个问题来说不够通用。 :)

标签: algorithm machine-learning


【解决方案1】:

我使用 sklearn MLPClassifier 算法得到了很好的分类器结果。这是散点图和等高线图:

详细代码在:https://www.linkedin.com/pulse/couple-scikit-learn-classifiers-peter-thorsteinson。下面的简化代码展示了它是如何工作的:

import math
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.neural_network import MLPClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report, confusion_matrix  

# Generate the artificial data set and display the resulting scatter plot 

x = []
y = []
z = []
for i in range(500):
    rand = np.random.uniform(0.0, 2*math.pi)
    randx = np.random.normal(0.0, 30.0)
    randy = np.random.normal(0.0, 30.0)
    if np.random.random() > 0.5:
        z.append(0)
        x.append(100*math.cos(rand) + randx)
        y.append(100*math.sin(rand) + randy)
    else:
        z.append(1)
        x.append(300*math.cos(rand) + randx)
        y.append(300*math.sin(rand) + randy)

plt.axis('equal')
plt.axis([-500, 500, -500, 500])
plt.scatter(x, y, c=z)
plt.show()

# Run the MLPClassifier algorithm on the training data

XY = pd.DataFrame({'x': x, 'y': y})
print(XY.head())
Z = pd.DataFrame({'z': z})
print(Z.head())
XY_train, XY_test, Z_train, Z_test = train_test_split(XY, Z, test_size = 0.20)
mlp = MLPClassifier(hidden_layer_sizes=(10, 10, 10), max_iter=1000)
mlp.fit(XY_train, Z_train.values.ravel())

# Make predictions on the test data and display resulting scatter plot

predictions = mlp.predict(XY_test)

print(confusion_matrix(Z_test,predictions))  
print(classification_report(Z_test,predictions))

plt.axis('equal')
plt.axis([-500, 500, -500, 500])
plt.scatter(XY_test.x, XY_test.y, c=predictions)
plt.show()

【讨论】:

    猜你喜欢
    • 2021-10-19
    • 2014-01-29
    • 2018-06-10
    • 1970-01-01
    • 2013-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多