【问题标题】:Find Most Important Input from a Neural Network从神经网络中找到最重要的输入
【发布时间】:2019-01-20 03:25:14
【问题描述】:

我用 37 个输入训练了一个神经网络。它的准确率约为 85%。我是否有可能找出哪个 Input 效果最大。我试过这段代码,但我不知道如何找到最重要的输入

weights = model.layers[0].get_weights()[0]
biases = model.layers[0].get_weights()[1]

【问题讨论】:

    标签: python-3.x tensorflow keras


    【解决方案1】:

    一种可能的解决方案是使用 keras.wrappers.scikit_learn 包装您的模型,然后在 scikit-learn 中使用 Recursive Feature elimination

    def create_model():
        # create model
        model = Sequential()
        model.add(Dense(512, activation='relu'))
        model.add(Dense(512, activation='relu'))
        model.add(Dense(10, activation='softmax'))
        # Compile model
        model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
        return model
    
    model = KerasClassifier(build_fn=create_model, epochs=100, batch_size=128, verbose=0)
    rfe = RFE(estimator=model, n_features_to_select=1, step=1)
    rfe.fit(X, y)
    ranking = rfe.ranking_.reshape(digits.images[0].shape)
    
    # Plot pixel ranking
    plt.matshow(ranking, cmap=plt.cm.Blues)
    plt.colorbar()
    plt.title("Ranking of pixels with RFE")
    plt.show()
    

    如果您需要可视化权重,请参阅here

    【讨论】:

    • 该示例似乎不再起作用,因为它引发以下错误:AttributeError: 'KerasClassifier' object has no attribute '_get_tags'
    猜你喜欢
    • 1970-01-01
    • 2012-10-05
    • 1970-01-01
    • 2010-10-13
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 2017-11-28
    相关资源
    最近更新 更多