generated from LufsX/Experiment-LogReg
This commit is contained in:
-33
@@ -26,16 +26,6 @@ name = "刘义天"
|
||||
|
||||
|
||||
def load_data(filepath):
|
||||
"""
|
||||
Load data from a specified file path and handle missing values.
|
||||
|
||||
Args:
|
||||
- filepath (str): The path to the data file.
|
||||
|
||||
Returns:
|
||||
- np.array: Feature data.
|
||||
- np.array: Label data.
|
||||
"""
|
||||
data = []
|
||||
with open(filepath, 'r') as file:
|
||||
for line in file:
|
||||
@@ -54,19 +44,6 @@ def load_data(filepath):
|
||||
|
||||
|
||||
def train_logreg(X, y, learning_rate=0.1, n_estimators=200, max_depth=5):
|
||||
"""
|
||||
Train a Gradient Boosting model.
|
||||
|
||||
Args:
|
||||
- X (numpy array): Feature data.
|
||||
- y (numpy array): Label data.
|
||||
- learning_rate (float): Learning rate for gradient boosting.
|
||||
- n_estimators (int): Number of trees.
|
||||
- max_depth (int): Maximum depth of each tree.
|
||||
|
||||
Returns:
|
||||
- tuple: (Trained model and scaler) packed into 'weights' for predict_logreg compatibility.
|
||||
"""
|
||||
scaler = StandardScaler()
|
||||
X = scaler.fit_transform(X)
|
||||
|
||||
@@ -83,16 +60,6 @@ def train_logreg(X, y, learning_rate=0.1, n_estimators=200, max_depth=5):
|
||||
|
||||
|
||||
def predict_logreg(inX, weights):
|
||||
"""
|
||||
Predict the class label for a given sample using Gradient Boosting.
|
||||
|
||||
Args:
|
||||
- inX (numpy array): Input sample for classification.
|
||||
- weights (tuple): Packed tuple containing trained model and scaler.
|
||||
|
||||
Returns:
|
||||
- int: Predicted class label (0 or 1).
|
||||
"""
|
||||
model, scaler = weights # Unpack model and scaler
|
||||
inX = scaler.transform([inX]) # Scale input
|
||||
prediction = model.predict(inX)
|
||||
|
||||
Reference in New Issue
Block a user