# -*- coding: utf-8 -*-
"""spectral_clustering.ipynb

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1Xut1VyJXD81WzKpWHXALpezkQFlxHZEk
"""

# Import Libraries
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_moons
from sklearn.cluster import SpectralClustering

# Create non-linear dataset (300 points, slight noise)
X, _ = make_moons(n_samples=300, noise=0.05)

plt.scatter(X[:, 0], X[:, 1]) # Plot data points
plt.title("Original Data") # Add title
plt.show() # Display Plot

# Initialize Spectral Clustering model
model = SpectralClustering(
    n_clusters=2,
    affinity='nearest_neighbors',
    n_neighbors=15
)

# Fit model and assign cluster labels
labels = model.fit_predict(X)

# Plot Clustered Structure
plt.scatter(X[:, 0], X[:, 1], c=labels, cmap='Set1')
plt.title("Spectral Clustering")
plt.show()

# Apply K-Means for comparison
from sklearn.cluster import KMeans

kmeans = KMeans(n_clusters=2, random_state=42)
k_labels = kmeans.fit_predict(X)

# Plot Spectral vs K-Means side by side
plt.figure(figsize=(10,4))

plt.subplot(1,2,1)
plt.scatter(X[:, 0], X[:, 1], c=labels, cmap='Set1')
plt.title("Spectral Clustering")

plt.subplot(1,2,2)
plt.scatter(X[:, 0], X[:, 1], c=k_labels, cmap='Set1')
plt.title("K-Means Clustering")

plt.show() # Display comparison

import random
import matplotlib.pyplot as plt

employees_needed = []

for _ in range(1000):
    customers = random.randint(20, 100)

    # time taken per pizza (in minutes)
    prep_time = random.randint(5, 10)

    # total work (in minutes)
    total_work = customers * prep_time

    # each employee works 60 minutes
    employees = total_work // 60 + 1

    employees_needed.append(employees)

plt.hist(employees_needed, bins=8, edgecolor='black')
plt.xlabel("Employees Needed")
plt.ylabel("No. of Simulations")
plt.title("Pizza Restaurant Simulation")

plt.show()