python-3.x - 从神经网络中找到最重要的输入
问题描述
我用 37 个输入训练了一个神经网络。它的准确率约为 85%。我是否有可能找出哪个 Input 效果最大。我试过这段代码,但我不知道如何找到最重要的输入
weights = model.layers[0].get_weights()[0]
biases = model.layers[0].get_weights()[1]
解决方案
一种可能的解决方案是使用scikit-learn包装模型,keras.wrappers.scikit_learn
然后使用递归特征消除:
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()
如果您需要可视化权重,请参见此处。
推荐阅读
- python - 用另一个列表中的值替换列表的开头
- python - 在 AWS S3 中分块创建大型 zip 文件
- sql - Snowflake SQL REGEXP - 在文件扩展名之前的连字符之后捕获
- javascript - 从日期和时间中减去小时数
- python - 我该如何修复(没有这样的列:可用性)错误???当我运行此代码时,我收到此错误:没有这样的列:可用性
- c++ - 没有得到正确的输出功能不起作用
- html - 横向 CSS 上的方向锁定
- css - 为什么 div 边距占据了我页面的整个顶部
- javascript - 从复选框组中获取值并从数组中添加/删除它们
- java - Groovy - 将 REST 响应正文中的两个 json 值(int、String)保存到 GlobalVariable