generated from LufsX/Experiment-LogReg
This commit is contained in:
+8
-4
@@ -28,9 +28,6 @@ name = "Tanjunfeng"
|
||||
|
||||
# 这里写自己的代码实现
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
def sigmoid(z):
|
||||
return 1 / (1 + np.exp(-z))
|
||||
|
||||
@@ -91,6 +88,12 @@ def load_data(filepath):
|
||||
- np.array: 标签数据。
|
||||
"""
|
||||
data = np.genfromtxt(filepath, delimiter=' ', dtype=np.float64)
|
||||
|
||||
# 处理缺失值,这里简单使用均值填充(仅为示例,可根据实际情况调整)
|
||||
column_means = np.nanmean(data, axis=0)
|
||||
inds = np.where(np.isnan(data))
|
||||
data[inds] = np.take(column_means, inds[1])
|
||||
|
||||
X = data[:, :-1]
|
||||
y = data[:, -1].reshape(-1, 1)
|
||||
return X, y
|
||||
@@ -109,4 +112,5 @@ if __name__ == "__main__":
|
||||
|
||||
# 测试单个数据
|
||||
y_pred = predict_logreg(X_test[11], weights)
|
||||
print(f"预测结果: {y_pred}, 实际结果: {y_test[11]}")
|
||||
print(f"预测结果: {y_pred}, 实际结果: {y_test[11]}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user