Change module name to MUFS

This commit is contained in:
2021-08-02 17:44:51 +02:00
parent bd709131e4
commit d8299766c9
14 changed files with 77 additions and 76 deletions

View File

@@ -1,6 +1,6 @@
[run]
branch = True
source = mfs
source = mufs
[report]
exclude_lines =
@@ -10,4 +10,4 @@ exclude_lines =
if __name__ == .__main__.:
ignore_errors = True
omit =
mfs/__init__.py
mufs/__init__.py

View File

@@ -30,9 +30,9 @@ jobs:
pip install -q --upgrade codecov coverage black flake8 codacy-coverage
- name: Lint
run: |
black --check --diff mfs
flake8 --count mfs
black --check --diff mufs
flake8 --count mufs
- name: Tests & coverage
run: |
coverage run -m unittest -v mfs.tests
coverage run -m unittest -v mufs.tests
coverage report -m --fail-under=100

View File

@@ -4,28 +4,26 @@ SHELL := /bin/bash
coverage: ## Run tests with coverage
coverage erase
coverage run -m unittest -v mfs.tests
coverage run -m unittest -v mufs.tests
coverage report -m
deps: ## Install dependencies
pip install -r requirements.txt
lint: ## Lint and static-check
black mfs
flake8 mfs
mypy mfs
black mufs
flake8 mufs
mypy mufs
push: ## Push code with tags
git push && git push --tags
test: ## Run tests
python -m unittest -v mfs.tests
doc: ## Update documentation
make -C docs --makefile=Makefile html
python -m unittest -v mufs.tests
build: ## Build package
rm -fr dist/*
rm -fr build/*
python setup.py sdist bdist_wheel
doc-clean: ## Update documentation

View File

@@ -1,8 +1,8 @@
![CI](https://github.com/Doctorado-ML/mfs/workflows/CI/badge.svg)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/66ad727eb13e4c7a8816db1e44d994a7)](https://www.codacy.com/gh/Doctorado-ML/mfs/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Doctorado-ML/mfs&utm_campaign=Badge_Grade)
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/Doctorado-ML/mfs.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Doctorado-ML/mfs/context:python)
![CI](https://github.com/Doctorado-ML/mufs/workflows/CI/badge.svg)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/66ad727eb13e4c7a8816db1e44d994a7)](https://www.codacy.com/gh/Doctorado-ML/mufs/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Doctorado-ML/mufs&utm_campaign=Badge_Grade)
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/Doctorado-ML/mufs.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Doctorado-ML/mufs/context:python)
# MFS
# MUFS
## Multi Feature Selection

View File

@@ -1,4 +0,0 @@
from .MFS_test import MFS_test
from .Metrics_test import Metrics_test
__all__ = ["MFS_test", "Metrics_test"]

View File

@@ -5,7 +5,7 @@ import numpy as np
from .Metrics import Metrics
class MFS:
class MUFS:
"""Compute Fast Fast Correlation Based Filter
Yu, L. and Liu, H.; Feature Selection for High-Dimensional Data: A Fast
Correlation Based Filter Solution,Proc. 20th Intl. Conf. Mach. Learn.

View File

@@ -1,9 +1,9 @@
from .Selection import MFS
from .Selection import MUFS
__version__ = "0.1"
__version__ = "0.1.1"
__author__ = "Ricardo Montañana Gómez"
__author_email__ = "Ricardo.Montanana@alu.uclm.es"
__copyright__ = "Copyright 2021, Ricardo Montañana Gómez"
__license__ = "MIT License"
__all__ = ["MFS"]
__all__ = ["MUFS"]

View File

@@ -2,10 +2,10 @@ import unittest
from mdlp import MDLP
from sklearn.datasets import load_wine, load_iris
from ..Selection import MFS
from ..Selection import MUFS
class MFS_test(unittest.TestCase):
class MUFS_test(unittest.TestCase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
mdlp = MDLP(random_state=1)
@@ -21,19 +21,19 @@ class MFS_test(unittest.TestCase):
self.assertAlmostEqual(a, b, tol)
def test_initialize(self):
mfs = MFS()
mfs.fcbf(self.X_w, self.y_w, 0.05)
mfs._initialize(self.X_w, self.y_w)
self.assertIsNone(mfs.get_results())
self.assertListEqual([], mfs.get_scores())
self.assertDictEqual({}, mfs._su_features)
self.assertIsNone(mfs._su_labels)
mufs = MUFS()
mufs.fcbf(self.X_w, self.y_w, 0.05)
mufs._initialize(self.X_w, self.y_w)
self.assertIsNone(mufs.get_results())
self.assertListEqual([], mufs.get_scores())
self.assertDictEqual({}, mufs._su_features)
self.assertIsNone(mufs._su_labels)
def test_csf_wine(self):
mfs = MFS()
mufs = MUFS()
expected = [6, 12, 9, 4, 10, 0]
self.assertListAlmostEqual(
expected, mfs.cfs(self.X_w, self.y_w).get_results()
expected, mufs.cfs(self.X_w, self.y_w).get_results()
)
expected = [
0.5218299405215557,
@@ -43,13 +43,13 @@ class MFS_test(unittest.TestCase):
0.28795671854246285,
0.2309165735173175,
]
self.assertListAlmostEqual(expected, mfs.get_scores())
self.assertListAlmostEqual(expected, mufs.get_scores())
def test_csf_wine_cont(self):
mfs = MFS(discrete=False)
mufs = MUFS(discrete=False)
expected = [10, 6, 0, 2, 11, 9]
self.assertListEqual(
expected, mfs.cfs(self.X_wc, self.y_w).get_results()
expected, mufs.cfs(self.X_wc, self.y_w).get_results()
)
expected = [
0.735264150416997,
@@ -59,25 +59,25 @@ class MFS_test(unittest.TestCase):
0.513637402071709,
0.41596400981378984,
]
self.assertListAlmostEqual(expected, mfs.get_scores())
self.assertListAlmostEqual(expected, mufs.get_scores())
def test_csf_max_features(self):
mfs = MFS(max_features=3)
mufs = MUFS(max_features=3)
expected = [6, 12, 9]
self.assertListAlmostEqual(
expected, mfs.cfs(self.X_w, self.y_w).get_results()
expected, mufs.cfs(self.X_w, self.y_w).get_results()
)
expected = [
0.5218299405215557,
0.602513857132804,
0.4877384978817362,
]
self.assertListAlmostEqual(expected, mfs.get_scores())
self.assertListAlmostEqual(expected, mufs.get_scores())
def test_csf_iris(self):
mfs = MFS()
mufs = MUFS()
expected = [3, 2, 0, 1]
computed = mfs.cfs(self.X_i, self.y_i).get_results()
computed = mufs.cfs(self.X_i, self.y_i).get_results()
self.assertListAlmostEqual(expected, computed)
expected = [
0.870521418179061,
@@ -85,11 +85,11 @@ class MFS_test(unittest.TestCase):
0.5908278453318913,
0.40371971570693366,
]
self.assertListAlmostEqual(expected, mfs.get_scores())
self.assertListAlmostEqual(expected, mufs.get_scores())
def test_fcbf_wine(self):
mfs = MFS()
computed = mfs.fcbf(self.X_w, self.y_w, threshold=0.05).get_results()
mufs = MUFS()
computed = mufs.fcbf(self.X_w, self.y_w, threshold=0.05).get_results()
expected = [6, 9, 12, 0, 11, 4]
self.assertListAlmostEqual(expected, computed)
expected = [
@@ -100,11 +100,11 @@ class MFS_test(unittest.TestCase):
0.3790082191220976,
0.24972405134844652,
]
self.assertListAlmostEqual(expected, mfs.get_scores())
self.assertListAlmostEqual(expected, mufs.get_scores())
def test_fcbf_max_features(self):
mfs = MFS(max_features=3)
computed = mfs.fcbf(self.X_w, self.y_w, threshold=0.05).get_results()
mufs = MUFS(max_features=3)
computed = mufs.fcbf(self.X_w, self.y_w, threshold=0.05).get_results()
expected = [6, 9, 12]
self.assertListAlmostEqual(expected, computed)
expected = [
@@ -112,32 +112,34 @@ class MFS_test(unittest.TestCase):
0.46224298637417455,
0.44518278979085646,
]
self.assertListAlmostEqual(expected, mfs.get_scores())
self.assertListAlmostEqual(expected, mufs.get_scores())
def test_fcbf_iris(self):
mfs = MFS()
computed = mfs.fcbf(self.X_i, self.y_i, threshold=0.05).get_results()
mufs = MUFS()
computed = mufs.fcbf(self.X_i, self.y_i, threshold=0.05).get_results()
expected = [3, 2]
self.assertListAlmostEqual(expected, computed)
expected = [0.870521418179061, 0.810724587460511]
self.assertListAlmostEqual(expected, mfs.get_scores())
self.assertListAlmostEqual(expected, mufs.get_scores())
def test_compute_su_labels(self):
mfs = MFS()
mfs.fcbf(self.X_i, self.y_i, threshold=0.05)
mufs = MUFS()
mufs.fcbf(self.X_i, self.y_i, threshold=0.05)
expected = [0.0, 0.0, 0.810724587460511, 0.870521418179061]
self.assertListAlmostEqual(expected, mfs._compute_su_labels().tolist())
mfs._su_labels = [1, 2, 3, 4]
self.assertListAlmostEqual([1, 2, 3, 4], mfs._compute_su_labels())
self.assertListAlmostEqual(
expected, mufs._compute_su_labels().tolist()
)
mufs._su_labels = [1, 2, 3, 4]
self.assertListAlmostEqual([1, 2, 3, 4], mufs._compute_su_labels())
def test_invalid_threshold(self):
mfs = MFS()
mufs = MUFS()
with self.assertRaises(ValueError):
mfs.fcbf(self.X_i, self.y_i, threshold=1e-15)
mufs.fcbf(self.X_i, self.y_i, threshold=1e-15)
def test_fcbf_exit_threshold(self):
mfs = MFS()
computed = mfs.fcbf(self.X_w, self.y_w, threshold=0.4).get_results()
mufs = MUFS()
computed = mufs.fcbf(self.X_w, self.y_w, threshold=0.4).get_results()
expected = [6, 9, 12]
self.assertListAlmostEqual(expected, computed)
expected = [
@@ -145,4 +147,4 @@ class MFS_test(unittest.TestCase):
0.46224298637417455,
0.44518278979085646,
]
self.assertListAlmostEqual(expected, mfs.get_scores())
self.assertListAlmostEqual(expected, mufs.get_scores())

4
mufs/tests/__init__.py Normal file
View File

@@ -0,0 +1,4 @@
from .MUFS_test import MUFS_test
from .Metrics_test import Metrics_test
__all__ = ["MUFS_test", "Metrics_test"]

View File

@@ -1 +1,2 @@
scikit-learn>0.24
mdlp

View File

@@ -1,11 +1,11 @@
import warnings
from mfs import MFS
from mfs.Metrics import Metrics
from mufs import MUFS
from mufs.Metrics import Metrics
from stree import Stree
import numpy as np
from scipy.io import arff
mfsc = MFS(discrete=False)
mufsc = MUFS(discrete=False)
filename = "conn-bench-sonar-mines-rocks.arff"
data, meta = arff.loadarff(filename)
@@ -26,10 +26,10 @@ for i in range(n):
# Classification
warnings.filterwarnings("ignore")
print("CFS")
cfs_f = mfsc.cfs(X, y).get_results()
cfs_f = mufsc.cfs(X, y).get_results()
print(cfs_f)
print("FCBF")
fcfb_f = mfsc.fcbf(X, y, 5e-2).get_results()
fcfb_f = mufsc.fcbf(X, y, 5e-2).get_results()
print(fcfb_f, len(fcfb_f))
print("X.shape=", X.shape)
clf = Stree(random_state=0)

View File

@@ -8,7 +8,7 @@ def readme():
def get_data(field: str):
item = ""
with open("mfs/__init__.py") as f:
with open("mufs/__init__.py") as f:
for line in f.readlines():
if line.startswith(f"__{field}__"):
delim = '"' if '"' in line else "'"
@@ -20,16 +20,16 @@ def get_data(field: str):
setuptools.setup(
name="MFS",
name="MUFS",
version=get_data("version"),
license=get_data("license"),
description="Multi Feature Selection",
long_description=readme(),
long_description_content_type="text/markdown",
packages=setuptools.find_packages(),
url="https://github.com/Doctorado-ML/mfs#mfs",
url="https://github.com/Doctorado-ML/mufs#mufs",
project_urls={
"Code": "https://github.com/Doctorado-ML/mfs",
"Code": "https://github.com/Doctorado-ML/mufs",
},
author=get_data("author"),
author_email=get_data("author_email"),
@@ -43,6 +43,6 @@ setuptools.setup(
"Intended Audience :: Science/Research",
],
install_requires=["scikit-learn"],
test_suite="mfs.tests",
test_suite="mufs.tests",
zip_safe=False,
)