简体   繁体   中英

How can I control the topology of neural network when using MLPClassifier?

I am trying to implement a 3 input logic gate us neural network using MLPClassifier. I want to customize the topology of the neural network so every neuron will have no more than 2 inputs.(by default all inputs are connected to all neurons) For that I was trying to set few components of the weight matrix (.coefs_) to 0 so no connectivity will be created (see code bellow) - but I did not succeed. Any idea how to do it right ?

from sklearn.neural_network import MLPClassifier
X = [[0.,0.,0.], [0.,0.,1.], [0.,1.,0.], [0.,1.,1.],[1.,0.,0.], [1.,0.,1.], [1.,1.,0.], [1.,1.,1.]]
y = [1, 0, 0, 1, 0, 1, 0, 1]
clf = MLPClassifier(alpha=1e-5, random_state=21, activation='logistic', solver='lbfgs',hidden_layer_sizes=(2),tol=0.0001,max_iter=100)
#clf.coefs_[0][2][1]=0   # Not working 
clf.fit(X, y)
clf.coefs_

Scikit-learn is not the right tool for the job. Deep learning frameworks such as Tensorflow or PyTorch allow you to create custom neural network architectures.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM