Skip to content

Instantly share code, notes, and snippets.

@FFroehlich
Created July 29, 2016 01:07
Show Gist options
  • Save FFroehlich/2689ef78284d91c245bb1f8d9ede30ca to your computer and use it in GitHub Desktop.
Save FFroehlich/2689ef78284d91c245bb1f8d9ede30ca to your computer and use it in GitHub Desktop.
% this .csv was exported from pokeminer
T = readtable('./pokeloc.csv');
spawnpoints = T{:,[6,7]};
spawnpoints = unique(spawnpoints,'rows');
spawnrates = zeros([size(spawnpoints,1),150]);
spawnnumber = zeros([size(spawnpoints,1),1]);
for ispawn = 1:size(spawnpoints,1)
ispawn
idx = sum(repmat(spawnpoints(ispawn,:),[size(T,1),1])==T{:,[6,7]},2)==2;
spawnnumber(ispawn) = sum(idx);
for jspawn = find(idx)'
spawnrates(ispawn,T{jspawn,2}) = spawnrates(ispawn,T{jspawn,2}) + 1/spawnnumber(ispawn);
end
end
%%
idx = spawnnumber>40;
pcs = 4;
ncluster = 4;
[coeff1, score1,latent,tsquared,explained,mu1] = pca(spawnrates);
[IDX,C] = kmeans(score1(:,1:pcs),ncluster);
cmap = lines(7);
cmap(4,:) = cmap(1,:);
cmap(1,:) = cmap(5,:);
clear I
for idx = unique(IDX)';
I(idx,:) = IDX == idx;
hold on
end
%%
clusters = {'bugs','thrash','parks/nests/rare','river','','','',''};
figure
hold on
for idx = unique(IDX)'
plot3(score1(I(idx,:),1),score1(I(idx,:),2),score1(I(idx,:),3),'o','Color',cmap(idx,:))
end
xlabel('pc1')
ylabel('pc2')
zlabel('pc3')
box on
legend(clusters)
figure
hold on
for idx = unique(IDX)'
plot3(score1(I(idx,:),1),score1(I(idx,:),2),score1(I(idx,:),4),'o','Color',cmap(idx,:))
end
legend(clusters)
figure
hold on
for idx = unique(IDX)'
plot3(score1(I(idx,:),1),score1(I(idx,:),3),score1(I(idx,:),4),'o','Color',cmap(idx,:))
end
legend(clusters)
figure
hold on
for idx = unique(IDX)'
plot3(score1(I(idx,:),2),score1(I(idx,:),3),score1(I(idx,:),4),'o','Color',cmap(idx,:))
end
legend(clusters)
figure
gscatter(spawnpoints(:,2),spawnpoints(:,1),IDX,cmap)
legend(clusters)
t = C*coeff1(:,[1:4])' + repmat(mu1,size(C,1),1);
%%
% this is the pokemon.json for pokemon names
pokedex = loadjson('./pokemon.json');
fid = fopen('clusteranalysis.txt','w');
for iclust = 1:ncluster
fprintf(fid,['cluster ' num2str(iclust) ': ' clusters{iclust} ' (' num2str(sum(IDX==iclust)/length(IDX)*100,'%0.1f') '%%)\n']);
pidx = find(t(iclust,:)>0.01);
for ipoke = pidx
fprintf(fid,[pokedex{ipoke}.Name ': ' num2str(t(iclust,ipoke)*100,'%0.1f') '%%\n']);
end
fprintf(fid,['other: ' num2str((1-sum(t(iclust,pidx)))*100,'%0.1f') '%%\n\n\n']);
end
fclose(fid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment