Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lightwood/__about__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__title__ = 'lightwood'
__package_name__ = 'lightwood'
__version__ = '25.9.1.0'
__version__ = '25.12.1.0'
__description__ = "Lightwood is a toolkit for automatic machine learning model building"
__email__ = "community@mindsdb.com"
__author__ = 'MindsDB Inc'
Expand Down
2 changes: 1 addition & 1 deletion lightwood/api/json_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ def add_implicit_values(json_ai: JsonAI) -> JsonAI:
mixers[i]["args"]["fit_on_dev"] = mixers[i]["args"].get("fit_on_dev", "True")
mixers[i]["args"]["use_stl"] = mixers[i]["args"].get("use_stl", "False")

elif mixers[i]["module"] in ("NHitsMixer", "GluonTSMixer"):
elif mixers[i]["module"] in ("NHitsMixer", ):
mixers[i]["args"]["horizon"] = "$problem_definition.timeseries_settings.horizon"
mixers[i]["args"]["window"] = "$problem_definition.timeseries_settings.window"
mixers[i]["args"]["ts_analysis"] = mixers[i]["args"].get(
Expand Down
28 changes: 8 additions & 20 deletions lightwood/ensemble/best_of.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
from lightwood.api.types import PredictionArguments, SubmodelData
from lightwood.data.encoded_ds import EncodedDs

# special dispatches
from lightwood.mixer import GluonTSMixer # imported from base mixer folder as it needs optional dependencies


class BestOf(BaseEnsemble):
"""
Expand All @@ -25,24 +22,19 @@ class BestOf(BaseEnsemble):
def __init__(self, target, mixers: List[BaseMixer], data: EncodedDs, accuracy_functions,
args: PredictionArguments, ts_analysis: Optional[dict] = None, fit: bool = True) -> None:
super().__init__(target, mixers, data, fit=False)
self.special_dispatch_list = [GluonTSMixer]

if fit:
score_list = []
for _, mixer in enumerate(self.mixers):
score_dict = evaluate_accuracies(
data.data_frame,
mixer(data, args)['prediction'],
target,
accuracy_functions,
ts_analysis=ts_analysis
)

if type(mixer) in self.special_dispatch_list:
avg_score = self.special_dispatch(mixer, data, args, target, ts_analysis)
else:
score_dict = evaluate_accuracies(
data.data_frame,
mixer(data, args)['prediction'],
target,
accuracy_functions,
ts_analysis=ts_analysis
)

avg_score = np.mean(list(score_dict.values()))
avg_score = np.mean(list(score_dict.values()))
log.info(f'Mixer: {type(mixer).__name__} got accuracy: {avg_score}')

if is_nan_numeric(avg_score):
Expand Down Expand Up @@ -81,7 +73,3 @@ def __call__(self, ds: EncodedDs, args: PredictionArguments) -> pd.DataFrame:
else:
log.warning(f'Unstable mixer {type(mixer).__name__} failed with exception: {e}.\
Trying next best')

def special_dispatch(self, mixer, data, args, target, ts_analysis):
if isinstance(mixer, GluonTSMixer):
return mixer.model_train_stats.loss_history[-1]
8 changes: 0 additions & 8 deletions lightwood/helpers/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@
import torch
import numpy as np

try:
import mxnet as mx
except Exception:
mx = None


def seed(seed_nr: int) -> None:
torch.manual_seed(seed_nr)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
np.random.seed(seed_nr)
random.seed(seed_nr)

if mx is not None:
mx.random.seed(seed_nr)
19 changes: 16 additions & 3 deletions lightwood/helpers/templating.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from typing import Callable
from collections import deque

Expand All @@ -8,11 +9,23 @@


def is_allowed(v):
if '(' in str(v):
if isinstance(v, dict):
# this required for compatability with nuimpy v1 and v2:
# v1: str({np.float64(1.5): np.float64(1.5)}) = {1.5: 1.5}
# v2: str({np.float64(1.5): np.float64(1.5)}) = {np.float64(1.5): np.float64(1.5)}
# v2: json.dumps({np.float64(1.5): np.float64(1.5)}) = {"1.5": 1.5}
try:
s = json.dumps(v)
except Exception:
s = str(v)
else:
s = str(v)

if '(' in s:
return False
if 'lambda' in str(v):
if 'lambda' in s:
return False
if '__' in str(v):
if '__' in s:
return False

return True
Expand Down
7 changes: 1 addition & 6 deletions lightwood/mixer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
except Exception:
ProphetMixer = None

try:
from lightwood.mixer.gluonts import GluonTSMixer
except Exception:
GluonTSMixer = None

try:
from lightwood.mixer.lightgbm import LightGBM
from lightwood.mixer.lightgbm_array import LightGBMArray
Expand All @@ -43,5 +38,5 @@
TabTransformerMixer = None

__all__ = ['BaseMixer', 'Neural', 'NeuralTs', 'LightGBM', 'RandomForest', 'LightGBMArray', 'Unit', 'Regression',
'SkTime', 'QClassic', 'ProphetMixer', 'ETSMixer', 'ARIMAMixer', 'NHitsMixer', 'GluonTSMixer', 'XGBoostMixer',
'SkTime', 'QClassic', 'ProphetMixer', 'ETSMixer', 'ARIMAMixer', 'NHitsMixer', 'XGBoostMixer',
'TabTransformerMixer', 'XGBoostArrayMixer']
Loading