1 Star 0 Fork 0

zzx-jlu/McTwo_Algorithm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
McTwo.py 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
zzx-jlu 提交于 2021-01-20 21:39 . McTwo
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)]
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zzx-jlu/McTwo_Algorithm.git
git@gitee.com:zzx-jlu/McTwo_Algorithm.git
zzx-jlu
McTwo_Algorithm
McTwo_Algorithm
main

搜索帮助