3000 explained code solutions for 75 technologies


python-scikit-learnUsing dbscan clustering example


from sklearn import datasets, cluster

X, y = datasets.load_iris(return_X_y=True)
model = cluster.DBSCAN()

clusters = model.fit_predict(X)ctrl + c
from sklearn import

import module from scikit-learn

load_iris

loads Iris dataset

.DBSCAN(

creates DBSCAN model

.fit_predict(

trains model and returns predicted cluster labels


Usage example

from sklearn import datasets, cluster

X, y = datasets.load_iris(return_X_y=True)
model = cluster.DBSCAN()

clusters = model.fit_predict(X)
print(clusters)
output
[ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 -1  0  0  0  0  0  0
  0  0  1  1  1  1  1  1  1 -1  1  1 -1  1  1  1  1  1  1  1 -1  1  1  1
  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1 -1  1  1  1  1  1 -1  1  1
  1  1 -1  1  1  1  1  1  1 -1 -1  1 -1 -1  1  1  1  1  1  1  1 -1 -1  1
  1  1 -1  1  1  1  1  1  1  1  1 -1  1  1 -1 -1  1  1  1  1  1  1  1  1
  1  1  1  1  1  1]