Source code for qlauncher.problems.problem_initialization.tabular_ml

 1import numpy as np
 2from qlauncher.base import Problem
 3
 4
[docs] 5class TabularML(Problem): 6 def __init__(self, X: np.ndarray, y: np.ndarray | None = None, instance_name: str = 'unnamed') -> None: 7 super().__init__((X, y), instance_name) 8 9 @property 10 def setup(self) -> dict: 11 X, y = self.instance 12 return { 13 'X_shape': X.shape, 14 'y_shape': y.shape if y is not None else None, 15 'instance_name': self.instance_name 16 } 17
[docs] 18 @staticmethod 19 def from_preset(instance_name: str, **kwargs) -> 'TabularML': 20 match instance_name: 21 case 'default': 22 return TabularML( 23 np.array([ 24 [5.2, 3.1], 25 [11.3, 2.2], 26 [9.8, 10.5], 27 [2.1, 1.9], 28 [12.0, 15.2], 29 [6.4, 9.9], 30 [0.0, 11.1], 31 [10.1, 10.2], 32 [8.8, 7.7], 33 [13.3, 0.4] 34 ]), 35 np.array([ 36 0, 37 1, 38 1, 39 0, 40 1, 41 0, 42 1, 43 1, 44 0, 45 1 46 ]), 47 instance_name=instance_name 48 ) 49 raise ValueError()
50
[docs] 51 def visualize(self): 52 X, y = self.instance 53 print(f"Tabular ML problem '{self.name}'") 54 print(X[:10]) 55 print(y[:10] if y is not None else 'No target variable')