我正在通过在线jupyter笔记本工作,我被困在为什么我的代码不能工作:
2.1类内散射矩阵SW:
我的代码如下:
def S_W_matrix(X,y):
S_W = np.zeros((X.shape[1],X.shape[1]))
n_classes = len(np.unique(y))
for cl, mv in zip(range(1, n_classes), mean_vectors):
class_sc_mat = np.zeros((X.shape[1],X.shape[1]))
for row in X[y == cl]:
row, mv = row.reshape(X.shape[1],1), mv.reshape((X.shape[1],1)) # make column vectors
class_sc_mat += (row-mv).dot((row-mv).T)
S_W += class_sc_mat
return S_W
在我看来,我的n\u类是不正确的,但我一辈子都搞不清楚为什么会这样,如果我们为每个唯一的类创建矩阵?你知道吗
任何提示/建议,谢谢!你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