MultilayerPerceptron | Python program to implement the multilayer | Machine Learning library
kandi X-RAY | MultilayerPerceptron Summary
kandi X-RAY | MultilayerPerceptron Summary
Python program to implement the multilayer perceptron neural network.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Train the network
- Feed the model
- Return the sigmoid function
- Print the weights
MultilayerPerceptron Key Features
MultilayerPerceptron Examples and Code Snippets
def save(mlp):
with open('MultiLayerPerceptron.sav',mode='wb') as f:
pickle.dump(mlp,f)
Community Discussions
Trending Discussions on MultilayerPerceptron
QUESTION
I'm a high school senior who's working on a project for my CS research class (I'm very lucky to have the opportunity to be in such a class)! The project is to make an AI learn the popular game, Snake, with a Multilayer Perceptron (MLP) that learns through Genetic Algorithm (GA). This project is heavily inspired by many videos I've seen on Youtube accomplishing what I've just described, as you can see here and here. I've written the project described above using JavaFX and an AI library called Neuroph.
This is what my program looks like currently:
The name is irrelevant, as I have a list of nouns and adjectives I used to generate them from (I thought it would make it more interesting). The number in the parenthesis for Score is the best score in that generation, since only 1 snake is shown at a time.
When breeding, I set x% of the snakes to be parents (in this case, 20). The number of children is then divided up evenly for each pair of snake parents. The "genes" in this case, are the weights of the MLP. Since my library doesn't really support biases, I added a bias neuron to the input layer and connected it to all of the other neurons in every layer for its weights to act as biases instead (as described in a thread here). Each of the snake's children has a 50, 50 chance of getting either parents' gene for every gene. There is also a 5% chance for a gene to mutate, where it's set to a random number between -1.0 and 1.0.
Each snake's MLP has 3 layers: 18 input neurons, 14 hidden ones, and 4 output neurons (for each direction). The inputs I feed it are the x of head, y of head, x of food, y of food, and steps left. It also looks in 4 directions, and check for the distance to food, wall, and itself (if it doesn't see it, it's set to -1.0). There's also the bias neuron I talked about which brings the number to 18 after adding it.
The way I calculate a snake's score is through my fitness function, which is (apples consumed × 5 + seconds alive / 2)
Here is my GAMLPAgent.java, where all the MLP and GA stuff happens.
...ANSWER
Answered 2020-Aug-30 at 05:13I'm not surprised your snakes are dying.
Let's take a step back. What is AI exactly? Well, it's a search problem. We're searching through some parameter space to find the set of parameters that solve snake given the current state of the game. You can imagine a space of parameters that has a global minimum: the best possible snake, the snake that makes the fewest mistakes.
All learning algorithms start at some point in this parameters space and attempt to find that global maximum over time. First, let's think about MLPs. MLPs learn by trying a set of weights, computing a loss function, and then taking a step in the direction that would further minimize the loss (gradient descent). It's fairly obvious that an MLP will find a minimum, but whether it can find a good enough minimum is a question and there are a lot of training techniques that exist to improve that chance.
Genetic algorithms, on the other hand, have very poor convergence characteristics. First, let's stop calling these genetic algorithms. Let's call these smorgasbord algorithms instead. A smorgasbord algorithm takes two sets of parameters from two parents, jumbles them, and then yields a new smorgasbord. What makes you think this would be a better smorgasbord than either of the two? What are you minimizing here? How do you know it's approaching anything better? If you attach a loss function, how do you know you're in a space that can actually be minimized?
The point I'm trying to make is that genetic algorithms are unprincipled, unlike nature. Nature does not just put codons in a blender to make a new strand of DNA, but that's exactly what genetic algorithms do. There are techniques to add some time of hill climbing, but still genetic algorithms have tons of problems.
Point is, don't get swept up in the name. Genetic algorithms are simply smorgasbord algorithms. My view is that your approach doesn't work because GAs have no guarantees of converging after infinite iterations and MLPs have no guarantees of converging to a good global minimum.
What to do? Well, a better approach would be to use a learning paradigm that fits your problem. That better approach would be to use reinforcement learning. There's a very good course on Udacity from Georgia Tech on the subject.
QUESTION
I am able to run Weka form CLI using below command:
...ANSWER
Answered 2018-Mar-31 at 17:26Posting answer to my own question:
QUESTION
I am trying to classify an instance using Weka in Java (specifically Android Studio). Initially, I saved a model from the Desktop Weka GUI and tried to import it into my project directory. If I am correct, this won't work because the Weka JDKs are different on PC versus Android.
Now I am trying to train a model on the Android itself (as I see no other option) by importing the training dataset. Here is where I am running into problems. When I run "Test.java," I get this error saying that my source hasn't been specified pointing to line 23 where I invoke the .loadDataset method. java.io.IOException: No source has been specified But, clearly, I have specified a path. Is this the correct path? I.E. I am not sure what I am doing wrong. I have looked at other examples/blogs, but none go in detail.
My end goal: train a model in android/java and classify instances in android/java using weka-developed models.
My code can be found at these links:
ModelGenerator.java
...ANSWER
Answered 2019-Apr-02 at 06:50Elaborate and in-detail answer is located at this link:
In short, you have to make a raw folder within the res directory. Then save whatever file there. You will access these files per their resource ID's.
QUESTION
I am comparing the performance of two programs about KerasRegressor
using Scikit-Learn StandardScaler
: one program with Scikit-Learn Pipeline
and one program without the Pipeline
.
Program 1:
...ANSWER
Answered 2017-May-06 at 09:21In the second case, you are calling StandardScaler.fit_transform()
on both X_train
and X_test
. Its wrong usage.
You should call fit_transform()
on X_train
and then call only transform()
on the X_test
. Because thats what the Pipeline
does.
The Pipeline
as the documentation states, will:
fit():
Fit all the transforms one after the other and transform the data, then fit the transformed data using the final estimator
predict():
Apply transforms to the data, and predict with the final estimator
So you see, it will only apply transform()
to the test data, not fit_transform()
.
So elaborate my point, your code should be:
QUESTION
I'm new to Weka. I downloaded it and can use the GUI interface, but I cannot figure out why I cannot run it from the command line (on a Mac OS X).
I'm in bash. When I do echo $PATH, I can see the path to weka.jar, but when I run
java -cp weka.jar weka.classifiers.functions.MultilayerPerceptron
Error: Could not find or load main class weka.classifiers.functions.MultilayerPerceptron Caused by: java.lang.ClassNotFoundException: weka.classifiers.functions.MultilayerPerceptron
Now, I go to the weka folders and I can see that I have classifiers/functions/ there, but the files inside are only htmls.
I also tried
java weka.core.WekaPackageManager
Error: Could not find or load main class weka.core.WekaPackageManager Caused by: java.lang.ClassNotFoundException: weka.core.WekaPackageManager
...ANSWER
Answered 2018-Feb-16 at 10:30I use this bash script to start wekafrom the command line:
QUESTION
I'm trying to decide on the best architecture for a multilayerPerceptron in Apache Spark and am wondering whether I can use cross-validation for that.
Some code:
...ANSWER
Answered 2018-Feb-11 at 12:15Looking at the code it seems syntactically correct. It not working may be a bug or intended, since it'd be rather expensive computationally. So I guess no, you can't use cv for that.
I ended up using the following formula:
QUESTION
I have been trying to use a MultilayerPerceptron neural network in order to classify my data. However, with whatever configuration tried, I always seem to get the same results, as shown below, of only 50% correct. I can confirm that other classifiers seem to provide more believable results using the same dataset.
My data is of the format 'string, nominal'.
To explain pre-processing a bit more - I am using the StringToWordVector filter to convert the string to attributes in my data set (this gives me about 1000 attributes). My class attribute is a nominal one, of either positive or negative.
When attempting to cross-validate the neural network on 4000 (2000 per class) of these instances, I get the same results repeatedly. What exactly is causing the network to point everything to a single class?
...ANSWER
Answered 2017-Dec-30 at 21:19For anyone looking for an answer to this, I found that I had to increase the number of neurons in the hidden layer. I got improved results changing this to 100 and in changing it to 'the number of attributes', it is not all being mapped to a single class (the original issue).
QUESTION
From what I know, test accuracy should increase when training time increase(up to some point); but experimenting with weka yielded the opposite. I am wondering if misunderstood someting. I used diabetes.arff for classification with 70% for training and 30% for testing. I used MultilayerPerceptron classifier and tried training times 100,500,1000,3000,5000. Here are my results,
...ANSWER
Answered 2017-Nov-30 at 04:59You got a very nice example of overfitting.
Here is the short explanation of what happened:You model (doesn't matter whether this is multilayer perceptron, decision trees or literally anything else) can fit the training data in two ways.
First one is a generalization - model tries to find patterns and trends and use them to make predictions. The second one is remembering the exact data points from the training dataset.
Imagine the computer vision task: classify images into two categories – humans vs trucks. The good model will find common features that are present in human pictures but not in the trucks pictures (smooth curves, skin-color surfaces). This is a generalization. Such model will be able to handle new pictures pretty well. The bad model, overfitted one, will just remember exact images, exact pixels of the training dataset and will have no idea what to do with new images on the test set.
What can you do to prevent overfitting?There are few common approaches to deal with overfitting:
- Use simpler models. With fewer parameters, it will be difficult for a model to remember the dataset
- Use regularization. Constrain the weights of the model and/or use dropout in your perceptron.
- Stop the training process. Split your training data once more, so you will have three parts of the data: training, dev, and test. Then train your model using training data only and stop the training when the error on the dev set stopped decreasing.
The good starting point to read about overfitting is Wikipedia: https://en.wikipedia.org/wiki/Overfitting
QUESTION
stackoverflowers , I need some help from tensorflow experts. Actually I've buid a multi-layer perceptron, trained it, tested it and everything seemed ok. However, When I restored the model and tried to use it again, its accuracy does not correspond to the trained model and the predictions are pretty different from the real labels. The code I am using for the restoring - prediction is the following : (I'm using R)
...ANSWER
Answered 2017-Aug-16 at 13:04Your code does not show where model_saver
is initialized, but it should be created after you create the computational graph. If not, it does not know which variables to restore/save. So create your model_saver
after pred <- multiLayerPerceptron(test_data)
.
Note that, if you made the same mistake during training, your checkpoint will be empty and you will need to retrain your model first.
QUESTION
Hi I am using Spark ML to train a model. The training dataset has 130 columns and 10 million rows. Now, the problem is that whenever I run MultiLayerPerceptron it shows the following error:
org.apache.spark.SparkException: Job aborted due to stage failure: Task 43 in stage 1882.0 failed 4 times, most recent failure: Lost task 43.3 in stage 1882.0 (TID 180174, 10.233.252.145, executor 6): java.lang.ArrayIndexOutOfBoundsException
Interestingly it does not happen when I used other classifiers such as Logistic Regression and Random Forest.
My Code:
...ANSWER
Answered 2017-Jun-23 at 20:41There were more than two classes in the label but in the multilayer perceptron classifier I have specified 2 output neurons which resulted in ArrayIndexOutOfBoundException.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install MultilayerPerceptron
You can use MultilayerPerceptron like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page