Advertisement
ImperfectionistCoder

SSE idea

Mar 17th, 2022
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. def cluster_centers(self,X):
  2.       listOfClusters = []
  3.       result = []
  4.       for i in self.clusters:
  5.           listOfClusters.append(self.cluster_list(X,i))
  6.       for ei in listOfClusters:
  7.         sum = [0]
  8.         count = 0
  9.         for ej in ei[1:]:
  10.             sum += ej
  11.             count += 1
  12.         result.append(sum/count)
  13.       return np.array(result)
  14.    
  15.     def SumSquaredError(self,X):
  16.       sse = 0
  17.       for i in self.clusters:
  18.           sse = np.sum((self.cluster_list(X,i) - self.cluster_centers(X)[i])**2)
  19.       return sse
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement