22 Commits

Author SHA1 Message Date
0fdd754050 Add constant features treatment 2023-10-13 13:35:24 +02:00
7035cc4edc Update readme 2022-05-19 17:52:54 +02:00
edc8816041 Update Setup and __init__ 2022-05-19 17:46:00 +02:00
20db8c5745 Add version to _version file, method and test 2022-05-19 17:36:59 +02:00
a9384685fe Clean main.yml 2022-05-19 17:27:40 +02:00
86aaf23dd9 Patch main.yml 2022-05-19 17:18:45 +02:00
9395e8cc23 Patch main.yml 2022-05-19 17:08:44 +02:00
5723da9535 Patch main.yml 2022-05-19 16:46:25 +02:00
fb4ed468b0 Patch main.yml 2022-05-19 16:37:19 +02:00
57334a0b74 Patch main.yml 2022-05-19 16:31:37 +02:00
c47f69847e Patch main.yml 2022-05-19 16:22:31 +02:00
4532309309 Patch main.yml 2022-05-19 16:09:36 +02:00
aa53e3dbc0 update main.yml 2022-05-19 14:22:10 +02:00
2861e22c57 Update main using checkout@v3 2022-05-19 12:53:14 +02:00
e0acd6d239 Update main.yml 2022-05-19 12:30:29 +02:00
3d98a39d4b Update sonar.sources 2022-05-19 11:57:44 +02:00
1a4de38328 Update sonar.project.properties 2022-05-19 11:52:23 +02:00
a9c40f1fb7 Fix issue in gh action 2022-05-19 11:46:48 +02:00
81da48ec31 Fix format issue 2022-05-19 11:41:09 +02:00
2548ab8533 Update formatter version 2022-05-19 11:37:45 +02:00
08cade5dec Add sonarqube scanner to gh actions 2022-05-19 11:21:55 +02:00
0a13f5e5eb Update main.yml requirements 2022-05-19 01:20:11 +02:00
11 changed files with 73 additions and 21 deletions

View File

@@ -12,11 +12,13 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
os: [macos-latest, ubuntu-latest] os: [ubuntu-latest]
python: [3.8] python: ["3.10"]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python }} - name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v2 uses: actions/setup-python@v2
with: with:
@@ -26,14 +28,37 @@ jobs:
pip install -q --upgrade pip pip install -q --upgrade pip
pip install -q cython pip install -q cython
pip install -q numpy pip install -q numpy
pip install -q git+git://github.com/doctorado-ml/mdlp pip install -q git+https://github.com/doctorado-ml/mdlp
pip install -q -r requirements/dev.txt pip install -q -r requirements/dev.txt
pip install -q --upgrade codecov coverage black flake8 codacy-coverage pip install -q --upgrade codecov coverage black flake8 codacy-coverage unittest-xml-reporting
- name: Lint - name: Lint
run: | run: |
black --check --diff mufs black --check --diff mufs
flake8 --count mufs flake8 --count mufs
- name: Tests & coverage - name: Tests & coverage
run: | run: |
coverage run -m unittest -v mufs.tests mkdir .report
coverage run -m xmlrunner -v mufs.tests -o .report
coverage xml -i -o .report/coverage.xml
coverage report -m --fail-under=100 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 }}

View File

@@ -1,12 +1,12 @@
repos: repos:
- repo: https://github.com/ambv/black - repo: https://github.com/ambv/black
rev: 20.8b1 rev: 22.3.0
hooks: hooks:
- id: black - id: black
exclude: ".virtual_documents" exclude: ".virtual_documents"
language_version: python3.8 language_version: python3.8
- repo: https://gitlab.com/pycqa/flake8 - repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4 rev: 3.9.2
hooks: hooks:
- id: flake8 - id: flake8
exclude: ".virtual_documents" exclude: ".virtual_documents"
@@ -16,7 +16,7 @@ repos:
# - id: mypy # - id: mypy
# # args: [--strict, --ignore-missing-imports] # # args: [--strict, --ignore-missing-imports]
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0 rev: v4.2.0
hooks: hooks:
- id: trailing-whitespace - id: trailing-whitespace
- id: check-case-conflict - id: check-case-conflict

View File

