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

Option to restrict access in "classes_" attribute #15861

Closed
fclesio opened this issue Dec 11, 2019 · 5 comments
Closed

Option to restrict access in "classes_" attribute #15861

fclesio opened this issue Dec 11, 2019 · 5 comments

Comments

@fclesio
Copy link

@fclesio fclesio commented Dec 11, 2019

Description

I was playing around with some models and I noticed that it's possible not only possible to change the number of the classes as it's possible to include the same class to be predicted and I believe this is can be a problem (e.g. credit approval models).

I think maybe it could be an option to have some option to disable this attribute that once the model it's trained it's could not possible to change the classes or any other aspect.

I don't know if this information it's suitable for a new feature request, if it's not I would like to know what I'm missing and the reasons behind that.

Steps/Code to Reproduce

Example: Changing classifier classes to predict one a single class

Link for the notebook with fill example: https://nbviewer.jupyter.org/github/fclesio/learning-space/blob/master/Python/doubt-scikit-learn.ipynb

# Displays prediction classes
model_rf_reload_pkl.classes_
#array([0, 1])

get_results(y_test, y_pred)
# Accuracy: 0.8153333333333334
# status
# 0    8071
# 1     929
# dtype: int64

# Change the classes for the model only to 1
model_rf_reload_pkl.classes_ = np.array([1, 1])

# Quick check
model_rf_reload_pkl.classes_
# array([1, 1])

# Call predict from the new model
y_pred = model_rf_reload_pkl.predict(X_test)

# Check results with a new model
get_results(y_test, y_pred)

# Accuracy: 0.2238888888888889
# status
# 1    9000
# dtype: int64

Versions

System:
    python: 3.6.8 (v3.6.8:3c6b436a57, Dec 24 2018, 02:04:31)  [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]
executable: /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
   machine: Darwin-18.6.0-x86_64-i386-64bit

BLAS:
    macros: NO_ATLAS_INFO=3, HAVE_CBLAS=None
  lib_dirs: 
cblas_libs: cblas

Python deps:
       pip: 19.3.1
setuptools: 41.0.1
   sklearn: 0.21.2
     numpy: 1.17.1
     scipy: 1.3.0
    Cython: 0.29.5
    pandas: 0.25.0
@jnothman

This comment has been minimized.

Copy link
Member

@jnothman jnothman commented Dec 11, 2019

@fclesio

This comment has been minimized.

Copy link
Author

@fclesio fclesio commented Dec 12, 2019

I don't think so @jnothman . I believe that once a model it's trained should not be possible to change this kind of critical parameter.

Maybe there's some reason that I'm missing.

@jnothman

This comment has been minimized.

Copy link
Member

@jnothman jnothman commented Dec 12, 2019

@NicolasHug

This comment has been minimized.

Copy link
Contributor

@NicolasHug NicolasHug commented Dec 12, 2019

Also, Python is very permissive on object attributes. Scikit-learn has a convention that attributes ending with _ should be read-only. But if users want to poke around, they can, at their own risk

@NicolasHug NicolasHug closed this Dec 12, 2019
@fclesio

This comment has been minimized.

Copy link
Author

@fclesio fclesio commented Dec 12, 2019

Thanks for the answer @NicolasHug. In that case, don't you think this can be a potential vulnerability source?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.