论文复现:Ensemble-based active learning using fuzzy-rough approach for cancer sample classification

 Reference:Ansuman Kumar, Anindya Halder.Ensemble-based active learning using fuzzy-rough approach for cancer sample classification.Engineering Applications of Artificial Intelligence, 2020 (91) 103591

不用查了,是SCI二区文章。

不用读了。作者写功好而已

文章在参数设置方面讲的不清楚。

1、模糊数m设置没有讲。

2、每个子模型的k值设置为多少没有讲。

3、集成过程并集为空怎么办没有讲。

花一小时复现了个非集成了的。

读者感兴趣的,自己改成集成的即可(用不同的k值重复select()函数)

'''
author:Deniu He
date:2020-12-11
organization: CQUPT
Reference:Ansuman Kumar, Anindya Halder.Ensemble-based active learning using fuzzy-rough approach for cancer
sample classification.Engineering Applications of Artificial Intelligence, 2020 (91) 103591
'''
import xlwt
import numpy as np
import pandas as pd
from copy import deepcopy
from sklearn.metrics import accuracy_score, mean_absolute_error
from collections import OrderedDict
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import StratifiedKFold
from pathlib import Path
from scipy.spatial.distance import  pdist,squareform


class ALFRNN():
    def __init__(self,X_pool,y_pool,labeled,budget,X_test,y_test):
        self.X_pool = X_pool
        self.y_pool = y_pool.astype(np.int)
        self.X_test = X_test
        self.y_test = y_test.astype(np.int)
        self.labels = np.unique(y_pool)
        self.n_class = len(np.unique(y_pool))
        self.labeled = list(deepcopy(labeled))
        self.unlabeled = self.initialization()
        self.distMatrix = squareform(pdist(self.X_pool,metric='euclidean'))
        self.budgetLeft = deepcopy(budget)
        self.budget = deepcopy(budget)
        self.model = LogisticRegression()
        self.AccList = []
        self.MAEList = []

        self.ALC_Acc = 0.0
        self.ALC_MAE = 0.0
        self.ALC_Acc_10k = 0.0
        self.ALC_MAE_10k = 0.0

    def initialization(self):
        unlabeled = [i for i in range(len(self.y_pool))]
        for j in self.labeled:
            unlabeled.remove(j)
        return unlabeled

    def find_neighbor(self,k):
        neighbor = OrderedDict()
        for idx in self.unlabeled:
            neighbor[idx] = []
            dist_list = []
            for j, jdx in enumerate(self.labeled):
                dist_list.append(self.distMatrix[idx,jdx])
            ordjdx = np.argsort(dist_list)
            for r in range(k):
                neighbor[idx].append(self.labeled[ordjdx[r]])
        return neighbor

    def C(self,j,jdx):
        if self.y_pool[jdx] == self.labels[j]:
            return 1.0
        else:
            return 0.0

    def select(self):
        while self.budgetLeft > 0:
            neighbor = self.find_neighbor(k=self.n_class-1)
            R = OrderedDict()
            for idx, nei in neighbor.items():
                dist_list = []
                for jdx in nei:
                    dist_list.append(self.distMatrix[idx,jdx])
                dist_list = np.array(dist_list)
                dist_list = dist_list ** 2
                R[idx] = sum(dist_list)/dist_list

            lower = OrderedDict()
            for idx, nei in neighbor.items():
                lower[idx] = np.zeros(self.n_class)
                for j in range(self.n_class):
                    rc = []
                    for b,jdx in enumerate(nei):
                        rc.append(min([1,1-R[idx][b]+self.C(j=j,jdx=jdx)]))
                    lower[idx][j] = min(rc)

            upper = OrderedDict()
            for idx, nei in neighbor.items():
                upper[idx] = np.zeros(self.n_class)
                for j in range(self.n_class):
                    rc = []
                    for b, jdx in enumerate(nei):
                        rc.append(max([0,R[idx][b]+self.C(j=j,jdx=jdx)-1]))
                    upper[idx][j] = max(rc)

            Avg = OrderedDict()
            metric = OrderedDict()
            for idx in self.unlabeled:
                Avg[idx] = np.zeros(self.n_class)
                for j in range(self.n_class):
                    Avg[idx][j] = (lower[idx][j] + upper[idx][j])/2
                Avg[idx] = Avg[idx]/ max(Avg[idx])
                ordjx = np.argsort(Avg[idx])
                metric[idx] = Avg[idx][ordjx[1]]
            tar_idx = max(metric,key=metric.get)
            self.labeled.append(tar_idx)
            self.unlabeled.remove(tar_idx)
            self.budgetLeft -= 1
            # print("预算剩余:{}".format(self.budgetLeft))
            self.model.fit(X=self.X_pool[self.labeled], y=self.y_pool[self.labeled])
            Acc = accuracy_score(y_true=self.y_test, y_pred=self.model.predict(self.X_test))
            MAE = mean_absolute_error(y_true=self.y_test, y_pred=self.model.predict(self.X_test))
            self.AccList.append(Acc)
            self.MAEList.append(MAE)
            self.ALC_Acc += Acc
            self.ALC_MAE += MAE

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DeniuHe

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值