Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def train_fn():
return logistic_classification_learner(target="target",
prediction_column="prediction",
weight_column="w",
params={"random_state": 52})
def train_fn():
return logistic_classification_learner(target="target",
prediction_column="prediction",
weight_column="w",
params={"random_state": 52})
'x1': [10.0, 13.0, 10.0, 13.0, 20, 13],
"x2": [0, 1, 1, 0, 1, 1],
"w": [2, 1, 2, 0.5, 0.5, 3],
'y': [0, 1, 2, 0, 1, 2]
})
df_test_multinomial = pd.DataFrame({
'id': ["id4", "id4", "id5", "id6", "id6", "id7"],
'x1': [12.0, 1000.0, -4.0, 0.0, 0.0, 1],
"x2": [1, 1, 0, 1, 1, 0],
"w": [1, 2, 0, 0.5, 0.1, 2],
'y': [2, 0, 1, 1, 0, 2]
})
# test binomial case
learner_binary = logistic_classification_learner(features=["x1", "x2"],
target="y",
params={"max_iter": 2000})
predict_fn, pred_train, log = learner_binary(df_train_binary)
pred_test = predict_fn(df_test_binary)
expected_col_train = df_train_binary.columns.tolist() + ["prediction"]
expected_col_test = df_test_binary.columns.tolist() + ["prediction"]
assert Counter(expected_col_train) == Counter(pred_train.columns.tolist())
assert Counter(expected_col_test) == Counter(pred_test.columns.tolist())
assert pred_test.prediction.max() < 1
assert pred_test.prediction.min() > 0
assert (pred_test.columns == pred_train.columns).all()
def train_fn():
return logistic_classification_learner(target="target",
prediction_column="prediction",
weight_column="w",
params={"random_state": 52})
predict_fn, pred_train, log = learner_binary(df_train_binary)
pred_test = predict_fn(df_test_binary)
expected_col_train = df_train_binary.columns.tolist() + ["prediction"]
expected_col_test = df_test_binary.columns.tolist() + ["prediction"]
assert Counter(expected_col_train) == Counter(pred_train.columns.tolist())
assert Counter(expected_col_test) == Counter(pred_test.columns.tolist())
assert pred_test.prediction.max() < 1
assert pred_test.prediction.min() > 0
assert (pred_test.columns == pred_train.columns).all()
# test multinomial case
learner_multinomial = logistic_classification_learner(features=["x1", "x2"],
target="y",
params={"multi_class": "multinomial",
"solver": "sag",
"max_iter": 2000},
weight_column="w")
predict_fn, pred_train, log = learner_multinomial(df_train_multinomial)
pred_test = predict_fn(df_test_multinomial)
expected_col_train = df_train_binary.columns.tolist() + ["prediction_0", "prediction_1", "prediction_2",
"prediction"]
expected_col_test = df_test_binary.columns.tolist() + ["prediction_0", "prediction_1", "prediction_2",
"prediction"]
assert Counter(expected_col_train) == Counter(pred_train.columns.tolist())