Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor logistic regression #171

Merged
merged 6 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
### Changed
- testcase for LogisticRegressionCV, LogisticRegression
- `README.md` updated
- `AUTHORS.md` updated
## [1.1] - 2024-11-25
Expand Down
13 changes: 0 additions & 13 deletions pymilo/utils/data_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,3 @@ def prepare_simple_clustering_datasets():
X = iris.data # Features
y = iris.target # Target (labels)
return X, y


def prepare_logistic_regression_datasets(threshold=None):
"""
Generate a dataset for logistic regression (the iris).

:param threshold: threshold for train/test splitting
:int threshold: int
:return: splitted dataset for logistic regression
"""
iris_X, iris_y = datasets.load_iris(return_X_y=True)
threshold = threshold if threshold else len(iris_y) // 2
return _split_X_y(iris_X, iris_y, threshold)
8 changes: 4 additions & 4 deletions tests/test_linear_models/logistic/logistic_regression.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from sklearn.linear_model import LogisticRegression
from pymilo.utils.test_pymilo import pymilo_regression_test
from pymilo.utils.data_exporter import prepare_simple_regression_datasets
from pymilo.utils.test_pymilo import pymilo_classification_test
from pymilo.utils.data_exporter import prepare_simple_classification_datasets

MODEL_NAME = "Logistic-Regression"


def logistic_regression():
x_train, y_train, x_test, y_test = prepare_simple_regression_datasets()
x_train, y_train, x_test, y_test = prepare_simple_classification_datasets()
# Create Logistic regression object
logistic_regression_random_state = 4
logistic_regression = LogisticRegression(
random_state=logistic_regression_random_state)
# Train the model using the training sets
logistic_regression.fit(x_train, y_train)
assert pymilo_regression_test(
assert pymilo_classification_test(
logistic_regression, MODEL_NAME, (x_test, y_test)) == True
8 changes: 4 additions & 4 deletions tests/test_linear_models/logistic/logistic_regression_cv.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from sklearn.linear_model import LogisticRegressionCV
from pymilo.utils.test_pymilo import pymilo_regression_test
from pymilo.utils.data_exporter import prepare_logistic_regression_datasets
from pymilo.utils.test_pymilo import pymilo_classification_test
from pymilo.utils.data_exporter import prepare_simple_classification_datasets

MODEL_NAME = "Logistic-Regression-CV"


def logistic_regression_cv():
x_train, y_train, x_test, y_test = prepare_logistic_regression_datasets()
x_train, y_train, x_test, y_test = prepare_simple_classification_datasets()
# Create Logistic regression cv object
logistic_regression_cv = 5
logistic_regression_random_state = 0
Expand All @@ -15,5 +15,5 @@ def logistic_regression_cv():
random_state=logistic_regression_random_state)
# Train the model using the training sets
logistic_regression_cv.fit(x_train, y_train)
assert pymilo_regression_test(
assert pymilo_classification_test(
logistic_regression_cv, MODEL_NAME, (x_test, y_test)) == True