代码拉取完成,页面将自动刷新
import numpy as np
from sklearn.neighbors import KNeighborsClassifier
def calBAcc(F, C):
nRow, nColumn = F.shape
C = C.astype('int')
NN = KNeighborsClassifier(n_neighbors = 1)
prediction = []
# LOO validation
for i in range(nRow):
NN.fit(F[[x for x in range(nRow) if x != i]],
C[[x for x in range(nRow) if x != i]])
prediction.append(NN.predict(F[[i]]).tolist()[0])
prediction = np.array(prediction)
BAcc = (np.mean(prediction[np.where(C == 0)] == C[np.where(C == 0)]) +
np.mean(prediction[np.where(C == 1)] == C[np.where(C == 1)])) / 2
return BAcc
def McTwo(F, C):
nRow, nColumn = F.shape
mBAcc = -1
selected = set([])
left = set([x for x in range(nColumn)])
while True:
BAcc, index = -1, -1
for x in left:
tempBAcc = calBAcc(F[:,list(selected) + [x]], C)
if tempBAcc > BAcc:
BAcc = tempBAcc
index = x
if BAcc > mBAcc:
mBAcc = BAcc
selected.add(index)
left.remove(index)
else:
break
return F[:, list(selected)]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。