Source code for qlauncher.problems.other.tabular_ml

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