Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用RandomTreesEmbedding作为Keras的输入_Python_Tensorflow_Keras_Scikit Learn - Fatal编程技术网

Python 使用RandomTreesEmbedding作为Keras的输入

Python 使用RandomTreesEmbedding作为Keras的输入,python,tensorflow,keras,scikit-learn,Python,Tensorflow,Keras,Scikit Learn,我一直在尝试使用NN解决回归问题,但我无法使其收敛。我尝试改变层/神经元的数量、学习率、批量大小等,但训练总是不成功,模型总是预测数据集的平均值: 我尝试用随机森林回归器解决同样的问题,结果稍微好一点,尽管还不够好: 因此,我尝试将这两种方法结合起来,通过构建基于随机森林分割的嵌入,然后使用这些嵌入作为神经网络的输入 我试过这样的方法: n_est=3 params = dict(n_estimators=n_est, max_depth=5,

我一直在尝试使用NN解决回归问题,但我无法使其收敛。我尝试改变层/神经元的数量、学习率、批量大小等,但训练总是不成功,模型总是预测数据集的平均值:

我尝试用随机森林回归器解决同样的问题,结果稍微好一点,尽管还不够好:

因此,我尝试将这两种方法结合起来,通过构建基于随机森林分割的嵌入,然后使用这些嵌入作为神经网络的输入

我试过这样的方法:

n_est=3
params = dict(n_estimators=n_est,
              max_depth=5,
              min_samples_split=2,
              min_samples_leaf=1,
              min_weight_fraction_leaf=0.0,
              max_leaf_nodes=None,
              min_impurity_decrease=0.0,
              min_impurity_split=None,
              random_state=42,
              verbose=1)
random_trees = RandomTreesEmbedding(**params).fit(X_train, y_train)
X_train_emb = random_trees.transform(X_train)
X_test_emb = random_trees.transform(X_test)
但问题是,我不能使用对象X_train_emb,X_test_emb作为模型的输入,因为它们是sklearn稀疏矩阵,而且Keras不支持它们。 我可以通过将它们转换为数组来修复它:

X_train_emb = random_trees.transform(X_train).toarray()
X_test_emb = random_trees.transform(X_test).toarray()
history = net.fit(X_train_emb, y_train, batch_size=batch_size, epochs=nr_epochs, validation_data=(X_test_emb, y_test))
但是生成的对象具有高维性,因此我很容易内存不足。是否有另一种更方便记忆的方法将嵌入传递给我的NN?

这有帮助吗?