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

support for keras model returning props for one class #44

Open
nataliawojak opened this issue Feb 27, 2024 · 0 comments
Open

support for keras model returning props for one class #44

nataliawojak opened this issue Feb 27, 2024 · 0 comments
Assignees

Comments

@nataliawojak
Copy link

Running lux on keras model which return probability for only one class an error occurs.

Code:
`#create daatframe with columns names as strings (LUX accepts only DataFrames withj string columns names)
iris = datasets.load_iris()
features = ['sepal_length','sepal_width','petal_length','petal_width']
target = 'class'
df_iris = pd.DataFrame(iris.data,columns=features)
df_iris[target] = iris.target
nn_model.fit(train[features],train[target])

#train classifier
train, test = train_test_split(df_iris)

input_shape=(train[features].shape[1],)
nn_model = Sequential()
nn_model.add(Dense(10, activation='relu',
input_shape=input_shape))
nn_model.add(Dense(10, activation='relu'))
nn_model.add(Dense(2, activation="sigmoid"))
nn_model.add(Dense(10, activation='relu'))
nn_model.add(Dense(1, activation="sigmoid"))
nn_model.compile(optimizer=Adam(0.01), loss='categorical_crossentropy')

#pick some instance from datasetr
iris_instance = train[features].sample(1).values
iris_instance

lux = LUX(predict_proba = nn_model.predict, neighborhood_size=20, max_depth=2, node_size_limit = 1, grow_confidence_threshold = 0 )
lux.fit(train[features], train[target], instance_to_explain=iris_instance,class_names=[0,1,2])

#see the justification of the instance being classified for a given class
lux.justify(np.array(iris_instance)) `

ERROR:

` InvalidParameterError Traceback (most recent call last)
in <cell line: 28>()
26
27 lux = LUX(predict_proba = nn_model.predict, neighborhood_size=20, max_depth=2, node_size_limit = 1, grow_confidence_threshold = 0 )
---> 28 lux.fit(train[features], train[target], instance_to_explain=iris_instance,class_names=[0,1,2])
29
30 #see the justification of the instance being classified for a given class

5 frames
/usr/local/lib/python3.10/dist-packages/sklearn/utils/_param_validation.py in validate_parameter_constraints(parameter_constraints, params, caller_name)
95 )
96
---> 97 raise InvalidParameterError(
98 f"The {param_name!r} parameter of {caller_name} must be"
99 f" {constraints_str}. Got {param_val!r} instead."

InvalidParameterError: The 'n_neighbors' parameter of NearestNeighbors must be an int in the range [1, inf) or None. Got 0 instead. `

@sbobek sbobek self-assigned this May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants