Question: In [34]: #Function to get weights from LIME explanation object def return_weights(ep) : exp_list = exp. as_map() [1] exp_list = sorted(exp_list, key=lambda x: x[0]) exp_weight
![In [34]: #Function to get weights from LIME explanation object def](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/10/6703fb40b9318_1766703fb40a1a36.jpg)
In [34]: #Function to get weights from LIME explanation object def return_weights(ep) : exp_list = exp. as_map() [1] exp_list = sorted(exp_list, key=lambda x: x[0]) exp_weight = [x[1] for x in exp_list] return exp_weight print(X_test. columns) print (len(X_test) ) #Iterate over the rows in feature matrix #and collect the LIME weights #You can run for more elements----but we pick a max of 25 for x in range (min(len(X_test), 25) ) : #Get explanation exp = lime_explainer . explain_instance(X_test. iloc[x], mlp . predict_proba, num_features = len(X_test. columns) ) #Get weights(exp) weights . append (exp_weight) Index([ 'mean radius', 'mean texture', "mean perimeter', "mean area", "mean smoothness', 'mean compactness', 'mean concavity", 'mean concave points", "mean symmetry', 'mean fractal dimension", 'radius error', 'texture error', 'perimeter error", 'area error", 'smoothness error', 'compactness error', 'concavity error', 'concave points error", 'symmetry error', 'fractal dimension error', 'worst radius', 'worst texture', "worst perimeter", 'worst area", 'worst smoothness', "worst compactness', 'worst concavity' 'worst concave points', 'worst symmetry', 'worst fractal dimension' ], dtype='object' ) 114 Name Error Traceback (most recent call last) Cell In [34], line 19 16 exp = lime_explainer . explain_instance(X_test. iloc[x], 17 mlp. predict_proba, num_features = len(X_test . columns) ) 18 #Get weights (exp) ---> 19 weights . append (exp_weight) NameError: name "weights' is not defined
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
