# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/parul21/data_analytics/blob/master/Ex6B_mds_eign_inbuilt.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + id="H0vxTsY2PoRY" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 269} outputId="0bfafda8-5368-4544-ebd1-25d77a6b2bca"
import pandas as pd
import numpy as np
from sklearn import manifold
import matplotlib.pyplot as plt

X = [[1,1],[2,1],[2,2],[3,2]]
X=np.array(X)
plt.scatter(X[:,0],X[:,1])
plt.show()

# + id="xXrF7ik5PvEZ" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 90} outputId="a57b489e-8a8b-4c8e-b2f3-78d7f6082d12"
from sklearn.metrics.pairwise import euclidean_distances
euc_dis_original=euclidean_distances(X, X)
print(euc_dis_original)

# + id="C_3lGzePPzyb" colab_type="code" colab={}
mds = manifold.MDS(n_components=2, dissimilarity="euclidean", n_init=100, max_iter=1000, random_state=10)

results = mds.fit(X)

# + id="KHBRllgjP-0j" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 685} outputId="234a6954-72a1-4db9-f657-ddcb283161bc"
coords = results.embedding_
euc_dis_mod=euclidean_distances(coords, coords)
print(euc_dis_mod)
fig = plt.figure(figsize=(12,10))

plt.subplots_adjust(bottom = 0.1)
plt.scatter(coords[:, 0], coords[:, 1])


plt.show()

# + id="VqYSp4zYQBBb" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 269} outputId="9a2e8e59-81e5-47e0-986e-a8e35e370aa9"
plt.scatter(euc_dis_original, euc_dis_mod)
plt.show()

# + id="9sLu8amtQJo5" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 269} outputId="c900491f-c7db-4c79-d84e-1651e4ed3b14"
plt.plot(euc_dis_original, euc_dis_mod)
plt.show()

# + id="XaH1K6ppQQZw" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 90} outputId="51cc25e5-6fe1-46a1-d019-8142d6562206"
print(euc_dis_original-euc_dis_mod)

StarcoderdataJupyterScriptsDedupFiltered