Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import itertools as it
- def is_equal(x):
- return (x[0]==x[1])
- def rand_index_score(y_gold, y_pred):
- # Vaš kôd ovdje...
- my_pair = list(it.combinations(range(len(y_gold)), 2)) #create list of all combinations with the length of labels.
- my_a = 0
- my_b = 0
- n = len(y_gold)
- for i in range(len(my_pair)):
- 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]]))
- and is_equal((y_pred[my_pair[i][0]],y_pred[my_pair[i][1]])) == True):
- my_a += 1
- 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]]))
- and is_equal((y_pred[my_pair[i][0]],y_pred[my_pair[i][1]])) == False):
- my_b += 1
- my_denom = n * (n-1)/2
- ri = (my_a + my_b) / my_denom
- return ri
- print(rand_index_score(y1, g1.predict(X1)))
- kmeans = KMeans(n_clusters=2).fit(X2)
- print(rand_index_score(y2, kmeans.predict(X2)))
- print(rand_index_score(y2, g2.predict(X2)))
- print(rand_index_score(y3, g3.predict(X3)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement