【发布时间】:2016-11-02 20:27:46
【问题描述】:
我有以下列表,我想对其执行无监督学习并使用这些知识来预测测试列表中每个项目的值
#Format [real_runtime, processors, requested_time, score, more_to_be_added]
#some entries from the list
训练数据集
Xsrc = [['354', '2048', '3600', '53.0521472395'],
['605', '2048', '600', '54.8768871369'],
['128', '2048', '600', '51.0'],
['136', '2048', '900', '51.0000000563'],
['19218', '480', '21600', '51.0'],
['15884', '2048', '18000', '51.0'],
['118', '2048', '1500', '51.0'],
['103', '2048', '2100', '51.0000002839'],
['18542', '480', '21600', '51.0000000001'],
['13272', '2048', '18000', '51.0000000001']]
测试数据集
使用集群我想预测一个新列表的 real_runtime: Xtest= [['-1', '2048', '1500', '51.0000000161'], ['-1', '2048', '10800', '51.0000000002'], ['-1', '512', '21600', '-1'], ['-1', '512', '2700', '51.0000000004'], ['-1, '1024', '21600', '51.1042617556']]
代码:在 python 中使用 scikit 格式化列表并制作集群并绘制集群
from sklearn.feature_selection import VarianceThreshold
import numpy as np
from sklearn.cluster import DBSCAN
from sklearn import metrics
from sklearn.datasets.samples_generator import make_blobs
from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt
##Training dataset
Xsrc = [['354', '2048', '3600', '53.0521472395'],
['605', '2048', '600', '54.8768871369'],
['128', '2048', '600', '51.0'],
['136', '2048', '900', '51.0000000563'],
['19218', '480', '21600', '51.0'],
['15884', '2048', '18000', '51.0'],
['118', '2048', '1500', '51.0'],
['103', '2048', '2100', '51.0000002839'],
['18542', '480', '21600', '51.0000000001'],
['13272', '2048', '18000', '51.0000000001']]
print "Xsrc:", Xsrc
##Test data set
Xtest= [['1224', '2048', '1500', '51.0000000161'],
['7867', '2048', '10800', '51.0000000002'],
['21594', '512', '21600', '-1'],
['1760', '512', '2700', '51.0000000004'],
['115', '1024', '21600', '51.1042617556']]
##Clustering
X = StandardScaler().fit_transform(Xsrc)
db = DBSCAN(min_samples=2).fit(X) #no clustering parameter, such as default eps
core_samples_mask = np.zeros_like(db.labels_, dtype=bool)
core_samples_mask[db.core_sample_indices_] = True
labels = db.labels_
n_clusters_ = len(set(labels)) - (1 if -1 in labels else 0)
clusters = [X[labels == i] for i in xrange(n_clusters_)]
print('Estimated number of clusters: %d' % n_clusters_)
print("Silhouette Coefficient: %0.3f" % metrics.silhouette_score(X, labels))
##Plotting the dataset
unique_labels = set(labels)
colors = plt.cm.Spectral(np.linspace(0, 1, len(unique_labels)))
for k, col in zip(unique_labels, colors):
if k == -1:
# Black used for noise.
col = 'k'
class_member_mask = (labels == k)
xy = X[class_member_mask & core_samples_mask]
plt.plot(xy[:, 0], xy[:, 1], 'o', markerfacecolor=col,
markeredgecolor='k', markersize=20)
xy = X[class_member_mask & ~core_samples_mask]
plt.plot(xy[:, 0], xy[:, 1], 'o', markerfacecolor=col,
markeredgecolor='k', markersize=10)
plt.title('Estimated number of clusters: %d' % n_clusters_)
plt.show()
有什么想法可以使用集群来预测值吗?
【问题讨论】:
-
你为什么要聚类,而不是做一个简单的多元回归?
-
正如 Prune 已经建议的那样 - 首先进行集群是没有意义的。这样做的唯一原因是因为您知道以后如何使用它,并且不做 不起作用。一般来说 - 这不是你应该解决问题的方式,从最简单的解决方案开始,如果它们失败了 - 寻找一些更复杂的解决方案。
-
最初的想法是从数百条记录中学习,并使用这些知识来预测下一条的一个属性。他们之所以我考虑聚类是因为新记录(预测)将与迄今为止学习(处理)的一些记录有相似之处,而不是全部。
标签: python machine-learning scikit-learn dbscan unsupervised-learning