Skip to content

Instantly share code, notes, and snippets.

@theibrr
theibrr / mds.py
Created October 12, 2021 21:11
MDS
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(
@theibrr
theibrr / mds.py
Created October 12, 2021 21:08
MDS
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)
@theibrr
theibrr / mds.py
Created October 12, 2021 21:03
MDS
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],
@theibrr
theibrr / Configure a CNN Model using Traditional Machine Learning Algorithms.ipynb
Created September 29, 2021 15:14
Configure a CNN Model using Traditional Machine Learning Algorithms
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@theibrr
theibrr / Configure a CNN Model using Traditional Machine Learning Algorithms.ipynb
Created September 29, 2021 15:11
Configure a CNN Model using Traditional Machine Learning Algorithms
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@theibrr
theibrr / Configure a CNN Model using Traditional Machine Learning Algorithms.py
Last active September 29, 2021 13:07
Configure a CNN Model using Traditional Machine Learning Algorithms
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
@theibrr
theibrr / birthday.py
Created September 14, 2021 12:36
birthday
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))
@theibrr
theibrr / cluster.py
Created September 8, 2021 22:43
Enlightening on Clustering types with various applications
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']
@theibrr
theibrr / cluster.py
Created September 8, 2021 22:10
Enlightening on Clustering types with various applications
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)
@theibrr
theibrr / cluster.py
Created September 8, 2021 21:17
Enlightening on Clustering types with various applications
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)