Question: 1 . Create a for loop that runs the code from Part I ten more times to build different number of clusters: . You can
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.
: AM s
from pyspark.mlclustering import KMeans
from pyspark.mlevaluation import ClusteringEvaluator
Loads data.
dataset spark.read.formatlibsvmloadFileStoretablescoloncancerbz
Trains a kmeans model.
kmeans KMeanssetKsetSeed
model kmeans.fitdataset
Make predictions
predictions model.transformdataset
Evaluate clustering by computing Silhouette score
evaluator ClusteringEvaluator
silhouette evaluator.evaluatepredictions
printSilhouette with squared euclidean distance strsilhouette
Shows the result.
centers model.clusterCenters
printCluster Centers:
for center in centers:
printcenter
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
