From 8ff2c2f0c054fcb511143ac7d8c1563decc9efb6 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Wed, 26 May 2021 07:41:32 +0000 Subject: [PATCH] Added Clustering.py moved kmeans from Analysis to Clustering --- analysis-master/tra_analysis/Analysis.py | 4 +-- analysis-master/tra_analysis/Clustering.py | 30 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 analysis-master/tra_analysis/Clustering.py diff --git a/analysis-master/tra_analysis/Analysis.py b/analysis-master/tra_analysis/Analysis.py index 6a8a63b3..df81951c 100644 --- a/analysis-master/tra_analysis/Analysis.py +++ b/analysis-master/tra_analysis/Analysis.py @@ -599,7 +599,7 @@ def npmin(data): def npmax(data): return np.amax(data) - +""" need to decide what to do with this function def kmeans(data, n_clusters=8, init="k-means++", n_init=10, max_iter=300, tol=0.0001, precompute_distances="auto", verbose=0, random_state=None, copy_x=True, n_jobs=None, algorithm="auto"): kernel = sklearn.cluster.KMeans(n_clusters = n_clusters, init = init, n_init = n_init, max_iter = max_iter, tol = tol, precompute_distances = precompute_distances, verbose = verbose, random_state = random_state, copy_x = copy_x, n_jobs = n_jobs, algorithm = algorithm) @@ -608,7 +608,7 @@ def kmeans(data, n_clusters=8, init="k-means++", n_init=10, max_iter=300, tol=0. centers = kernel.cluster_centers_ return centers, predictions - +""" def pca(data, n_components = None, copy = True, whiten = False, svd_solver = "auto", tol = 0.0, iterated_power = "auto", random_state = None): kernel = sklearn.decomposition.PCA(n_components = n_components, copy = copy, whiten = whiten, svd_solver = svd_solver, tol = tol, iterated_power = iterated_power, random_state = random_state) diff --git a/analysis-master/tra_analysis/Clustering.py b/analysis-master/tra_analysis/Clustering.py new file mode 100644 index 00000000..35988715 --- /dev/null +++ b/analysis-master/tra_analysis/Clustering.py @@ -0,0 +1,30 @@ +# Titan Robotics Team 2022: Clustering submodule +# Written by Arthur Lu +# Notes: +# this should be imported as a python module using 'from tra_analysis import Clustering' +# setup: + +__version__ = "1.0.0" + +# changelog should be viewed using print(analysis.__changelog__) +__changelog__ = """changelog: + 1.0.0: + - created this submodule + - copied kmeans clustering from Analysis +""" + +__author__ = ( + "Arthur Lu ", +) + +__all__ = [ +] + +def kmeans(data, n_clusters=8, init="k-means++", n_init=10, max_iter=300, tol=0.0001, precompute_distances="auto", verbose=0, random_state=None, copy_x=True, n_jobs=None, algorithm="auto"): + + kernel = sklearn.cluster.KMeans(n_clusters = n_clusters, init = init, n_init = n_init, max_iter = max_iter, tol = tol, precompute_distances = precompute_distances, verbose = verbose, random_state = random_state, copy_x = copy_x, n_jobs = n_jobs, algorithm = algorithm) + kernel.fit(data) + predictions = kernel.predict(data) + centers = kernel.cluster_centers_ + + return centers, predictions \ No newline at end of file