Как создать дендрограмму без ASCII с помощью Python?

Пытаюсь создать дендрограмму с этим найденным блоком кода, и она работает до вызова:

r('mt_dist <- dist(t(mt))')

потом выдает ошибку:

RPy_RException: ошибка в dist(t(mt)) : объект (список) нельзя заставить ввести тип double

до этого момента это выглядело хорошо ... я, вероятно, упускаю что-то действительно простое

Любая помощь?

#importing modules
from numpy import array
from random import normalvariate,shuffle
from rpy import r

# creating a random matrix
# creating it with different 'samples' in different columns
mt = []
for l in range(20): #20 lines
    line = []
    means = range(1,9)
    for c in range(8): # 8 columns
        #Colum 1: mean 1; Column 2: mean 2.... values normally distributed s.d. = 0.5       
        line.append(normalvariate(means.pop(), 0.5))

    mt.append(line)

# once we have a matrix, transform it in an array
mt_array = array(mt)

# The R work
# Pass the array to 'mt' variable in R
r.assign("mt", mt_array)

# manipulate R via r('command')
r('print(mt)') #print the matrix 'mt' to check values

#The clustering process
#Calculating distances with 'dist'
#'dist' calculates distance among lines, so I am transposing (with t()) in order to have my columns clustered
## I guess 'dist' uses euclidian distance as default

r('mt_dist <- dist(t(mt))')
# hclust does the clustering with upgma as default

r('result = hclust(mt_dist)')

# directs the output to a determinde file
r('png("output_file.png")')

# plot the result
labels = ["sample A", "sample B","sample C", "sample D","sample E", "sample F", "sample G", "sample H"]
r.assign("labels", labels)
r('plot(result, labels=labels, main="My title")')

# 'close' you output
r('dev.off()')

person T Carrasco    schedule 23.02.2011    source источник


Ответы (1)


Это не ответ на вашу проблему исключения RPy_.... Скорее предоставляя ответ на ваш заголовок How do I create a non-ascii dendrogram with Python?. Вы можете попробовать это, чтобы построить дендрограмму .

person eat    schedule 23.02.2011
comment
я по колено в scipy и matplotlib, и работах. у меня все это установлено и несколько примеров запущены. я, вероятно, задал вопрос лучше здесь - stackoverflow.com/questions/5089030/ - person T Carrasco; 23.02.2011
comment
@Morvern: Итак, мой ответ помог вам двигаться в правильном направлении ;-). - person eat; 23.02.2011
comment
правда ~ так вы можете помочь по предоставленной ссылке? хе-хе - person T Carrasco; 24.02.2011