eli5.permutation_importance get_score_importances 使 Google Colab 会话崩溃

时间:2021-04-22 03:35:35

标签: python keras neural-network eli5

我从以下文章中了解到 eli5.permutation_importance get_score_importanceshttps://towardsdatascience.com/how-to-find-feature-importances-for-blackbox-models-c418b694659d; 这里是 documentation

当我尝试在我的神经网络上使用 get_score_importances 时,我的 RAM 增加并且我的会话在 Google Colab 中崩溃。 x_test 的形状是 (34463, 2355)

这是我的神经网络模型

NN_model = Sequential()
NN_model.add(Dense(128, kernel_initializer='normal',input_dim = 
x_train.shape[1], activation='relu'))
NN_model.add(Dense(256, kernel_initializer='normal',activation='relu'))
NN_model.add(Dense(1, kernel_initializer='normal',activation='linear'))

# Compile the network :
NN_model.compile(loss='mean_absolute_error', optimizer='adam', metrics= 
['mean_absolute_error'])
NN_model.summary()

#Define a checkpoint callback
checkpoint_name = 'Weights-{epoch:03d}--{val_loss:.5f}.hdf5' 
checkpoint = ModelCheckpoint(checkpoint_name, monitor='val_loss', verbose = 
1, save_best_only = True, 
mode ='auto')
callbacks_list = [checkpoint]

#train a neural network model
NN_model.fit(x_train, y_train, epochs=500, batch_size=32, validation_split = 
 0.2, 
callbacks=callbacks_list)

这是我用来运行 get_score_importances 的代码

import numpy as np
from eli5.permutation_importance import get_score_importances

import numpy as np
y_array = np.array(y_test)
x_array = np.array(x_test)

#score function
from sklearn.metrics import mean_absolute_error
def score(X, y):
    predictions = NN_model.predict(X)
    return mean_absolute_error(y , predictions)

# This function takes only numpy arrays as inputs
#The following line crashes the session
base_score, score_decreases = get_score_importances(score,x_array, y_array)
#The following line never gets run
feature_importances = np.mean(score_decreases, axis=0)

是不是我做错了什么导致 Google Colab 崩溃?我正在运行 8GB RAM 和 Intel Core i7 5500U CPU,2.4 GHZ,Windows 64 位。任何帮助将不胜感激。

0 个答案:

没有答案