最佳学习算法用于同心且非线性可分数据

以下是两个散点图。第一个图表展示了具有x和y值的数据点,我想知道是否存在一种聚类算法能够自动识别出存在两个聚类。这些聚类是同心的且非线性可分的。K-means算法在几方面不适合。另一个图表类似,但它包含x、y和颜色值,我想知道哪种学习算法最适合根据x和y的值来分类或预测正确的颜色。enter image description here


回答:

我使用sklearn的MLPClassifier算法在这个问题上获得了很好的分类结果。以下是散点图和等高线图:

enter image description here

详细代码请见: https://www.linkedin.com/pulse/couple-scikit-learn-classifiers-peter-thorsteinson。下面的简化代码展示了它的工作原理:

import mathimport numpy as npimport matplotlib.pyplot as pltimport pandas as pdfrom sklearn.neural_network import MLPClassifierfrom sklearn.model_selection import train_test_splitfrom sklearn.metrics import classification_report, confusion_matrix  # 生成人工数据集并显示生成的散点图 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()# 在训练数据上运行MLPClassifier算法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())# 在测试数据上进行预测并显示生成的散点图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()

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注