Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import itertools as it
  2. def is_equal(x):
  3. return (x[0]==x[1])
  4. def rand_index_score(y_gold, y_pred):
  5. # Vaš kôd ovdje...
  6. my_pair = list(it.combinations(range(len(y_gold)), 2)) #create list of all combinations with the length of labels.
  7. my_a = 0
  8. my_b = 0
  9. n = len(y_gold)
  10.  
  11. for i in range(len(my_pair)):
  12. if(is_equal((y_gold[my_pair[i][0]],y_gold[my_pair[i][1]])) == is_equal((y_pred[my_pair[i][0]],y_pred[my_pair[i][1]]))
  13. and is_equal((y_pred[my_pair[i][0]],y_pred[my_pair[i][1]])) == True):
  14. my_a += 1
  15. if(is_equal((y_gold[my_pair[i][0]],y_gold[my_pair[i][1]])) == is_equal((y_pred[my_pair[i][0]],y_pred[my_pair[i][1]]))
  16. and is_equal((y_pred[my_pair[i][0]],y_pred[my_pair[i][1]])) == False):
  17. my_b += 1
  18. my_denom = n * (n-1)/2
  19. ri = (my_a + my_b) / my_denom
  20. return ri
  21. print(rand_index_score(y1, g1.predict(X1)))
  22. kmeans = KMeans(n_clusters=2).fit(X2)
  23. print(rand_index_score(y2, kmeans.predict(X2)))
  24. print(rand_index_score(y2, g2.predict(X2)))
  25. print(rand_index_score(y3, g3.predict(X3)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement