【发布时间】:2019-08-20 18:46:33
【问题描述】:
提出的问题如下:使用 scikit-learn 将数据拆分为训练集和测试集。使用 DBSCAN 将数据分类为猫或狗。
我试图弄清楚如何使用 DBSCAN 来拟合使用训练数据的模型,然后预测测试集的标签。我很清楚 DBSCAN 用于聚类而不是预测。我还查看了Use sklearn DBSCAN model to classify new entries 以及许多其他线程。 DBSCAN 只带有 fit 和 fit_predict 函数,在尝试使用训练数据拟合模型然后使用测试数据测试模型时,这似乎不太有用。
问题是措辞不当还是我遗漏了什么?我查看了 scikit-learn 文档以及寻找示例,但没有任何运气。
# Split the samples into two subsets, use one for training and the other for testing
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
# Instantiate the learning model
dbscan = DBSCAN()
# Fit the model
dbscan.fit(X_train, y_train)
# Predict the response
# Confusion matrix and quantitative metrics
print("The confusion matrix is: " + np.str(confusion_matrix(y_test, dbscan_pred)))
print("The accuracy score is: " + np.str(accuracy_score(y_test, dbscan_pred)))
【问题讨论】:
-
实际上是 Use sklearn DBSCAN model to classify new entries 的复制品,因为只有当您可以预测新数据上的学习标签时,训练/测试拆分才有意义。
标签: machine-learning scikit-learn cluster-analysis data-mining dbscan