generated from LufsX/Experiment-LogReg
This commit is contained in:
+4
-11
@@ -1,5 +1,6 @@
|
||||
# function.py
|
||||
import numpy as np
|
||||
from sklearn.preprocessing import MinMaxScaler
|
||||
from sklearn.model_selection import train_test_split
|
||||
|
||||
"""
|
||||
实验说明:
|
||||
@@ -17,17 +18,8 @@ import numpy as np
|
||||
- numpy: 2.1.1
|
||||
"""
|
||||
|
||||
|
||||
"""
|
||||
请在这里填写学号和姓名,不填写即成绩无效。
|
||||
"""
|
||||
id = "202210423130"
|
||||
name = "董秋"
|
||||
# 这里写自己的代码实现
|
||||
import numpy as np
|
||||
from sklearn.preprocessing import MinMaxScaler
|
||||
from sklearn.model_selection import train_test_split
|
||||
|
||||
|
||||
def sigmoid(z):
|
||||
return 1.0 / (1 + np.exp(-z))
|
||||
@@ -85,6 +77,7 @@ def load_data(filepath):
|
||||
|
||||
data = np.array(data)
|
||||
labels = np.array(labels)
|
||||
|
||||
# 将标签二分类化,2和3为0,其余为1
|
||||
target_variable = np.where((labels == 2) | (labels == 3), 0, 1)
|
||||
|
||||
@@ -119,4 +112,4 @@ if __name__ == "__main__":
|
||||
|
||||
# 测试模型
|
||||
final_test_accuracy = accuracy(X_test, y_test, final_weights)
|
||||
print(f"最终测试集的准确率: {final_test_accuracy:.4f}")
|
||||
print(f"最终测试集的准确率: {final_test_accuracy:.4f}")
|
||||
|
||||
Reference in New Issue
Block a user