Question: Im doing some analytics using python 3.5 and anaconda. in K means Clustering python will not recognise ggplot, even after importing. any alternatives to ggplot?

Im doing some analytics using python 3.5 and anaconda.

in K means Clustering python will not recognise ggplot, even after importing.

any alternatives to ggplot?

this is my code

import pandas as pd import numpy as np from sklearn.cluster import KMeans from sklearn.decomposition import PCA from ggplot import aes from ggplot import *

data = pd.read_csv(r'C:\Users\user\Anaconda3\envs\assign\land-area-population-density-london.csv') data.columns = ["Codes","Ward names" ,"Borough", "Hectares", "Square Kilometres", "Population 2015", "Population per hectare 2015", "Population per square kilometre 2015", "Census population(2011)", "Population per hectare 2011"]

#creating a matrix table

matrix = data.pivot_table(index=['Ward names'], columns=['Borough','Population per hectare 2015', 'Population per hectare 2011']) print(matrix)

matrix = matrix.fillna(0).reset_index() x_cols = matrix.columns[1:]

cluster = KMeans(n_clusters=5)

matrix['cluster']= cluster.fit_predict(matrix[matrix.columns[3:]])

pca = PCA(n_components=2)

matrix['x'] = pca.fit_transform(matrix[x_cols])[:,0] matrix['y'] = pca.fit_transform(matrix[x_cols])[:,1]

matrix = matrix.reset_index()

customer_clusters = matrix [['Ward names', 'cluster', 'x', 'y']] #works up to here

g = ggplot(data, aes(x='x', y='y',color='cluster')) +\ geom_point(size=75) +\ ggtitle("Clustering based on Area")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!