Logistic Regression Task
Importing Necessary Packages
import numpy as np
import pandas
import 2pm.dataset
from 2pm import 2PMNode
from 2pm.statsmodel import LogitTaskDefining the Logistic Regression Task
class SpectorLogitTask(LogitTask):
def __init__(self) -> None:
super().__init__(
name="spector_logit", # Task name
min_clients=2, # Minimum required number of clients, at least 2
max_clients=3, # Maximum supported number of clients, must be greater than or equal to min_clients
wait_timeout=5, # Wait timeout to control the timeout for a round of computation
connection_timeout=5, # Connection timeout to control the timeout for each phase in the process
verify_timeout=500, # Verification timeout to control the timeout for the zero-knowledge proof stage
enable_verify=True # Whether to enable the zero-knowledge proof stage after task completion
)
def dataset(self):
"""
Define the data required for the task.
Output: Dictionary, keys are the names of the data, which must correspond with the parameter names in the preprocess method.
"""
return {
"data": 2pm.dataset.DataFrame("spector.csv"),
}
def preprocess(self, data: pandas.DataFrame):
"""
Preprocessing function to process the dataset and split it into features (x) and labels (y).
Input: Corresponds with the return value of the dataset method
Output: Features (x) and labels (y)
"""
names = data.columns
y_name = names[3]
y = data[y_name].copy() # type: ignore
x = data.drop([y_name], axis=1)
return x, y
def options(self):
"""
Optional method to configure the training for the logistic regression task.
Output: Dictionary, training configuration options for the logistic regression task.
"""
return {
"maxiter": 35, # Maximum number of training iterations, default is 35
"method": "newton", # Training method, current option is "newton"
"start_params": None, # Initial weights for logistic regression, default is None. If None, weights are initialized to zero
"ord": np.inf, # Coefficient related to the newton method. Order of the gradient norm
"tol": 1e-8, # Coefficient related to the newton method. Tolerance for stopping the training
"ridge_factor": 1e-10, # Coefficient related to the newton method. Ridge regression coefficient
}
Task Configuration
Dataset
Data Preprocessing
Logistic Regression Options
Specifying the API for the 2PM Node to Execute Tasks
Last updated