From 4614d57c13fca62321a7473300d9ab9ff23feff2 Mon Sep 17 00:00:00 2001 From: Lance Galletti Date: Wed, 9 Feb 2022 15:35:19 -0500 Subject: [PATCH] Updating: adding dbscan --- 04-dbscan/README.md | 5 +++++ 04-dbscan/main.py | 18 ++++++++++++++++++ 04-dbscan/requirements.txt | 11 +++++++++++ 3 files changed, 34 insertions(+) create mode 100644 04-dbscan/README.md create mode 100644 04-dbscan/main.py create mode 100644 04-dbscan/requirements.txt diff --git a/04-dbscan/README.md b/04-dbscan/README.md new file mode 100644 index 0000000..821846b --- /dev/null +++ b/04-dbscan/README.md @@ -0,0 +1,5 @@ +# DBScan + +We will implement DBScan together in class + +In addition to the requirements.txt, you need to install the `cs506` python package from [02-library](../02-library/). \ No newline at end of file diff --git a/04-dbscan/main.py b/04-dbscan/main.py new file mode 100644 index 0000000..27c89a6 --- /dev/null +++ b/04-dbscan/main.py @@ -0,0 +1,18 @@ +import numpy as np +import matplotlib.pyplot as plt +import sklearn.datasets as datasets +from sklearn.preprocessing import StandardScaler + +from cs506 import dbscan + +centers = [[1, 1], [-1, -1], [1, -1]] +X, _ = datasets.make_blobs(n_samples=750, centers=centers, cluster_std=0.4, + random_state=0) +plt.scatter(X[:,0],X[:,1],s=10, alpha=0.8) +plt.show() + +clustering = dbscan.DBC(X, 3, .2).dbscan() +colors = np.array([x for x in 'bgrcmykbgrcmykbgrcmykbgrcmyk']) +colors = np.hstack([colors] * 20) +plt.scatter(X[:, 0], X[:, 1], color=colors[clustering].tolist(), s=10, alpha=0.8) +plt.show() diff --git a/04-dbscan/requirements.txt b/04-dbscan/requirements.txt new file mode 100644 index 0000000..51dd1fe --- /dev/null +++ b/04-dbscan/requirements.txt @@ -0,0 +1,11 @@ +cycler==0.10.0 +joblib==0.14.0 +kiwisolver==1.1.0 +matplotlib==3.1.1 +numpy==1.17.4 +pyparsing==2.4.5 +python-dateutil==2.8.1 +scikit-learn==0.21.3 +scipy==1.3.2 +six==1.13.0 +sklearn==0.0