Skip to content

Commit

Permalink
Merge branch 'release/tok'
Browse files Browse the repository at this point in the history
  • Loading branch information
cnheider committed Sep 14, 2020
2 parents 7526d26 + ab08d13 commit 086b2e5
Show file tree
Hide file tree
Showing 11 changed files with 3,705 additions and 3,494 deletions.
File renamed without changes.
15 changes: 15 additions & 0 deletions .github/FUNDING.yml
@@ -0,0 +1,15 @@

# These are supported funding model platforms

github: [cnheider]
patreon: cnheider
open_collective: cnheider
ko_fi: cnheider
custom: # Replace with a single custom sponsorship URL


tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
27 changes: 27 additions & 0 deletions .github/workflows/disabled/stale.yml
@@ -0,0 +1,27 @@
name: Mark stale issues and pull requests

on:
workflow_dispatch:
#inputs:
# logLevel:
# description: 'Log level'
# required: true
# default: 'warning'
# tags:
# description: 'Test scenario tags'
#schedule:
# - cron: "0 0 * * *"

jobs:
stale:

runs-on: ubuntu-latest

steps:
- uses: actions/stale@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'Stale issue message'
stale-pr-message: 'Stale pull request message'
stale-issue-label: 'no-issue-activity'
stale-pr-label: 'no-pr-activity'
17 changes: 17 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,17 @@
include requirements*.txt # Include requirements

#include pyproject.toml

# Include the EMDS
#include *.md
#recursive-include . *.md
global-include *.md




# Include the license file
#include LICENSE.txt

# Include the data files
#recursive-include data *
1 change: 1 addition & 0 deletions munin/README.md
@@ -0,0 +1 @@
# Munin
5 changes: 5 additions & 0 deletions munin/__init__.py
Expand Up @@ -22,6 +22,11 @@
@author: cnheider
"""

import pathlib

with open(pathlib.Path(__file__).parent / "README.md", "r") as this_init_file:
__doc__ += this_init_file.read()

import pkg_resources

# __all__ = ['PROJECT_APP_PATH', 'PROJECT_NAME', 'PROJECT_VERSION', 'get_version']
Expand Down
6,726 changes: 3,400 additions & 3,326 deletions munin/classification_report.html

Large diffs are not rendered by default.

90 changes: 53 additions & 37 deletions munin/generate_report.py
Expand Up @@ -3,13 +3,13 @@
import pathlib
from collections import namedtuple

import draugr
import numpy
from apppath import ensure_existence
from munin.utilities.html_embeddings import MetricEntry, generate_metric_table, plt_html, plt_html_svg
from sklearn.multiclass import OneVsRestClassifier
from sklearn.preprocessing import LabelBinarizer

import draugr
from munin.utilities.html_embeddings import generate_metrics, plt_html, plt_html_svg

ReportEntry = namedtuple("ReportEntry", ("name", "figure", "prediction", "truth", "outcome", "explanation"))

__author__ = "Christian Heider Nielsen"
Expand All @@ -21,37 +21,41 @@


def generate_html(
file_name, template_page="classification_report_template.html", template_path=None, **kwargs
):
if not template_path:
template_path = pathlib.Path(__file__).parent / "templates"
file_name,
template_page: str = "classification_report_template.html",
template_path: pathlib.Path = None,
**kwargs
):
if not template_path:
template_path = pathlib.Path(__file__).parent / "templates"

from jinja2 import Environment, select_autoescape, FileSystemLoader
from jinja2 import Environment, select_autoescape, FileSystemLoader

env = Environment(
loader=FileSystemLoader(str(template_path)), autoescape=select_autoescape(["html", "xml"])
)
template = env.get_template(template_page)
with open(f"{file_name}.html", "w") as f:
f.writelines(template.render())
with open(f"{file_name}.html", "w", encoding="utf-8") as f:
f.writelines(Environment(loader=FileSystemLoader(str(template_path)),
autoescape=select_autoescape(["html", "xml"])
).get_template(template_page).render(**kwargs))


def generate_pdf(file_name):
import pdfkit
import pdfkit

pdfkit.from_file(f"{file_name}.html", f"{file_name}.pdf")
pdfkit.from_file(f"{file_name}.html", f"{file_name}.pdf")


if __name__ == "__main__":
def a(title: str = "Classification Report", out_path=pathlib.Path.cwd() / 'exclude', num_classes=3):

from matplotlib import pyplot

do_generate_pdf = False
pyplot.rcParams["figure.figsize"] = (3, 3)
from warg.named_ordered_dictionary import NOD

data_path = pathlib.Path.home()
num_classes = 3
ensure_existence(out_path)

file_name = out_path / title.lower().replace(" ", "_")

cell_width = (800 / num_classes) - 6 - 6 * 2

pyplot.plot(numpy.random.random((3, 3)))
Expand All @@ -63,7 +67,7 @@ def generate_pdf(file_name):
truth="b",
outcome="fp",
explanation=None,
)
)

pyplot.plot(numpy.ones((9, 3)))

Expand All @@ -74,7 +78,7 @@ def generate_pdf(file_name):
truth="c",
outcome="fp",
explanation=None,
)
)

pyplot.plot(numpy.ones((5, 6)))

Expand All @@ -85,7 +89,7 @@ def generate_pdf(file_name):
truth="a",
outcome="tp",
explanation=None,
)
)

d = ReportEntry(
name="fas3",
Expand All @@ -94,7 +98,7 @@ def generate_pdf(file_name):
truth="a",
outcome="tp",
explanation=None,
)
)

e = ReportEntry(
name="fas3",
Expand All @@ -103,7 +107,7 @@ def generate_pdf(file_name):
truth="c",
outcome="tn",
explanation=plt_html(format="svg", size=[cell_width, cell_width]),
)
)

from sklearn import svm, datasets
from sklearn.model_selection import train_test_split
Expand All @@ -126,22 +130,34 @@ def generate_pdf(file_name):
y_p_max = y_pred.argmax(axis=-1)
y_t_max = y_test.argmax(axis=-1)

draugr.plot_confusion_matrix(y_t_max, y_p_max, class_names=class_names)

title = "Classification Report"
confusion_matrix = plt_html(format="png", size=[800, 800])
confusion_matrix = plt_html(draugr.confusion_matrix_plot(y_t_max,
y_p_max, category_names=class_names),
format="png",
size=[800, 800])
predictions = [[GPU_STATS, b, d], [GPU_STATS, c, d], [GPU_STATS, c, b], [c, b, e]]

metric_fields, metrics = generate_metrics(y_t_max, y_p_max, class_names)

draugr.roc_plot(y_pred, y_test, n_classes)

roc_figure = plt_html(format="png", size=[800, 800])

bundle = NOD.nod_of(title, confusion_matrix, metric_fields, metrics, predictions, roc_figure)

file_name = title.lower().replace(" ", "_")
metrics = generate_metric_table(y_t_max,
y_p_max,
class_names)
metric_fields = ('Metric', *MetricEntry._fields)

roc_figure = plt_html(draugr.roc_plot(y_pred,
y_test,
n_classes),
format="png",
size=[800, 800])

bundle = NOD.nod_of(title,
confusion_matrix,
metric_fields,
metrics,
predictions,
roc_figure
)

generate_html(file_name, **bundle)
if do_generate_pdf:
generate_pdf(file_name)
generate_pdf(file_name)


a()

0 comments on commit 086b2e5

Please sign in to comment.