After running the following code in lesson 1, how can I use the feature matrix and try out using other classifiers like Decision Tree and Random Forest using Scikit-Learn?
I meant to obtain the matrix that is being fed to the last layer containing the fully connected network. Then, instead of using a fully connected network, I wish to use a decision tree.
Oh so you want the activations at the final layer? Try this
def return_sequential(layer_num, model):
return nn.Sequential(
*list(model.children())[:layer_num]
)
class get_activation_layer(nn.Module):
def __init__(self, model):
super().__init__()
self.model = model
self.layer_models = []
for i in range(len(self.model)):
self.layer_models.append(return_sequential(i, self.model))
def forward(self, x):
self.outputs = []
for i in range(len(self.model)):
self.outputs.append(self.layer_models[i](x))
return self.outputs