Source code for wip.modules.model_module
from __future__ import annotations
import itertools
from pathlib import Path
from typing import List
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from sklearn.metrics import mean_squared_error, r2_score
from sklearn.model_selection import KFold
[docs]def format_key(key):
if "_" in key:
return "".join(s[0].upper() for s in key.split("_"))
return key[:4]
[docs]def format_value(value):
if value:
return "Y"
if not value:
return "N"
return "-" if value is None else value
[docs]def params_to_str(params: dict, exclude: List[str] | str | None = None) -> str:
"""Convert a dictionary to string.
Function
Parameters
----------
params : dict
Dictionary to convert.
exclude: List[str] | str | None, optional
Keys to exclude from the string conversion.
When ``None`` (default), excludes keys: ``"random_state"``, ``"seed"``.
Returns
-------
str
Dictionary converted to string. Keys are separated by ``;``.
"""
if exclude is None:
exclude = {"random_state", "seed"}
elif isinstance(exclude, str):
exclude = {exclude}
return ";".join(
f"{format_key(key)}={format_value(value)}"
for key, value in params.items()
if key not in exclude
)