Open uozveren opened 2 months ago
Hi, might be good to run a baseline model (say linear regression, MLP) to see how that performs. And then we can have a sense of how hard this problem is, and have a sense of whether it's your implementation error or it's KAN's problem.
I am currently employing the KAN model for a basic engineering regression problem and have observed unexpectedly low R^2 scores, even for the simplest configurations. Given this, I suspect there might be an issue with the implementation in my script.
Would you be able to review my code to identify any potential errors or suggest improvements? I have attached the script for your reference. Any insights or recommendations you could provide would be greatly appreciated as I aim to optimize the model's performance.
@import pandas as pd import torch from kan import KAN from sklearn.model_selection import train_test_split from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score, explained_variance_score, max_error import tkinter as tk from tkinter import filedialog
def load_data(): root = tk.Tk() root.withdraw() # GUI ekranını gizle filepath = filedialog.askopenfilename(title="Excel dosyası seçin", filetypes=(("Excel files", ".xlsx .xls"), ("All files", "."))) root.destroy() if not filepath: print("Dosya seçilmedi.") return None, None data = pd.read_excel(filepath) X = data.iloc[:, :-1].values
y = data.iloc[:, -1].values return X, y
def train_and_evaluate(X, y): X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=42) X_train = torch.tensor(X_train, dtype=torch.float32) X_test = torch.tensor(X_test, dtype=torch.float32) y_train = torch.tensor(y_train, dtype=torch.float32).view(-1, 1) y_test = torch.tensor(y_test, dtype=torch.float32).view(-1, 1)
def print_metrics(true_values, predicted_values, dataset_type): mse = mean_squared_error(true_values, predicted_values) mae = mean_absolute_error(true_values, predicted_values) r2 = r2_score(true_values, predicted_values) evs = explained_variance_score(true_values, predicted_values) max_err = max_error(true_values, predicted_values)
def main(): X, y = load_data() if X is not None and y is not None: train_and_evaluate(X, y)
if name == "main": main()