Python - Dimension Reduction – Self Organizing Maps (SOM)
Data:
Employees when they sent job applicant (40 rows)
Mission:
How to visualize data mapping using SOM algorithm
Library used:
Pandas
Scikit
SimpSOM
Code:
import pandas as pd
from sklearn.preprocessing import StandardScaler
!pip install SimpSOM
import SimpSOM as sps
url = 'https://raw.githubusercontent.com/kokocamp/vlog119/main/vlog119.csv'
vlog139 = pd.read_csv(url)
X = vlog139[['gpa','gmat','work_experience','admitted']]
y = vlog139['admitted']
scaler = StandardScaler()
data = scaler.fit_transform(pd.DataFrame(X))
labels = scaler.fit_transform(pd.DataFrame(y))
print(data)
net = sps.somNet(50, 50, data)
#Train the network for 10000 epochs and with initial learning rate of 0.1.
net.train(0.01, 1000)
#Print a map of the network nodes and colour them according to the first feature (column number 0) of the dataset
#and then according to the distance between each node and its neighbours.
net.nodes_graph()
net.diff_graph()
#Project the datapoints on the new 2D network map.
net.project(data, labels=labels)
#Cluster the datapoints according to the Quality Threshold algorithm.
net.cluster(data)
I wrapped the scenario in a Youtube video below.
Click this link (http://paparadit.blogspot.com/2020/11/the-algorithms-of-machine-learning.html), if you want to check out for other algorithms. Thank you for for visiting this blog & subs my channel.
Labels: Programming, Python
PS: If you've benefit from this blog, you can support it by making a small contribution. |
Post a Comment
Leave comments here...