if np.any(all_compare[i]<0): kmeans_best_1se.append( np.min(np.arange(1,10)[all_compare[i]<0]) ) kmeans_best_gap.append( np.arange(1,11)[np.max(all_gaps[i])==all_gaps[i]][0]) else: kmeans_best_1se.append( 1 ) kmeans_best_gap.append( np.arange(1,11)[np.max(all_gaps[i])==all_gaps[i]][0]) sns.set_style("white") fig = plt.figure() # gaussian ax1 = fig.add_subplot(321,projection='3d') kmean = sklearn.cluster.KMeans(kmeans_best_1se[0]) _ = three_d_cluster(X_used,predictions=kmean.fit_predict(X_used),fig_to_continue = ax1) ax1.set_title(null_names[0]+" 1se best comparison "+str(kmeans_best_1se[0])+" clusters") ax2 = fig.add_subplot(322,projection='3d') kmean = sklearn.cluster.KMeans(kmeans_best_gap[0]) _ = three_d_cluster(X_used,predictions=kmean.fit_predict(X_used),fig_to_continue = ax2) ax2.set_title(null_names[0]+" best gap "+str(kmeans_best_gap[0])+" clusters") # uniform ax3 = fig.add_subplot(323,projection='3d') kmean = sklearn.cluster.KMeans(kmeans_best_1se[1]) _ = three_d_cluster(X_used,predictions=kmean.fit_predict(X_used),fig_to_continue = ax3) ax3.set_title(null_names[1]+" 1se best comparison "+str(kmeans_best_1se[1])+" clusters") ax4 = fig.add_subplot(324,projection='3d') kmean = sklearn.cluster.KMeans(kmeans_best_gap[1])
from visuals_functions import three_d_cluster,pair_plot_funct rot_elev=[(76,30),(103,24),(113,24),(46,24),(145,12)] sns.set_style("white") for i in np.arange(2,7): kmean = sklearn.cluster.KMeans(i) pred = kmean.fit_predict(X_used) fig1 = plt.figure() ax1 = fig1.add_subplot(111,projection='3d') three_d_cluster(X_used[:,-3:],rotation_angle=rot_elev[i-2][0], elevation=rot_elev[i-2][1],predictions=pred,type_marker="numeric", fig_to_continue =ax1) plt.savefig(images+"/presentation/"+data_info+"_"+str(i)+"_clusters3d.png") plt.close() # pairs plot: pairplotsX = pd.concat([pd.DataFrame(X_used),pd.DataFrame(pred)],axis=1) pairplotsX.columns = ["x"+str(i) for i in range(X_used.shape[-1])]+["prediction"] pair_plot_funct(pairplotsX,save=False) plt.savefig(images+"/presentation/"+data_info+"_"+str(i)+"_clusters_pairs.png") plt.close()