This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from sklearn.decomposition import PCA | |
| pca = PCA(n_components=2) | |
| x_pca = pca.fit_transform(x_scaled) | |
| cities = ['Istanbul','Ankara','Izmir','Denizli','Antalya','Erzurum'] | |
| plt.figure(figsize=(10,6)) | |
| plt.scatter(x_pca[:,0],x_pca[:,1]) | |
| plt.title('PCA') | |
| for label, x, y in zip(cities, x_pca[:, 0], x_pca[:, 1]): | |
| plt.annotate( | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from sklearn.manifold import MDS | |
| stress = [] | |
| for i in range(1, 5): | |
| mds_sklearn = MDS(n_components=i) | |
| # Apply MDS | |
| pts = mds_sklearn.fit_transform(x_scaled) | |
| # Retrieve the stress value | |
| stress.append(mds_sklearn.stress_) | |
| # Plot stress vs. n_components | |
| plt.plot(range(1, 5), stress) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import numpy as np | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| cities = {'Istanbul':[0,350,329,360,483,1048], | |
| 'Ankara':[350,0,522,405,387,719], | |
| 'Izmir':[329,522,0,186,359,1231], | |
| 'Denizli':[360,405,186,0,174,1082], | |
| 'Antalya':[483,387,359,174,0,981], | |
| 'Erzurum':[1048,719,1231,1082,981,0], | 
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
      
      Loading
      
  Sorry, something went wrong. Reload?
      Sorry, we cannot display this file.
      Sorry, this file is invalid so it cannot be displayed.
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import cv2 | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| img = cv2.imread(r'image.jpg',0) | |
| def gradient(m,n): | |
| kernel = np.ones((m,n),np.uint8) | |
| gradient = cv2.morphologyEx(img, cv2.MORPH_GRADIENT, kernel) | |
| return gradient | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import random | |
| import time | |
| import collections | |
| import pandas as pd | |
| def str_time_prop(start, end, time_format, prop): | |
| stime = time.mktime(time.strptime(start, time_format)) | |
| etime = time.mktime(time.strptime(end, time_format)) | |
| ptime = stime + prop * (etime - stime) | |
| return time.strftime(time_format, time.localtime(ptime)) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from sklearn.mixture import GaussianMixture | |
| import numpy as np | |
| import cv2 | |
| import matplotlib.pyplot as plt | |
| bic_total = [] | |
| cov_total = [] | |
| K=[2,3,4,5] | |
| cv_types = ['spherical', 'tied', 'diag', 'full'] | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from sklearn.mixture import GaussianMixture | |
| import numpy as np | |
| import cv2 | |
| import matplotlib.pyplot as plt | |
| img = cv2.imread(r'C:\Users\ibrah\OneDrive\Pictures\Medium\Machine Learning\unsupervised learning/flower.png') | |
| img = np.array(img) | |
| img2 = img.reshape((-1,3)) | |
| img2 = np.float32(img2) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from sklearn.tree import DecisionTreeClassifier | |
| from sklearn.model_selection import train_test_split | |
| from sklearn.datasets import load_digits | |
| from sklearn.cluster import KMeans | |
| data= load_digits() | |
| x = data.data | |
| y = data.target | |
| x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2,random_state=2021) |