The project aims to see the mean value of Pokemon attack and defense and also plot a graph between attack and defense
Step: 1
First, we will import the necessary libraries then we upload the dataset
import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt
P = pd.read_csv('Pokemon_A.csv')
P
P.info()
Step: 2
Now we see agglomeration values
Q=P[['Attack','Defence']]
def doAgglomerative(X, nclust=2):
Model = AgglomerativeClustering(n_clusters=nclust,affinity='euclidean',linkage='ward')
Clust_Labels = Model.fit_predict(X)
return (Clust_Labels)
Clust_Labels = doAgglomerative(Q,20)
agglomerative = pd.DataFrame(Clust_Labels)
Q.insert((Q.shape[1]),'agglomerative',agglomerative)
T=Q T['Name']=P['Name'] T
for i in range(20):
names0=T[T['agglomerative']==i]['Name']
print('[ Agglomerative '+str(i)+' ]')
print(list(set(names0)))
print()
Step: 3
Now we calculate the mean value of
Q.groupby('agglomerative').mean()
Step: 4
Now we plot a graph of Agglomerative Clustering between Attack and Defenses
fig = plt.figure()
ax = fig.add_subplot(111)
scatter = ax.scatter(Q['Attack'],Q['Defence'],c=agglomerative[0],s=50)
ax.set_title('Agglomerative Clustering')
ax.set_xlabel('Attack')
ax.set_ylabel('Defence')
plt.rcParams['figure.figsize'] = (6,5)
plt.colorbar(scatter)
Submitted by Sudipta Ghosh (Sudipta609)
Download packets of source code on Coders Packet
Comments