Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pykan == 0.2.6 Cann't load ?? with my code but tutorial is work!! #473

Open
THEFLASHFORD opened this issue Oct 3, 2024 · 1 comment
Open

Comments

@THEFLASHFORD
Copy link

class KAN_Regressor(Model):
def init(self , grid=3, k=3, steps=10, **kwargs) -> None:
super().init(eliminate_duplicates=False, eliminate_duplicates_eps=1e-8, **kwargs)
self.dataset = {}
self.model = None
self.model_list = []
self.grid = grid
self.k = k
self.steps = steps

def fit(self,X,y):
    if self.model is None:
        model = KAN(width=[X.shape[1],2,2], grid=self.grid, k=self.k,seed=0, device=device)
        self.model = model

    model = copy.deepcopy(self.model)

    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.8)
    self.dataset['train_input'] = torch.from_numpy(X_train)
    self.dataset['test_input'] = torch.from_numpy(X_test)
    self.dataset['train_label'] = torch.from_numpy(y_train[:,None])
    self.dataset['test_label'] = torch.from_numpy(y_test[:,None])

    try:
        model.fit(self.dataset, opt="LBFGS", steps=self.steps)
    except:
        model = self.model_list[-1]

    self.model_list.append(model)    

def predict(self,X):
    model = self.model_list[-1]
    return model(torch.from_numpy(X)).detach().numpy()

Screenshot 2024-10-03 192526
image

@THEFLASHFORD
Copy link
Author

Oh, i forgot it some line code lol

torch.set_default_dtype(torch.float64)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant