Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Option to restrict access in "classes_" attribute #15861
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