我有一项工作要使用最小冗余最大相关性算法。代码如下。
import numpy as np
import pandas as pd
from skfeature.function import information_theoretical_based
dataset=pd.read_csv("cancer.csv")
data=pd.DataFrame(dataset)
X= data.iloc[:,:1].values
y=data.iloc[:,1:].values
information_theoretical_based.MRMR.mrmr(X,y)
程序给我错误“ TypeError:不可哈希类型:'numpy.ndarray'”:
TypeError跟踪(最近的呼叫 最后)在() ----> 1 information_theoretical_based.MRMR.mrmr(X,y)
/usr/local/lib/python3.6/dist-packages/skfeature/function/information_theoretical_based/MRMR.py 以mrmr(X,y,** kwargs)为单位 33 F,J_CMI,MIfy = LCSI.lcsi(X,y,gamma = 0,function_name ='MRMR',n_selected_features = n_selected_features) 其他34个: ---> 35 F,J_CMI,MIfy = LCSI.lcsi(X,y,gamma = 0,function_name ='MRMR') 36 return F,J_CMI,MIfy
/usr/local/lib/python3.6/dist-packages/skfeature/function/information_theoretical_based/LCSI.py 在lcsi(X,y,** kwargs)中 对于范围内的我65(n_features): 66 f = X [:, i] ---> 67 t1 [i] = midd(f,y) 68 69#确保j_cmi一开始就为正
/usr/local/lib/python3.6/dist-packages/skfeature/utility/entropy_estimators.py 在midd(x,y) 101“”“ 102 -> 103 return -entropyd(list(zip(x(y,y)))+ entropyd(x)+ entropyd(y) 104 105
/usr/local/lib/python3.6/dist-packages/skfeature/utility/entropy_estimators.py 以entropyd(sx,base)为单位 93“”“ 94 ---> 95从probs(hist(sx),base = base)返回熵 96 97
/usr/local/lib/python3.6/dist-packages/skfeature/utility/entropy_estimators.py 在hist(sx)中 116天= dict() s中s的117: -> 118 d [s] = d.get(s,0)+ 1 119返回映射图(lambda z:float(z)/ len(sx),d.values()) 120
TypeError:不可哈希类型:'numpy.ndarray'
答案 0 :(得分:0)
您的X小于您的y。
也许将其更改为:
X = data.iloc[:,1:].values
y = data.iloc[:,:1].values