How to get flat clustering corresponding to color clusters in the dendrogram created by scipy

I think you’re on the right track. Let’s try this: import scipy import scipy.cluster.hierarchy as sch X = scipy.randn(100, 2) # 100 2-dimensional observations d = sch.distance.pdist(X) # vector of (100 choose 2) pairwise distances L = sch.linkage(d, method=’complete’) ind = sch.fcluster(L, 0.5*d.max(), ‘distance’) ind will give you cluster indices for each of the 100 … Read more

pandas dataframe select columns in multiindex [duplicate]

There is a get_level_values method that you can use in conjunction with boolean indexing to get the the intended result. In [13]: df = pd.DataFrame(np.random.random((4,4))) df.columns = pd.MultiIndex.from_product([[1,2],[‘A’,’B’]]) print df 1 2 A B A B 0 0.543980 0.628078 0.756941 0.698824 1 0.633005 0.089604 0.198510 0.783556 2 0.662391 0.541182 0.544060 0.059381 3 0.841242 0.634603 0.815334 … Read more

How to concatenate two layers in keras?

You’re getting the error because result defined as Sequential() is just a container for the model and you have not defined an input for it. Given what you’re trying to build set result to take the third input x3. first = Sequential() first.add(Dense(1, input_shape=(2,), activation=’sigmoid’)) second = Sequential() second.add(Dense(1, input_shape=(1,), activation=’sigmoid’)) third = Sequential() # … Read more