mirror of
https://github.com/Doctorado-ML/mufs.git
synced 2025-08-16 16:15:56 +00:00
Change module name to MUFS
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[run]
|
[run]
|
||||||
branch = True
|
branch = True
|
||||||
source = mfs
|
source = mufs
|
||||||
|
|
||||||
[report]
|
[report]
|
||||||
exclude_lines =
|
exclude_lines =
|
||||||
@@ -10,4 +10,4 @@ exclude_lines =
|
|||||||
if __name__ == .__main__.:
|
if __name__ == .__main__.:
|
||||||
ignore_errors = True
|
ignore_errors = True
|
||||||
omit =
|
omit =
|
||||||
mfs/__init__.py
|
mufs/__init__.py
|
6
.github/workflows/main.yml
vendored
6
.github/workflows/main.yml
vendored
@@ -30,9 +30,9 @@ jobs:
|
|||||||
pip install -q --upgrade codecov coverage black flake8 codacy-coverage
|
pip install -q --upgrade codecov coverage black flake8 codacy-coverage
|
||||||
- name: Lint
|
- name: Lint
|
||||||
run: |
|
run: |
|
||||||
black --check --diff mfs
|
black --check --diff mufs
|
||||||
flake8 --count mfs
|
flake8 --count mufs
|
||||||
- name: Tests & coverage
|
- name: Tests & coverage
|
||||||
run: |
|
run: |
|
||||||
coverage run -m unittest -v mfs.tests
|
coverage run -m unittest -v mufs.tests
|
||||||
coverage report -m --fail-under=100
|
coverage report -m --fail-under=100
|
||||||
|
14
Makefile
14
Makefile
@@ -4,28 +4,26 @@ SHELL := /bin/bash
|
|||||||
|
|
||||||
coverage: ## Run tests with coverage
|
coverage: ## Run tests with coverage
|
||||||
coverage erase
|
coverage erase
|
||||||
coverage run -m unittest -v mfs.tests
|
coverage run -m unittest -v mufs.tests
|
||||||
coverage report -m
|
coverage report -m
|
||||||
|
|
||||||
deps: ## Install dependencies
|
deps: ## Install dependencies
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
|
|
||||||
lint: ## Lint and static-check
|
lint: ## Lint and static-check
|
||||||
black mfs
|
black mufs
|
||||||
flake8 mfs
|
flake8 mufs
|
||||||
mypy mfs
|
mypy mufs
|
||||||
|
|
||||||
push: ## Push code with tags
|
push: ## Push code with tags
|
||||||
git push && git push --tags
|
git push && git push --tags
|
||||||
|
|
||||||
test: ## Run tests
|
test: ## Run tests
|
||||||
python -m unittest -v mfs.tests
|
python -m unittest -v mufs.tests
|
||||||
|
|
||||||
doc: ## Update documentation
|
|
||||||
make -C docs --makefile=Makefile html
|
|
||||||
|
|
||||||
build: ## Build package
|
build: ## Build package
|
||||||
rm -fr dist/*
|
rm -fr dist/*
|
||||||
|
rm -fr build/*
|
||||||
python setup.py sdist bdist_wheel
|
python setup.py sdist bdist_wheel
|
||||||
|
|
||||||
doc-clean: ## Update documentation
|
doc-clean: ## Update documentation
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||

|

|
||||||
[](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)
|
[](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)
|
||||||
[](https://lgtm.com/projects/g/Doctorado-ML/mfs/context:python)
|
[](https://lgtm.com/projects/g/Doctorado-ML/mufs/context:python)
|
||||||
|
|
||||||
# MFS
|
# MUFS
|
||||||
|
|
||||||
## Multi Feature Selection
|
## Multi Feature Selection
|
||||||
|
|
||||||
|
@@ -1,4 +0,0 @@
|
|||||||
from .MFS_test import MFS_test
|
|
||||||
from .Metrics_test import Metrics_test
|
|
||||||
|
|
||||||
__all__ = ["MFS_test", "Metrics_test"]
|
|
@@ -5,7 +5,7 @@ import numpy as np
|
|||||||
from .Metrics import Metrics
|
from .Metrics import Metrics
|
||||||
|
|
||||||
|
|
||||||
class MFS:
|
class MUFS:
|
||||||
"""Compute Fast Fast Correlation Based Filter
|
"""Compute Fast Fast Correlation Based Filter
|
||||||
Yu, L. and Liu, H.; Feature Selection for High-Dimensional Data: A Fast
|
Yu, L. and Liu, H.; Feature Selection for High-Dimensional Data: A Fast
|
||||||
Correlation Based Filter Solution,Proc. 20th Intl. Conf. Mach. Learn.
|
Correlation Based Filter Solution,Proc. 20th Intl. Conf. Mach. Learn.
|
@@ -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__ = "Ricardo Montañana Gómez"
|
||||||
__author_email__ = "Ricardo.Montanana@alu.uclm.es"
|
__author_email__ = "Ricardo.Montanana@alu.uclm.es"
|
||||||
__copyright__ = "Copyright 2021, Ricardo Montañana Gómez"
|
__copyright__ = "Copyright 2021, Ricardo Montañana Gómez"
|
||||||
__license__ = "MIT License"
|
__license__ = "MIT License"
|
||||||
|
|
||||||
__all__ = ["MFS"]
|
__all__ = ["MUFS"]
|
@@ -2,10 +2,10 @@ import unittest
|
|||||||
from mdlp import MDLP
|
from mdlp import MDLP
|
||||||
from sklearn.datasets import load_wine, load_iris
|
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):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
mdlp = MDLP(random_state=1)
|
mdlp = MDLP(random_state=1)
|
||||||
@@ -21,19 +21,19 @@ class MFS_test(unittest.TestCase):
|
|||||||
self.assertAlmostEqual(a, b, tol)
|
self.assertAlmostEqual(a, b, tol)
|
||||||
|
|
||||||
def test_initialize(self):
|
def test_initialize(self):
|
||||||
mfs = MFS()
|
mufs = MUFS()
|
||||||
mfs.fcbf(self.X_w, self.y_w, 0.05)
|
mufs.fcbf(self.X_w, self.y_w, 0.05)
|
||||||
mfs._initialize(self.X_w, self.y_w)
|
mufs._initialize(self.X_w, self.y_w)
|
||||||
self.assertIsNone(mfs.get_results())
|
self.assertIsNone(mufs.get_results())
|
||||||
self.assertListEqual([], mfs.get_scores())
|
self.assertListEqual([], mufs.get_scores())
|
||||||
self.assertDictEqual({}, mfs._su_features)
|
self.assertDictEqual({}, mufs._su_features)
|
||||||
self.assertIsNone(mfs._su_labels)
|
self.assertIsNone(mufs._su_labels)
|
||||||
|
|
||||||
def test_csf_wine(self):
|
def test_csf_wine(self):
|
||||||
mfs = MFS()
|
mufs = MUFS()
|
||||||
expected = [6, 12, 9, 4, 10, 0]
|
expected = [6, 12, 9, 4, 10, 0]
|
||||||
self.assertListAlmostEqual(
|
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 = [
|
expected = [
|
||||||
0.5218299405215557,
|
0.5218299405215557,
|
||||||
@@ -43,13 +43,13 @@ class MFS_test(unittest.TestCase):
|
|||||||
0.28795671854246285,
|
0.28795671854246285,
|
||||||
0.2309165735173175,
|
0.2309165735173175,
|
||||||
]
|
]
|
||||||
self.assertListAlmostEqual(expected, mfs.get_scores())
|
self.assertListAlmostEqual(expected, mufs.get_scores())
|
||||||
|
|
||||||
def test_csf_wine_cont(self):
|
def test_csf_wine_cont(self):
|
||||||
mfs = MFS(discrete=False)
|
mufs = MUFS(discrete=False)
|
||||||
expected = [10, 6, 0, 2, 11, 9]
|
expected = [10, 6, 0, 2, 11, 9]
|
||||||
self.assertListEqual(
|
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 = [
|
expected = [
|
||||||
0.735264150416997,
|
0.735264150416997,
|
||||||
@@ -59,25 +59,25 @@ class MFS_test(unittest.TestCase):
|
|||||||
0.513637402071709,
|
0.513637402071709,
|
||||||
0.41596400981378984,
|
0.41596400981378984,
|
||||||
]
|
]
|
||||||
self.assertListAlmostEqual(expected, mfs.get_scores())
|
self.assertListAlmostEqual(expected, mufs.get_scores())
|
||||||
|
|
||||||
def test_csf_max_features(self):
|
def test_csf_max_features(self):
|
||||||
mfs = MFS(max_features=3)
|
mufs = MUFS(max_features=3)
|
||||||
expected = [6, 12, 9]
|
expected = [6, 12, 9]
|
||||||
self.assertListAlmostEqual(
|
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 = [
|
expected = [
|
||||||
0.5218299405215557,
|
0.5218299405215557,
|
||||||
0.602513857132804,
|
0.602513857132804,
|
||||||
0.4877384978817362,
|
0.4877384978817362,
|
||||||
]
|
]
|
||||||
self.assertListAlmostEqual(expected, mfs.get_scores())
|
self.assertListAlmostEqual(expected, mufs.get_scores())
|
||||||
|
|
||||||
def test_csf_iris(self):
|
def test_csf_iris(self):
|
||||||
mfs = MFS()
|
mufs = MUFS()
|
||||||
expected = [3, 2, 0, 1]
|
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)
|
self.assertListAlmostEqual(expected, computed)
|
||||||
expected = [
|
expected = [
|
||||||
0.870521418179061,
|
0.870521418179061,
|
||||||
@@ -85,11 +85,11 @@ class MFS_test(unittest.TestCase):
|
|||||||
0.5908278453318913,
|
0.5908278453318913,
|
||||||
0.40371971570693366,
|
0.40371971570693366,
|
||||||
]
|
]
|
||||||
self.assertListAlmostEqual(expected, mfs.get_scores())
|
self.assertListAlmostEqual(expected, mufs.get_scores())
|
||||||
|
|
||||||
def test_fcbf_wine(self):
|
def test_fcbf_wine(self):
|
||||||
mfs = MFS()
|
mufs = MUFS()
|
||||||
computed = mfs.fcbf(self.X_w, self.y_w, threshold=0.05).get_results()
|
computed = mufs.fcbf(self.X_w, self.y_w, threshold=0.05).get_results()
|
||||||
expected = [6, 9, 12, 0, 11, 4]
|
expected = [6, 9, 12, 0, 11, 4]
|
||||||
self.assertListAlmostEqual(expected, computed)
|
self.assertListAlmostEqual(expected, computed)
|
||||||
expected = [
|
expected = [
|
||||||
@@ -100,11 +100,11 @@ class MFS_test(unittest.TestCase):
|
|||||||
0.3790082191220976,
|
0.3790082191220976,
|
||||||
0.24972405134844652,
|
0.24972405134844652,
|
||||||
]
|
]
|
||||||
self.assertListAlmostEqual(expected, mfs.get_scores())
|
self.assertListAlmostEqual(expected, mufs.get_scores())
|
||||||
|
|
||||||
def test_fcbf_max_features(self):
|
def test_fcbf_max_features(self):
|
||||||
mfs = MFS(max_features=3)
|
mufs = MUFS(max_features=3)
|
||||||
computed = mfs.fcbf(self.X_w, self.y_w, threshold=0.05).get_results()
|
computed = mufs.fcbf(self.X_w, self.y_w, threshold=0.05).get_results()
|
||||||
expected = [6, 9, 12]
|
expected = [6, 9, 12]
|
||||||
self.assertListAlmostEqual(expected, computed)
|
self.assertListAlmostEqual(expected, computed)
|
||||||
expected = [
|
expected = [
|
||||||
@@ -112,32 +112,34 @@ class MFS_test(unittest.TestCase):
|
|||||||
0.46224298637417455,
|
0.46224298637417455,
|
||||||
0.44518278979085646,
|
0.44518278979085646,
|
||||||
]
|
]
|
||||||
self.assertListAlmostEqual(expected, mfs.get_scores())
|
self.assertListAlmostEqual(expected, mufs.get_scores())
|
||||||
|
|
||||||
def test_fcbf_iris(self):
|
def test_fcbf_iris(self):
|
||||||
mfs = MFS()
|
mufs = MUFS()
|
||||||
computed = mfs.fcbf(self.X_i, self.y_i, threshold=0.05).get_results()
|
computed = mufs.fcbf(self.X_i, self.y_i, threshold=0.05).get_results()
|
||||||
expected = [3, 2]
|
expected = [3, 2]
|
||||||
self.assertListAlmostEqual(expected, computed)
|
self.assertListAlmostEqual(expected, computed)
|
||||||
expected = [0.870521418179061, 0.810724587460511]
|
expected = [0.870521418179061, 0.810724587460511]
|
||||||
self.assertListAlmostEqual(expected, mfs.get_scores())
|
self.assertListAlmostEqual(expected, mufs.get_scores())
|
||||||
|
|
||||||
def test_compute_su_labels(self):
|
def test_compute_su_labels(self):
|
||||||
mfs = MFS()
|
mufs = MUFS()
|
||||||
mfs.fcbf(self.X_i, self.y_i, threshold=0.05)
|
mufs.fcbf(self.X_i, self.y_i, threshold=0.05)
|
||||||
expected = [0.0, 0.0, 0.810724587460511, 0.870521418179061]
|
expected = [0.0, 0.0, 0.810724587460511, 0.870521418179061]
|
||||||
self.assertListAlmostEqual(expected, mfs._compute_su_labels().tolist())
|
self.assertListAlmostEqual(
|
||||||
mfs._su_labels = [1, 2, 3, 4]
|
expected, mufs._compute_su_labels().tolist()
|
||||||
self.assertListAlmostEqual([1, 2, 3, 4], mfs._compute_su_labels())
|
)
|
||||||
|
mufs._su_labels = [1, 2, 3, 4]
|
||||||
|
self.assertListAlmostEqual([1, 2, 3, 4], mufs._compute_su_labels())
|
||||||
|
|
||||||
def test_invalid_threshold(self):
|
def test_invalid_threshold(self):
|
||||||
mfs = MFS()
|
mufs = MUFS()
|
||||||
with self.assertRaises(ValueError):
|
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):
|
def test_fcbf_exit_threshold(self):
|
||||||
mfs = MFS()
|
mufs = MUFS()
|
||||||
computed = mfs.fcbf(self.X_w, self.y_w, threshold=0.4).get_results()
|
computed = mufs.fcbf(self.X_w, self.y_w, threshold=0.4).get_results()
|
||||||
expected = [6, 9, 12]
|
expected = [6, 9, 12]
|
||||||
self.assertListAlmostEqual(expected, computed)
|
self.assertListAlmostEqual(expected, computed)
|
||||||
expected = [
|
expected = [
|
||||||
@@ -145,4 +147,4 @@ class MFS_test(unittest.TestCase):
|
|||||||
0.46224298637417455,
|
0.46224298637417455,
|
||||||
0.44518278979085646,
|
0.44518278979085646,
|
||||||
]
|
]
|
||||||
self.assertListAlmostEqual(expected, mfs.get_scores())
|
self.assertListAlmostEqual(expected, mufs.get_scores())
|
4
mufs/tests/__init__.py
Normal file
4
mufs/tests/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
from .MUFS_test import MUFS_test
|
||||||
|
from .Metrics_test import Metrics_test
|
||||||
|
|
||||||
|
__all__ = ["MUFS_test", "Metrics_test"]
|
@@ -1 +1,2 @@
|
|||||||
scikit-learn>0.24
|
scikit-learn>0.24
|
||||||
|
mdlp
|
10
sample.py
10
sample.py
@@ -1,11 +1,11 @@
|
|||||||
import warnings
|
import warnings
|
||||||
from mfs import MFS
|
from mufs import MUFS
|
||||||
from mfs.Metrics import Metrics
|
from mufs.Metrics import Metrics
|
||||||
from stree import Stree
|
from stree import Stree
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from scipy.io import arff
|
from scipy.io import arff
|
||||||
|
|
||||||
mfsc = MFS(discrete=False)
|
mufsc = MUFS(discrete=False)
|
||||||
|
|
||||||
filename = "conn-bench-sonar-mines-rocks.arff"
|
filename = "conn-bench-sonar-mines-rocks.arff"
|
||||||
data, meta = arff.loadarff(filename)
|
data, meta = arff.loadarff(filename)
|
||||||
@@ -26,10 +26,10 @@ for i in range(n):
|
|||||||
# Classification
|
# Classification
|
||||||
warnings.filterwarnings("ignore")
|
warnings.filterwarnings("ignore")
|
||||||
print("CFS")
|
print("CFS")
|
||||||
cfs_f = mfsc.cfs(X, y).get_results()
|
cfs_f = mufsc.cfs(X, y).get_results()
|
||||||
print(cfs_f)
|
print(cfs_f)
|
||||||
print("FCBF")
|
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(fcfb_f, len(fcfb_f))
|
||||||
print("X.shape=", X.shape)
|
print("X.shape=", X.shape)
|
||||||
clf = Stree(random_state=0)
|
clf = Stree(random_state=0)
|
||||||
|
10
setup.py
10
setup.py
@@ -8,7 +8,7 @@ def readme():
|
|||||||
|
|
||||||
def get_data(field: str):
|
def get_data(field: str):
|
||||||
item = ""
|
item = ""
|
||||||
with open("mfs/__init__.py") as f:
|
with open("mufs/__init__.py") as f:
|
||||||
for line in f.readlines():
|
for line in f.readlines():
|
||||||
if line.startswith(f"__{field}__"):
|
if line.startswith(f"__{field}__"):
|
||||||
delim = '"' if '"' in line else "'"
|
delim = '"' if '"' in line else "'"
|
||||||
@@ -20,16 +20,16 @@ def get_data(field: str):
|
|||||||
|
|
||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="MFS",
|
name="MUFS",
|
||||||
version=get_data("version"),
|
version=get_data("version"),
|
||||||
license=get_data("license"),
|
license=get_data("license"),
|
||||||
description="Multi Feature Selection",
|
description="Multi Feature Selection",
|
||||||
long_description=readme(),
|
long_description=readme(),
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
packages=setuptools.find_packages(),
|
packages=setuptools.find_packages(),
|
||||||
url="https://github.com/Doctorado-ML/mfs#mfs",
|
url="https://github.com/Doctorado-ML/mufs#mufs",
|
||||||
project_urls={
|
project_urls={
|
||||||
"Code": "https://github.com/Doctorado-ML/mfs",
|
"Code": "https://github.com/Doctorado-ML/mufs",
|
||||||
},
|
},
|
||||||
author=get_data("author"),
|
author=get_data("author"),
|
||||||
author_email=get_data("author_email"),
|
author_email=get_data("author_email"),
|
||||||
@@ -43,6 +43,6 @@ setuptools.setup(
|
|||||||
"Intended Audience :: Science/Research",
|
"Intended Audience :: Science/Research",
|
||||||
],
|
],
|
||||||
install_requires=["scikit-learn"],
|
install_requires=["scikit-learn"],
|
||||||
test_suite="mfs.tests",
|
test_suite="mufs.tests",
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user