コード例 #1
0
def test2():
    """
	tests the max_kappa function that finds the maximum kappa value for 2 sets
	of predictions up to permutations of the cluster numberings
	"""

    pred1 = np.array([0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 0, 0, 0])
    pred2 = np.array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2])

    x = np.array([[2, 0, 3], [5, 0, 0], [1, 4, 0]])

    kappa_max, corrected_x, new_order = max_kappa(pred1, pred2)

    assert_allclose(x[:, new_order], corrected_x)

    assert kappa_max == kappa_function(x[:, new_order])
コード例 #2
0
# In [2]: kmean_pred.shape
# Out[2]: (4, 159, 2, 2)
#        data, obs, cluster options, grey
# In [3]: dirichelet_pred.shape
# Out[3]: (4, 159, 2, 2)
# In [4]: hierarchy_pred.shape
# Out[4]: (159, 5, 8)
#  		 obs, cluster type, data * grey




comparison_kappa    = np.zeros((4,2,2+2+5,2+2+5))
comparison_accuracy = np.zeros((4,2,2+2+5,2+2+5))

for data_num,grey_num in itertools.product(np.arange(4),np.arange(2)):
	predictions        = -10*np.ones((X_full.shape[0],9))
	predictions[:,:2]  = kmean_pred[data_num,:,grey_num,:]
	predictions[:,2:4] = dirichelet_pred[data_num,:,grey_num,:]
	predictions[:,4:]  = hierarchy_pred[:,:,2*data_num+grey_num]


	for i,pred1 in enumerate(predictions):
		for j,pred2 in enumerate(predictions):
			m_kappa, m_confusion, _  = max_kappa(pred1,pred2)

			comparison_kappa[data_num,grey_num,i,j]    = m_kappa
			comparison_accuracy[data_num,grey_num,i,j] =