generated from LufsX/Experiment-LogReg
This commit is contained in:
+4
-2
@@ -73,7 +73,7 @@ def predict_logreg(X, weights):
|
|||||||
z = np.dot(X, weights)
|
z = np.dot(X, weights)
|
||||||
h = sigmoid(z)
|
h = sigmoid(z)
|
||||||
return np.where(h >= 0.5, 1, 0)
|
return np.where(h >= 0.5, 1, 0)
|
||||||
|
|
||||||
def load_data(filepath):
|
def load_data(filepath):
|
||||||
data, labels = [], []
|
data, labels = [], []
|
||||||
with open(filepath, 'r') as f:
|
with open(filepath, 'r') as f:
|
||||||
@@ -103,7 +103,9 @@ def load_data(filepath):
|
|||||||
|
|
||||||
return data, target_variable
|
return data, target_variable
|
||||||
|
|
||||||
|
def accuracy(X, y, weights):
|
||||||
|
predictions = predict_logreg(X, weights)
|
||||||
|
return np.mean(predictions == y)
|
||||||
|
|
||||||
# 其余代码保持不变
|
# 其余代码保持不变
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user