I have to do spectral clustering on moons shaped dataset and then have to create a graph showing the links between data points.
This is my code
import numpy as np
import os
from sklearn import metrics
from sklearn.cluster import SpectralClustering
from sklearn.neighbors import DistanceMetric
from sklearn.cluster import KMeans
import pandas as pd
import pylab as pl
import sklearn.metrics as sm
from sklearn.metrics import confusion_matrix,classification_report
from sklearn.preprocessing import MinMaxScaler
from sklearn.datasets import make_moons
import matplotlib.pyplot as plt
import networkx as nx
X, y = make_moons(n_samples=20)
print(X)
clustering=SpectralClustering(n_clusters=2,
assign_labels='kmeans',affinity='rbf',gamma=10, degree=3,
random_state=0)
y_predict=clustering.fit_predict(X)
y_predict_labels = clustering.labels_
clustering.affinity_matrix_
I have got the nodes as data points and the affinity matrix as the weight over the edges. Can someone help me to create a graph using nearest neighbors=2 in the shape of two moons(as my dataset is of two moons) using data points as nodes and affinity matrix as edges between the nodes.