本文主要是介绍论文复现Ranked batch-mode active learning表述非常好的论文,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Reference:[1]Silva, Rodrigo, M, et al. Ranked batch-mode active learning[J]. Information Sciences: An International Journal, 2017.
复现了,效果很好~
这个是pointwise 版本的
import xlwt
import numpy as np
import pandas as pd
from copy import deepcopy
from sklearn.metrics import accuracy_score, mean_absolute_error, f1_score, recall_score
from sklearn.metrics import balanced_accuracy_score
from collections import OrderedDictfrom sklearn.model_selection import StratifiedKFold
from sklearn.cluster import KMeans
from pathlib import Pathfrom skactiveml.classifier._pwc import PWC
from skactiveml.pool._probal import McPALimport matplotlib.pyplot as plt
from scipy.spatial.distance import pdist, squareform
from itertools import product, combinations
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics.pairwise import pairwise_distancesclass RBAL():def __init__(self, X_pool, y_pool, labeled, budget, X_test, y_test):self.X_pool = X_poolself.y_pool = y_pool.astype(np.int)self.X_test = X_testself.y_test = y_test.astype(np.int)self.labeled = list(deepcopy(labeled))self.labels = np.unique(self.y_pool)self.nClass = len(self.labels)self.nSample = len(self.y_pool)self.model = LogisticAT()self.theta = Noneself.w = Noneself.unlabeled = self.initialization()self.budget = deepcopy(budget)self.budgetLeft = deepcopy(budget)##-------------------## Evaluation criteriaself.AccList = []self.MAEList = []self.RecallList = []self.FscoreList = []self.CindexList = []self.ALC_ACC = 0.0self.ALC_MAE = 0.0self.ALC_F1 = 0.0self.ALC_Recall = 0.0self.ALC_Cindex = 0.0def initialization(self):unlabeled = [i for i in range(len(self.y_pool))]for j in self.labeled:unlabeled.remove(j)self.model.fit(X=self.X_pool[self.labeled], y=self.y_pool[self.labeled])self.theta, self.w = self.model.theta_w()return unlabeleddef evaluation(self):self.model.fit(X=self.X_pool[self.labeled],y=self.y_pool[self.labeled])y_pred = self.model.predict(X=self.X_test)def Cosine(self,a,b):return pdist(np.vstack([a, b]), "cosine")def select(self):while self.budgetLeft > 0:knnmodel = KNeighborsClassifier(n_neighbors=self.nClass)knnmodel.fit(X=self.X_pool[self.labeled],y=self.y_pool[self.labeled])y_pred_prob = knnmodel.predict_proba(X=self.X_pool[self.unlabeled])metric = OrderedDict()UncertaintyScore = OrderedDict()SimilarityScore = OrderedDict()alpha = len(self.unlabeled) / self.nSamplebeta = 1 - alphafor i, idx in enumerate(self.unlabeled):UncertaintyScore[idx] = 1 - np.max(y_pred_prob[i])biggestSim = 0.0for jdx in self.labeled:simi = 1 / (1 + self.Cosine(self.X_pool[idx],self.X_pool[jdx]))if simi > biggestSim:biggestSim = simiSimilarityScore[idx] = biggestSimmetric[idx] = alpha * (1 - SimilarityScore[idx]) + beta * UncertaintyScore[idx]tar_idx = max(metric, key=metric.get)self.unlabeled.remove(tar_idx)self.labeled.append(tar_idx)self.budgetLeft -= 1self.evaluation()
这篇关于论文复现Ranked batch-mode active learning表述非常好的论文的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!