def test_refine_cluster(self): me = Analyze() # only close and distal me.self_low = False me.silhouette = 0.5 me.df = pd.DataFrame(np.array( [self.dist_gamma, self.dist_lognorm[:800]]).T, columns=['close', 'distal']) me.df['hgt'] = (me.df['close'] < 2) & (me.df['distal'] > 2) me.refine_cluster(me.calc_cluster_props()) self.assertEqual(me.df[me.df['hgt']].shape[0], 11) # all three groups me.self_low = True me.df = pd.DataFrame(np.array( [self.dist_norm1[:800], self.dist_gamma, self.dist_lognorm[:800]]).T, columns=['self', 'close', 'distal']) me.df['hgt'] = (me.df['close'] < 2) & (me.df['distal'] > 2) me.refine_cluster(me.calc_cluster_props()) self.assertEqual(me.df[me.df['hgt']].shape[0], 4)
def test_calc_cluster_props(self): me = Analyze() me.self_low = False me.df = pd.DataFrame(np.array( [self.dist_gamma, self.dist_lognorm[:800]]).T, columns=['close', 'distal']) me.df['hgt'] = (me.df['close'] < 2) & (me.df['distal'] > 2) obs = me.calc_cluster_props() self.assertAlmostEqual(obs[0], 1.094658052928843) self.assertAlmostEqual(obs[1], 4.30076698399293) obs = me.df['silh'].describe() self.assertAlmostEqual(obs['mean'], 0.312495082044277) self.assertAlmostEqual(obs['std'], 0.21945541659155993) self.assertEqual(me.df.query('hgt & silh < 0.5').shape[0], 35)