mirror of
https://github.com/Doctorado-ML/mufs.git
synced 2025-08-18 17:15:52 +00:00
Compare commits
2 Commits
v0.1.3
...
fix_merit_
Author | SHA1 | Date | |
---|---|---|---|
d0f1cc5979
|
|||
b958bccef6
|
37
.github/workflows/main.yml
vendored
37
.github/workflows/main.yml
vendored
@@ -12,13 +12,11 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
python: ["3.10"]
|
||||
os: [macos-latest, ubuntu-latest]
|
||||
python: [3.8]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Python ${{ matrix.python }}
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
@@ -28,37 +26,14 @@ jobs:
|
||||
pip install -q --upgrade pip
|
||||
pip install -q cython
|
||||
pip install -q numpy
|
||||
pip install -q git+https://github.com/doctorado-ml/mdlp
|
||||
pip install -q git+git://github.com/doctorado-ml/mdlp
|
||||
pip install -q -r requirements/dev.txt
|
||||
pip install -q --upgrade codecov coverage black flake8 codacy-coverage unittest-xml-reporting
|
||||
pip install -q --upgrade codecov coverage black flake8 codacy-coverage
|
||||
- name: Lint
|
||||
run: |
|
||||
black --check --diff mufs
|
||||
flake8 --count mufs
|
||||
- name: Tests & coverage
|
||||
run: |
|
||||
mkdir .report
|
||||
coverage run -m xmlrunner -v mufs.tests -o .report
|
||||
coverage xml -i -o .report/coverage.xml
|
||||
coverage run -m unittest -v mufs.tests
|
||||
coverage report -m --fail-under=100
|
||||
- name: Get project version
|
||||
run: echo "project_version=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
|
||||
- name: Override Coverage Source Path for Sonar
|
||||
run: sed -i 's/\/home\/runner\/work\/mufs\/mufs\//\/github\/workspace\//g' .report/coverage.xml
|
||||
- name: SonarQube scanner
|
||||
uses: sonarsource/sonarqube-scan-action@master
|
||||
env:
|
||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
|
||||
with:
|
||||
args: >
|
||||
-Dsonar.projectVersion=${{ env.project_version }}
|
||||
-Dsonar.python.coverage.reportPaths=.report/coverage.xml
|
||||
-Dsonar.python.xunit.reportPath=.report/TEST*
|
||||
# If you wish to fail your job when the Quality Gate is red, uncomment the
|
||||
# following lines. This would typically be used to fail a deployment.
|
||||
- name: Quality Gate
|
||||
uses: sonarsource/sonarqube-quality-gate-action@master
|
||||
timeout-minutes: 5
|
||||
env:
|
||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||
|
@@ -1,12 +1,12 @@
|
||||
repos:
|
||||
- repo: https://github.com/ambv/black
|
||||
rev: 22.3.0
|
||||
rev: 22.1.0
|
||||
hooks:
|
||||
- id: black
|
||||
exclude: ".virtual_documents"
|
||||
language_version: python3.8
|
||||
- repo: https://gitlab.com/pycqa/flake8
|
||||
rev: 3.9.2
|
||||
rev: 3.8.4
|
||||
hooks:
|
||||
- id: flake8
|
||||
exclude: ".virtual_documents"
|
||||
@@ -16,7 +16,7 @@ repos:
|
||||
# - id: mypy
|
||||
# # args: [--strict, --ignore-missing-imports]
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.2.0
|
||||
rev: v3.4.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: check-case-conflict
|
||||
|
5
Makefile
5
Makefile
@@ -1,6 +1,6 @@
|
||||
SHELL := /bin/bash
|
||||
.DEFAULT_GOAL := help
|
||||
.PHONY: coverage deps help lint push test build
|
||||
.PHONY: coverage deps help lint push test doc build
|
||||
|
||||
coverage: ## Run tests with coverage
|
||||
coverage erase
|
||||
@@ -26,6 +26,9 @@ build: ## Build package
|
||||
rm -fr build/*
|
||||
python setup.py sdist bdist_wheel
|
||||
|
||||
doc-clean: ## Update documentation
|
||||
make -C docs --makefile=Makefile clean
|
||||
|
||||
help: ## Show help message
|
||||
@IFS=$$'\n' ; \
|
||||
help_lines=(`fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##/:/'`); \
|
||||
|
@@ -2,8 +2,6 @@
|
||||
[](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/mufs/context:python)
|
||||
[](https://badge.fury.io/py/MUFS)
|
||||
[](https://haystack.rmontanana.es:25000/dashboard?id=mufs)
|
||||
[](https://haystack.rmontanana.es:25000/dashboard?id=mufs)
|
||||

|
||||
|
||||
# MUFS
|
||||
|
@@ -3,7 +3,6 @@ from sys import float_info
|
||||
from itertools import combinations
|
||||
import numpy as np
|
||||
from .Metrics import Metrics
|
||||
from ._version import __version__
|
||||
|
||||
|
||||
class MUFS:
|
||||
@@ -41,11 +40,6 @@ class MUFS:
|
||||
)
|
||||
self._fitted = False
|
||||
|
||||
@staticmethod
|
||||
def version() -> str:
|
||||
"""Return the version of the package."""
|
||||
return __version__
|
||||
|
||||
def _initialize(self, X, y):
|
||||
"""Initialize the attributes so support multiple calls using same
|
||||
object
|
||||
@@ -134,7 +128,7 @@ class MUFS:
|
||||
k = len(features)
|
||||
for pair in list(combinations(features, 2)):
|
||||
rff += self._compute_su_features(*pair)
|
||||
return rcf / sqrt(k + (k**2 - k) * rff)
|
||||
return k * rcf / sqrt(k + (k**2 - k) * rff)
|
||||
|
||||
def cfs(self, X, y):
|
||||
"""Correlation-based Feature Selection
|
||||
|
@@ -1,8 +1,9 @@
|
||||
from .Selection import MUFS
|
||||
|
||||
__version__ = "0.1.2"
|
||||
__author__ = "Ricardo Montañana Gómez"
|
||||
__author_email__ = "Ricardo.Montanana@alu.uclm.es"
|
||||
__copyright__ = "Copyright 2021-2022, Ricardo Montañana Gómez"
|
||||
__copyright__ = "Copyright 2021, Ricardo Montañana Gómez"
|
||||
__license__ = "MIT License"
|
||||
|
||||
__all__ = ["MUFS"]
|
||||
|
@@ -1 +0,0 @@
|
||||
__version__ = "0.1.3"
|
@@ -4,8 +4,8 @@ import pandas as pd
|
||||
import numpy as np
|
||||
from mdlp import MDLP
|
||||
from sklearn.datasets import load_wine, load_iris
|
||||
|
||||
from ..Selection import MUFS
|
||||
from .._version import __version__
|
||||
|
||||
|
||||
class MUFSTest(unittest.TestCase):
|
||||
@@ -18,11 +18,6 @@ class MUFSTest(unittest.TestCase):
|
||||
mdlp = MDLP(random_state=1)
|
||||
self.X_i = mdlp.fit_transform(self.X_ic, self.y_i).astype("int64")
|
||||
|
||||
def test_version(self):
|
||||
"""Check package version."""
|
||||
mufs = MUFS()
|
||||
self.assertEqual(__version__, mufs.version())
|
||||
|
||||
def assertListAlmostEqual(self, list1, list2, tol=7):
|
||||
self.assertEqual(len(list1), len(list2))
|
||||
for a, b in zip(list1, list2):
|
||||
@@ -39,33 +34,38 @@ class MUFSTest(unittest.TestCase):
|
||||
|
||||
def test_csf_wine(self):
|
||||
mufs = MUFS()
|
||||
expected = [6, 12, 9, 4, 10, 0]
|
||||
expected = [6, 12, 9, 4, 10, 0, 7, 8]
|
||||
self.assertListEqual(
|
||||
expected, mufs.cfs(self.X_w, self.y_w).get_results()
|
||||
)
|
||||
expected = [
|
||||
0.5218299405215557,
|
||||
0.602513857132804,
|
||||
0.4877384978817362,
|
||||
0.3743688234383051,
|
||||
0.28795671854246285,
|
||||
0.2309165735173175,
|
||||
1.205027714265608,
|
||||
1.4632154936452084,
|
||||
1.4974752937532203,
|
||||
1.4397835927123144,
|
||||
1.385499441103905,
|
||||
1.340618857006277,
|
||||
1.2989177695790775,
|
||||
]
|
||||
self.assertListAlmostEqual(expected, mufs.get_scores())
|
||||
|
||||
def test_csf_wine_cont(self):
|
||||
mufs = MUFS(discrete=False)
|
||||
expected = [10, 6, 0, 2, 11, 9]
|
||||
expected = [10, 6, 0, 2, 11, 9, 8, 1, 5]
|
||||
self.assertListEqual(
|
||||
expected, mufs.cfs(self.X_wc, self.y_w).get_results()
|
||||
)
|
||||
expected = [
|
||||
0.735264150416997,
|
||||
0.8321684551546848,
|
||||
0.7439915858469107,
|
||||
0.6238883340158233,
|
||||
0.513637402071709,
|
||||
0.41596400981378984,
|
||||
1.6643369103093697,
|
||||
2.231974757540732,
|
||||
2.4955533360632933,
|
||||
2.568187010358545,
|
||||
2.495784058882739,
|
||||
2.4409992149141915,
|
||||
2.3665143407182456,
|
||||
2.280111788845658,
|
||||
]
|
||||
self.assertListAlmostEqual(expected, mufs.get_scores())
|
||||
|
||||
@@ -75,11 +75,7 @@ class MUFSTest(unittest.TestCase):
|
||||
self.assertListAlmostEqual(
|
||||
expected, mufs.cfs(self.X_w, self.y_w).get_results()
|
||||
)
|
||||
expected = [
|
||||
0.5218299405215557,
|
||||
0.602513857132804,
|
||||
0.4877384978817362,
|
||||
]
|
||||
expected = [0.5218299405215557, 1.205027714265608, 1.4632154936452084]
|
||||
self.assertListAlmostEqual(expected, mufs.get_scores())
|
||||
|
||||
def test_csf_iris(self):
|
||||
@@ -89,9 +85,9 @@ class MUFSTest(unittest.TestCase):
|
||||
self.assertListEqual(expected, computed)
|
||||
expected = [
|
||||
0.870521418179061,
|
||||
0.8968651482682227,
|
||||
0.5908278453318913,
|
||||
0.40371971570693366,
|
||||
1.7937302965364454,
|
||||
1.7724835359956739,
|
||||
1.6148788628277346,
|
||||
]
|
||||
self.assertListAlmostEqual(expected, mufs.get_scores())
|
||||
|
||||
@@ -159,11 +155,19 @@ class MUFSTest(unittest.TestCase):
|
||||
|
||||
def test_iwss_wine(self):
|
||||
mufs = MUFS()
|
||||
expected = [6, 9, 12]
|
||||
expected = [6, 9, 12, 0, 11, 10, 5]
|
||||
self.assertListEqual(
|
||||
expected, mufs.iwss(self.X_w, self.y_w, 0.2).get_results()
|
||||
)
|
||||
expected = [0.5218299405215557, 0.5947822876110085, 0.4877384978817362]
|
||||
expected = [
|
||||
0.5218299405215557,
|
||||
1.189564575222017,
|
||||
1.4632154936452084,
|
||||
1.428626297656075,
|
||||
1.3384248731269246,
|
||||
1.2869213430115078,
|
||||
1.1949414936926785,
|
||||
]
|
||||
self.assertListAlmostEqual(expected, mufs.get_scores())
|
||||
|
||||
def test_iwss_wine_max_features(self):
|
||||
@@ -172,7 +176,7 @@ class MUFSTest(unittest.TestCase):
|
||||
self.assertListEqual(
|
||||
expected, mufs.iwss(self.X_w, self.y_w, 0.4).get_results()
|
||||
)
|
||||
expected = [0.5218299405215557, 0.5947822876110085, 0.4877384978817362]
|
||||
expected = [0.5218299405215557, 1.189564575222017, 1.4632154936452084]
|
||||
self.assertListAlmostEqual(expected, mufs.get_scores())
|
||||
|
||||
def test_iwss_exception(self):
|
||||
|
@@ -1,3 +1,3 @@
|
||||
-r production.txt
|
||||
mdlp
|
||||
pandas
|
||||
pandas
|
||||
|
15
setup.py
15
setup.py
@@ -1,4 +1,3 @@
|
||||
import os
|
||||
import setuptools
|
||||
|
||||
|
||||
@@ -7,10 +6,9 @@ def readme():
|
||||
return f.read()
|
||||
|
||||
|
||||
def get_data(field):
|
||||
def get_data(field: str):
|
||||
item = ""
|
||||
file_name = "_version.py" if field == "version" else "__init__.py"
|
||||
with open(os.path.join("mufs", file_name)) as f:
|
||||
with open("mufs/__init__.py") as f:
|
||||
for line in f.readlines():
|
||||
if line.startswith(f"__{field}__"):
|
||||
delim = '"' if '"' in line else "'"
|
||||
@@ -21,11 +19,6 @@ def get_data(field):
|
||||
return item
|
||||
|
||||
|
||||
def get_requirements():
|
||||
with open("requirements/production.txt") as f:
|
||||
return f.read().splitlines()
|
||||
|
||||
|
||||
setuptools.setup(
|
||||
name="MUFS",
|
||||
version=get_data("version"),
|
||||
@@ -45,13 +38,11 @@ setuptools.setup(
|
||||
"Development Status :: 4 - Beta",
|
||||
"License :: OSI Approved :: " + get_data("license"),
|
||||
"Programming Language :: Python :: 3.8",
|
||||
"Programming Language :: Python :: 3.9",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Natural Language :: English",
|
||||
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
||||
"Intended Audience :: Science/Research",
|
||||
],
|
||||
install_requires=get_requirements(),
|
||||
install_requires=["scikit-learn"],
|
||||
test_suite="mufs.tests",
|
||||
zip_safe=False,
|
||||
)
|
||||
|
@@ -1,4 +0,0 @@
|
||||
sonar.projectKey=mufs
|
||||
sonar.sourceEncoding=UTF-8
|
||||
sonar.sources=.
|
||||
sonar.python.version=3.8, 3.9, 3.10
|
Reference in New Issue
Block a user