generated from LufsX/Experiment-LogReg
This commit is contained in:
+18
-2
@@ -17,6 +17,7 @@ id = "202210423208"
|
|||||||
name = "刘义天"
|
name = "刘义天"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 加载数据并添加非线性特征
|
# 加载数据并添加非线性特征
|
||||||
def load_data(filepath):
|
def load_data(filepath):
|
||||||
"""
|
"""
|
||||||
@@ -96,6 +97,22 @@ def train_decision_tree(X, y):
|
|||||||
return clf
|
return clf
|
||||||
|
|
||||||
|
|
||||||
|
# 对率回归预测函数
|
||||||
|
def predict_logreg(inX, weights):
|
||||||
|
"""
|
||||||
|
对率回归预测函数。
|
||||||
|
|
||||||
|
Args:
|
||||||
|
- inX (numpy array): 输入待分类的样本。
|
||||||
|
- weights (numpy array): 训练得到的权重。
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
- int: 预测的分类标签。
|
||||||
|
"""
|
||||||
|
probability = 1 / (1 + np.exp(-np.dot(inX, weights)))
|
||||||
|
return 1 if probability >= 0.4 else 0
|
||||||
|
|
||||||
|
|
||||||
# 融合预测函数
|
# 融合预测函数
|
||||||
def predict_fusion(inX, weights, clf):
|
def predict_fusion(inX, weights, clf):
|
||||||
"""
|
"""
|
||||||
@@ -110,8 +127,7 @@ def predict_fusion(inX, weights, clf):
|
|||||||
- int: 最终预测的分类标签。
|
- int: 最终预测的分类标签。
|
||||||
"""
|
"""
|
||||||
# 对率回归预测
|
# 对率回归预测
|
||||||
probability_logreg = 1 / (1 + np.exp(-np.dot(inX, weights)))
|
prediction_logreg = predict_logreg(inX, weights)
|
||||||
prediction_logreg = 1 if probability_logreg >= 0.4 else 0
|
|
||||||
|
|
||||||
# 决策树预测
|
# 决策树预测
|
||||||
prediction_tree = clf.predict(inX.reshape(1, -1))[0]
|
prediction_tree = clf.predict(inX.reshape(1, -1))[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user