Spectral
- class geoanalytics.clustering.Spectral.Spectral(dataframe)[source]
Bases:
objectAbout this algorithm
- Description:
Spectral Clustering uses graph-based methods to cluster points based on the eigenvalues of a similarity matrix. It’s particularly effective for complex cluster shapes that traditional methods like KMeans may not detect.
- Parameters:
dataframe (pd.DataFrame) – Input dataset where the first two columns are assumed to be spatial (‘x’, ‘y’) and all remaining columns are used for clustering.
- Attributes:
df (pd.DataFrame) – Cleaned and formatted input data.
labelsDF (pd.DataFrame) – Output containing ‘x’, ‘y’, and assigned cluster labels.
Execution methods
import pandas as pd from goeAnalytics.clustering import Spectral df = pd.read_csv("data.csv") obj = Spectral(df) obj.clustering(n_clusters=4) labels_df = output[0] obj.save(outputFile="SpectralLabels.csv")
Credits
This implementation was created and revised under the guidance of Professor Rage Uday Kiran.
- getMemoryRSS()[source]
Prints the memory usage (RSS) of the process in kilobytes.
- getMemoryUSS()[source]
Prints the memory usage (USS) of the process in kilobytes.
- getRuntime()[source]
Prints the total runtime of the clustering algorithm.
- run(n_clusters=8, assign_labels='discretize')[source]
Applies Spectral Clustering to the dataset.
- Parameters:
n_clusters – Number of clusters to form.
assign_labels – Method for assigning labels after clustering (‘kmeans’ or ‘discretize’).
- Returns:
A DataFrame containing x, y, and assigned labels.
- save(outputFile='SpectralLabels.csv')[source]
Saves the clustering results to a CSV file.
- Parameters:
outputFile – Filename to save the resulting DataFrame.