更新 function.py
Gitea Actions Experiment Test / Experiment-Actions (push) Successful in 11s

This commit is contained in:
2024-11-02 15:57:27 +08:00
parent d73552e103
commit 49d7b0c7e8
+10 -1
View File
@@ -38,7 +38,7 @@ def load_data(filepath):
data = np.genfromtxt(filepath, delimiter=delimiter, missing_values='?', filling_values=np.nan)
# Check if the data has been loaded correctly with at least two dimensions
if data.ndim < 2 or data.size == 0:
if data.ndim < 2 or data.shape[1] < 2: # 至少需要两列:特征和标签
continue # 尝试下一个分隔符
# Remove rows with NaN values
@@ -53,6 +53,14 @@ def load_data(filepath):
X = data[:, :-1] # Features
y = data[:, -1] # Labels
# Check if shapes of X and y match
if X.shape[0] != y.shape[0]:
print(f"Error: Feature and label count mismatch in file '{filepath}'")
return None, None
# 输出数据形状供检查
print(f"Loaded data from '{filepath}': {X.shape[0]} samples, {X.shape[1]} features.")
return X, y
except Exception as e:
print(f"Error loading data with delimiter '{delimiter}': {e}")
@@ -111,3 +119,4 @@ def predict_logreg(X, weights):
X = np.c_[np.ones(X.shape[0]), X] # Add intercept term
probabilities = sigmoid(np.dot(X, weights))
return (probabilities >= 0.5).astype(int)