def predict_fn(x):
    # Konvertiere das NumPy-Array zurück in ein DataFrame mit den richtigen Feature-Namen
    df = pd.DataFrame(x, columns=X_train.columns)
    return best_rf_model.predict_proba(df)

# Speichere mehrere Erklärungen
explanations = []
for i in range(100):
    exp = lime_explainer.explain_instance(
        instance, 
        predict_fn,
        num_features=20
    )
    explanations.append(exp.as_list())

# Berechne die Varianz der Feature-Wichtigkeiten
feature_variances = {}
for i in range(len(explanations[0])):
    feature = explanations[0][i][0]
    values = [exp[i][1] for exp in explanations if len(exp) > i and exp[i][0] == feature]
    feature_variances[feature] = np.var(values)

print("Varianz der Feature-Wichtigkeiten:")
for feature, variance in feature_variances.items():
    print(f"{feature}: {variance:.6f}")