@@ -1,6 +1,6 @@
SHELL := /bin/bash SHELL := /bin/bash
.DEFAULT_GOAL := help .DEFAULT_GOAL := help
.PHONY: coverage deps help lint push test doc build .PHONY: coverage deps help lint push test build
coverage: ## Run tests with coverage coverage: ## Run tests with coverage
coverage erase coverage erase
@@ -26,9 +26,6 @@ build: ## Build package
rm -fr build/* rm -fr build/*
python setup.py sdist bdist_wheel python setup.py sdist bdist_wheel
doc-clean: ## Update documentation
make -C docs --makefile=Makefile clean
help: ## Show help message help: ## Show help message
@IFS=$$'\n' ; \ @IFS=$$'\n' ; \
help_lines=(`fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##/:/'`); \ help_lines=(`fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##/:/'`); \

View File

@@ -2,6 +2,8 @@
[![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) [![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) [![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)
[![PyPI version](https://badge.fury.io/py/MUFS.svg)](https://badge.fury.io/py/MUFS) [![PyPI version](https://badge.fury.io/py/MUFS.svg)](https://badge.fury.io/py/MUFS)
[![Technical Debt](https://haystack.rmontanana.es:25000/api/project_badges/measure?project=mufs&metric=sqale_index&token=1119a3bfd4025d50ef3009a44c600c16670ee31a)](https://haystack.rmontanana.es:25000/dashboard?id=mufs)
[![Quality Gate Status](https://haystack.rmontanana.es:25000/api/project_badges/measure?project=mufs&metric=alert_status&token=1119a3bfd4025d50ef3009a44c600c16670ee31a)](https://haystack.rmontanana.es:25000/dashboard?id=mufs)
![https://img.shields.io/badge/python-3.8%2B-blue](https://img.shields.io/badge/python-3.8%2B-brightgreen) ![https://img.shields.io/badge/python-3.8%2B-blue](https://img.shields.io/badge/python-3.8%2B-brightgreen)
# MUFS # MUFS

View File

@@ -3,6 +3,7 @@ from sys import float_info
from itertools import combinations from itertools import combinations
import numpy as np import numpy as np
from .Metrics import Metrics from .Metrics import Metrics
from ._version import __version__
class MUFS: class MUFS:
@@ -40,6 +41,11 @@ class MUFS:
) )
self._fitted = False self._fitted = False
@staticmethod
def version() -> str:
"""Return the version of the package."""
return __version__
def _initialize(self, X, y): def _initialize(self, X, y):
"""Initialize the attributes so support multiple calls using same """Initialize the attributes so support multiple calls using same
object object
@@ -128,7 +134,7 @@ class MUFS:
k = len(features) k = len(features)
for pair in list(combinations(features, 2)): for pair in list(combinations(features, 2)):
rff += self._compute_su_features(*pair) rff += self._compute_su_features(*pair)
return rcf / sqrt(k + (k ** 2 - k) * rff) return rcf / sqrt(k + (k**2 - k) * rff)
def cfs(self, X, y): def cfs(self, X, y):
"""Correlation-based Feature Selection """Correlation-based Feature Selection
@@ -166,6 +172,10 @@ class MUFS:
id_selected = idx id_selected = idx
merit = merit_new merit = merit_new
candidates.pop() candidates.pop()
if id_selected is None:
# No more features to add all merits are nan because of
# constant features
break
candidates.append(feature_order[id_selected]) candidates.append(feature_order[id_selected])
self._scores.append(merit) self._scores.append(merit)
del feature_order[id_selected] del feature_order[id_selected]

View File

@@ -1,9 +1,8 @@
from .Selection import MUFS from .Selection import MUFS
__version__ = "0.1.2"
__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-2022, Ricardo Montañana Gómez"
__license__ = "MIT License" __license__ = "MIT License"
__all__ = ["MUFS"] __all__ = ["MUFS"]

1
mufs/_version.py Normal file
View File

@@ -0,0 +1 @@
__version__ = "0.1.3"

View File

@@ -4,8 +4,8 @@ import pandas as pd
import numpy as np import numpy as np
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 MUFS from ..Selection import MUFS
from .._version import __version__
class MUFSTest(unittest.TestCase): class MUFSTest(unittest.TestCase):
@@ -18,6 +18,11 @@ class MUFSTest(unittest.TestCase):
mdlp = MDLP(random_state=1) mdlp = MDLP(random_state=1)
self.X_i = mdlp.fit_transform(self.X_ic, self.y_i).astype("int64") 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): def assertListAlmostEqual(self, list1, list2, tol=7):
self.assertEqual(len(list1), len(list2)) self.assertEqual(len(list1), len(list2))
for a, b in zip(list1, list2): for a, b in zip(list1, list2):

View File

@@ -1,3 +1,3 @@
-r production.txt -r production.txt
mdlp mdlp
pandas pandas

View File

@@ -1,3 +1,4 @@
import os
import setuptools import setuptools
@@ -6,9 +7,10 @@ def readme():
return f.read() return f.read()
def get_data(field: str): def get_data(field):
item = "" item = ""
with open("mufs/__init__.py") as f: file_name = "_version.py" if field == "version" else "__init__.py"
with open(os.path.join("mufs", file_name)) 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 "'"
@@ -19,6 +21,11 @@ def get_data(field: str):
return item return item
def get_requirements():
with open("requirements/production.txt") as f:
return f.read().splitlines()
setuptools.setup( setuptools.setup(
name="MUFS", name="MUFS",
version=get_data("version"), version=get_data("version"),
@@ -38,11 +45,13 @@ setuptools.setup(
"Development Status :: 4 - Beta", "Development Status :: 4 - Beta",
"License :: OSI Approved :: " + get_data("license"), "License :: OSI Approved :: " + get_data("license"),
"Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Natural Language :: English", "Natural Language :: English",
"Topic :: Scientific/Engineering :: Artificial Intelligence", "Topic :: Scientific/Engineering :: Artificial Intelligence",
"Intended Audience :: Science/Research", "Intended Audience :: Science/Research",
], ],
install_requires=["scikit-learn"], install_requires=get_requirements(),
test_suite="mufs.tests", test_suite="mufs.tests",
zip_safe=False, zip_safe=False,
) )

4
sonar-project.properties Normal file
View File

@@ -0,0 +1,4 @@
sonar.projectKey=mufs
sonar.sourceEncoding=UTF-8
sonar.sources=.
sonar.python.version=3.8, 3.9, 3.10