File size: 1,580 Bytes
8c348c5
29cce3f
8c348c5
29cce3f
 
 
 
 
 
 
 
 
 
 
 
 
8c348c5
 
 
 
 
29cce3f
 
 
 
 
 
 
 
 
8c348c5
 
 
 
29cce3f
8c348c5
 
29cce3f
8c348c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29cce3f
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from typing import Callable
import pandas as pd
import numpy as np


class NN:
    def __init__(
        self,
        epochs: int,
        hidden_size: int,
        learning_rate: float,
        test_size: float,
        activation: str,
        features: list[str],
        target: str,
        data: str,

        wh: np.array,
        wo: np.array,
        bh: np.array,
        bo: np.array,
    ):
        self.epochs = epochs
        self.hidden_size = hidden_size
        self.learning_rate = learning_rate
        self.test_size = test_size
        self.activation = activation
        self.features = features
        self.target = target
        self.data = data
        self.wh: np.array = wh
        self.wo: np.array = wo
        self.bh: np.array = bh
        self.bo: np.array = bo

        self.func_prime: Callable = None
        self.func: Callable = None
        self.df: pd.DataFrame = None
        self.X: pd.DataFrame = None
        self.y: pd.DataFrame = None

    def read_csv(self) -> dict[str, str]:
        self.df = pd.read_csv(self.data)
        self.X = self.df[self.features]
        self.y = self.df[self.target]

    def set_func(self, f: Callable) -> None:
        assert isinstance(f, Callable)
        self.func = f

    def set_func_prime(self, f: Callable) -> None:
        assert isinstance(f, Callable)
        self.func_prime = f

    @classmethod
    def from_dict(cls, dct):
        """ Creates an instance of NN given a dictionary
        we can use this to make sure that the arguments are right
        """
        return cls(**dct)