generated from LufsX/Experiment-LogReg
This commit is contained in:
+1
-6
@@ -1,5 +1,6 @@
|
||||
import numpy as np
|
||||
from sklearn.tree import DecisionTreeClassifier
|
||||
|
||||
"""
|
||||
实验说明:
|
||||
- 自行编写实现数据加载与预测病马死亡的对率回归算法。
|
||||
@@ -16,8 +17,6 @@ from sklearn.tree import DecisionTreeClassifier
|
||||
id = "202210423208"
|
||||
name = "刘义天"
|
||||
|
||||
|
||||
|
||||
# 加载数据并添加非线性特征
|
||||
def load_data(filepath):
|
||||
"""
|
||||
@@ -55,7 +54,6 @@ def load_data(filepath):
|
||||
|
||||
return X, y
|
||||
|
||||
|
||||
# 对率回归训练函数
|
||||
def train_logreg(X, y, learning_rate=0.01, num_iterations=1000, regularization_strength=0):
|
||||
"""
|
||||
@@ -79,7 +77,6 @@ def train_logreg(X, y, learning_rate=0.01, num_iterations=1000, regularization_s
|
||||
weights -= learning_rate * gradient
|
||||
return weights
|
||||
|
||||
|
||||
# 决策树训练函数
|
||||
def train_decision_tree(X, y):
|
||||
"""
|
||||
@@ -96,7 +93,6 @@ def train_decision_tree(X, y):
|
||||
clf.fit(X, y)
|
||||
return clf
|
||||
|
||||
|
||||
# 对率回归预测函数
|
||||
def predict_logreg(inX, weights):
|
||||
"""
|
||||
@@ -112,7 +108,6 @@ def predict_logreg(inX, weights):
|
||||
probability = 1 / (1 + np.exp(-np.dot(inX, weights)))
|
||||
return 1 if probability >= 0.4 else 0
|
||||
|
||||
|
||||
# 融合预测函数
|
||||
def predict_fusion(inX, weights, clf):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user