Question: 1 . Create a for loop that runs the code from Part I ten more times to build different number of clusters: . You can

1. Create a for loop that runs the code from Part I ten more times to build different number of clusters: . You can change the number of clusters by changing the parameter value that you pass to this function in the code: This function is called in the second line of the Databricks Scala code that you might have used in Part I.
08:14 AM (33s)
1
from pyspark.ml.clustering import KMeans
from pyspark.ml.evaluation import ClusteringEvaluator
Loads data.
dataset = spark.read.format("libsvm").load("/FileStore/tables/colon_cancer__1_.bz2")
Trains a k-means model.
kmeans = KMeans().setK(2).setSeed(1)
model = kmeans.fit(dataset)
Make predictions
predictions = model.transform(dataset)
Evaluate clustering by computing Silhouette score
evaluator = ClusteringEvaluator()
silhouette = evaluator.evaluate(predictions)
print("Silhouette with squared euclidean distance ="+ str(silhouette))
Shows the result.
centers = model.clusterCenters()
print("Cluster Centers: ")
for center in centers:
print(center)
1 . Create a for loop that runs the code from

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 Programming Questions!