Skip to main content

Compare two ML models.

Project description

Test & Upload to TestPyPI

License: MIT

Models Contrast

A simple package for compare the performance of two ML models in sklearn, python.

Installation

Use the package manager pip to install model-contrast.

pip install model-contrast

Usage

Compare 2 Binary Classifiers

from sklearn.datasets import make_classification
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split

# create two demo models
X, y =  make_classification(n_samples=700, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y,
         test_size=0.2, random_state=42)

model1 = RandomForestClassifier(n_estimators=10, random_state=42)
model2 = LogisticRegression()

#train the models
model1.fit(X_train, y_train)
model2.fit(X_train, y_train)

Now let's compare them with our package:

from model_contrast import classificator_contrast

classificator_contrast(model1, model2, X_test, y_test)

and it return:

image

Compare Multi-Class Classifiers

from sklearn.datasets import make_classification
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split

# create two demo models
X, y =  make_classification(n_samples=700, random_state=42, n_classes=4, n_informative=4)
X_train, X_test, y_train, y_test = train_test_split(X, y,
         test_size=0.2, random_state=42)

model1 = RandomForestClassifier(n_estimators=10, random_state=42)
model2 = LogisticRegression()

#train the models
model1.fit(X_train, y_train)
model2.fit(X_train, y_train)

Compare them:

from model_contrast import classificator_contrast

classificator_contrast(model1, model2, X_test, y_test)

and it returns:

image

Compare 2 Regressors

from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import RandomForestRegressor

#create the regressor
X, y =  make_regression(n_samples=700, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y,
         test_size=0.2, random_state=42)

model1 = RandomForestRegressor(n_estimators=10, random_state=42)
model2 = LinearRegression()

#train the regressors
model1.fit(X_train, y_train)
model2.fit(X_train, y_train)

Compare them:

from model_contrast import  regressor_contrast

regressor_contrast(model1, model2, X_test, y_test)

and it returns:

image

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

model contrast-0.1.8.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

model_contrast-0.1.8-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file model contrast-0.1.8.tar.gz.

File metadata

  • Download URL: model contrast-0.1.8.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.11

File hashes

Hashes for model contrast-0.1.8.tar.gz
Algorithm Hash digest
SHA256 a911c1867ebae2d99e077423685cecf086178ed845f3d03b94b3d9b312d35857
MD5 84df70a2d6290b14413f2eb4c73e7b97
BLAKE2b-256 e7525bb1dbb93ea16e1909745d6fd596fa0dd569e27364c565a2997ef1bfc86a

See more details on using hashes here.

File details

Details for the file model_contrast-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: model_contrast-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.11

File hashes

Hashes for model_contrast-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 31ac543d771cc431294dcdb35f3f3a7e27010320116e3a015bf3b69752a48261
MD5 699c5a37fa065418ecd6e76319c5d9ed
BLAKE2b-256 27b3997fb6c6079303b63e302dfc344c457146a1ceac9cc99494e31881155114

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page