Add alternative path to data

This commit is contained in:
2021-10-11 23:51:40 +02:00
parent 7288dee193
commit 7abab4f0b1
2 changed files with 63 additions and 7 deletions

View File

@@ -28,15 +28,26 @@ class Diterator:
class Datasets: class Datasets:
def __init__(self): def __init__(self):
try:
with open(os.path.join(Folders.data, Files.index)) as f: with open(os.path.join(Folders.data, Files.index)) as f:
self.data_sets = f.read().splitlines() self.data_sets = f.read().splitlines()
except FileNotFoundError:
with open(os.path.join("..", Folders.data, Files.index)) as f:
self.data_sets = f.read().splitlines()
def load(self, name): def load(self, name):
try:
data = pd.read_csv( data = pd.read_csv(
os.path.join(Folders.data, Files.dataset(name)), os.path.join(Folders.data, Files.dataset(name)),
sep="\t", sep="\t",
index_col=0, index_col=0,
) )
except FileNotFoundError:
data = pd.read_csv(
os.path.join("..", Folders.data, Files.dataset(name)),
sep="\t",
index_col=0,
)
X = data.drop("clase", axis=1).to_numpy() X = data.drop("clase", axis=1).to_numpy()
y = data["clase"].to_numpy() y = data["clase"].to_numpy()
return X, y return X, y

45
src/td.py Normal file
View File

@@ -0,0 +1,45 @@
import sys
import time
from Experiments import Datasets
from mufs import MUFS
mufs_i = MUFS()
mufs_c = MUFS()
mufs_f = MUFS()
datasets = Datasets()
iwss_t = iwss_tl = cfs_t = cfs_tl = fcbf_t = fcbf_tl = 0
for i in datasets:
X, y = datasets.load(i)
now = time.time()
mufs_i.iwss(X, y, float(sys.argv[1]))
iwss = time.time() - now
iwss_r = len(mufs_i.get_results())
now = time.time()
mufs_c.cfs(X, y)
cfs = time.time() - now
cfs_r = len(mufs_c.get_results())
now = time.time()
mufs_f.fcbf(X, y, 1e-5)
fcbf = time.time() - now
fcbf_r = len(mufs_f.get_results())
print(
f"{i:30s} {iwss:.4f}({iwss_r:2d}) {cfs:.4f}({cfs_r:2d}) {fcbf:.4f}"
f"({fcbf_r:2d})"
)
iwss_t += iwss
iwss_tl += iwss_r
cfs_t += cfs
cfs_tl += cfs_r
fcbf_t += fcbf
fcbf_tl += fcbf_r
num = len(list(datasets))
iwss_t /= num
iwss_tl /= num
cfs_t /= num
cfs_tl /= num
fcbf_t /= num
fcbf_tl /= num
print(
f"{'Average ..: ':30s} {iwss_t:.4f}({iwss_tl:.2f}) {cfs_t:.4f}"
f"({cfs_tl:.2f}) {fcbf_t:.4f}({fcbf_tl:.2f})"
)