Chat with us, powered by LiveChat Artificial Intelligence Neural network | WriteDemy

For this milestone, you will design and train a neural network to accomplish some classification task.

Choose a data set

The UCI Machine Learning Archive hosts various data sets suitable for testing learning algorithms. I suggest clicking on “View ALL Data Sets” on the right side of the page. That provides a nice interface in which you can filter by data type or area of interest.

The data should be suitable for a classification task, not clustering, recommendations, or regression. Neural networks support both categorical and numerical data, you’ll just want to keep the number of attributes to less than 100, because we’ll have to tune the way each attribute is presented to the network.

When you click on the data set, you’ll see a description, citations, and details about the attributes. There are links near the top to the “Data Folder”, and there you’ll find a list of files ending in .data (the raw data) or .names (attribute descriptions).

Download the data and descriptions. I have a lot of experience with the Mushroom data, so I’ll explore that in this explanation – but you can choose something else for your project. For mushrooms, the .names file contains:

1. Title: Mushroom Database2. Sources: (a) Mushroom records drawn from The Audubon Society Field Guide to North American Mushrooms (1981). G. H. Lincoff (Pres.), New York: Alfred A. Knopf (b) Donor: Jeff Schlimmer (.cs.cmu.edu) (c) Date: 27 April 19873. Past Usage: 1. Schlimmer,J.S. (1987). Concept Acquisition Through Representational Adjustment (Technical Report 87-19). Doctoral disseration, Department of Information and Computer Science, University of California, Irvine. — STAGGER: asymptoted to 95% classification accuracy after reviewing 1000 instances.[etc.]5. Number of Instances: 81246. Number of Attributes: 22 (all nominally valued)7. Attribute Information: (classes: edible=e, poisonous=p) 1. cap-shape: bell=b,conical=c,convex=x,flat=f, knobbed=k,sunken=s 2. cap-surface: fibrous=f,grooves=g,scaly=y,smooth=s 3. cap-color: brown=n,buff=b,cinnamon=c,gray=g,green=r, pink=p,purple=u,red=e,white=w,yellow=y[etc.]

The .data file is a text file with comma-separated values (CSV), which can be imported easily into Excel or other spreadsheet applications:

p,x,s,n,t,p,f,c,n,k,e,e,s,s,w,w,p,w,o,p,k,s,ue,x,s,y,t,a,f,c,b,k,e,c,s,s,w,w,p,w,o,p,n,n,ge,b,s,w,t,l,f,c,b,n,e,c,s,s,w,w,p,w,o,p,n,n,mp,x,y,w,t,p,f,c,n,n,e,e,s,s,w,w,p,w,o,p,k,s,ue,x,s,g,f,n,f,w,b,k,t,e,s,s,w,w,p,w,o,e,n,a,g[etc.]

Design your network

Your next task is to design your neural network architecture: how many neurons in each layer, and how to map neuronal activations to and from the data set?

Input layer

The number of input neurons will be based on the number of attributes in your data set, but it may not be a one-to-one match.

Generally, a continuous (real number) attribute can map directly to one neuron. There are no continuous attributes in the mushroom set, but the Heart Disease data contains a few, such as:

thalach: maximum heart rate achieved

which has values like 127, 154, or 166. It is helpful, however, to normalize these values to the range 0..1, so they are not terribly out of proportion to the inputs from other attributes. In the case of heart rate, we would find the minimum (60) and the maximum (182) in the data file. Then, to convert any value, we subtract the minimum and divide by the size of the range (182-60 = 122):

Raw value Normalized value 60 0.0 = (60-60)/122 127 0.549180327869 = (127-60)/122 154 0.770491803279 = (154-60)/122 166 0.868852459016 = (166-60)/122 182 1.0 = (182-60)/122

A discrete (categorical) attribute must be translated in some way, usually using a binary encoding. Let’s take the cap-shape of mushrooms as an example. These are the possible values:

bell=b, conical=c, convex=x, flat=f, knobbed=k, sunken=s

Because there are 6 possible values, we can represent them in ⌈log2(6)⌉=3⌈log2(6)⌉=3 input neurons, like this:

Code Category # Binary Input[0] Input[1] Input[2] b bell 0 000 0.0 0.0 0.0 c conical 1 001 0.0 0.0 1.0 x convex 2 010 0.0 1.0 0.0 f flat 3 011 0.0 1.0 1.0 k knobbed 4 100 1.0 0.0 0.0 s sunken 5 101 1.0 0.0 1.0

Work through the attribute descriptions for your data set to determine the number of input neurons, the normalization parameters for continuous attributes, and the binary encoding for discrete attributes.

Hidden layer

You will have to decide how many neurons to use in the hidden layer. Too few, and the network will not be sophisticated enough to recognize the patterns in the data. Too many, and the network may take longer to converge on an acceptable solution.

I would recommend starting with the same number of hidden neurons as input neurons, and then experiment with reducing it.

Output layer

Most classifications will be discrete categories: poisonous/edible for mushrooms, or the diagnosis of heart disease in that data set:

num: diagnosis of heart disease (angiographic disease status) — Value 0: < 50% diameter narrowing — Value 1: > 50% diameter narrowing

You will want to have one output neuron for each possible classification, and use the “winner take all” strategy – the neuron with the highest activation determines the result. Here would be the expected outputs for the categories of mushrooms:

Code Category Output[0] Output[1] e edible 1.0 0.0 p poison 0.0 1.0

Implementation

Network architecture

Start with your (or my) mazur-nn implementation, but you’ll have to redefine the network architecture, something like this:

// 3-layer network architectureconst int NUM_INPUTS = 57;const int NUM_HIDDEN = 10;const int NUM_OUTPUTS = 2;

Those are the numbers I used for the mushroom data, but you can alter them for your own network.

Input data

Next, you’ll need to read the data. Here’s a routine you can use that interprets the comma-separated values (CSV) format generally used by data sets in the UCI archive:

#include #include #include #include void read_csv(const char* filename, vector< vector >& data){ const int BUFFER_SIZE = 8192; char buffer[BUFFER_SIZE]; FILE* fp = fopen(filename, “r”); if(!fp) { perror(filename); exit(1); } // Read each line of the file while(fgets(buffer, BUFFER_SIZE-1, fp)) { // Parse by splitting on commas vector row; char* elt = strtok(buffer, “,”); while(elt) { row.push_back(elt); elt = strtok(NULL, “,”); } data.push_back(row); } cout << “Read ” << data.size() << ” records x ” << data[0].size() << ” attributes from ” << filename << “n”; fclose(fp);}

You’d call it like this:

vector> data; // Read data from file into two-dimensional vector read_csv(“shrooms.data”, data);

If it works, you should see a message like this upon running the program:

Read 8124 records x 23 attributes from shrooms.data

Set target outputs

Next, you’ll have to modify the parts of the mazur-nn code that provides inputs to the network, and that specify the target outputs. Let’s begin with the target outputs. In the mazur-nnexample, we simply used:

vector targets = {0.01, 0.99};

But now we’ll have to vary that for each example in the data file. Strategic Goal Controlling,Management,,

Get a Unique Answer HERE or Order a Similar Paper


You’d call it like this:

vector> data; // Read data from file into two-dimensional vector read_csv(“shrooms.data”, data);

If it works, you should see a message like this upon running the program:

Read 8124 records x 23 attributes from shrooms.data

Set target outputs

Next, you’ll have to modify the parts of the mazur-nn code that provides inputs to the network, and that specify the target outputs. Let’s begin with the target outputs. In the mazur-nnexample, we simply used:

vector targets = {0.01, 0.99};

But now we’ll have to vary that for each example in the data file. Strategic Goal Controlling,Management,,

Get a Unique Answer HERE or Order a Similar Paper

Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

Do you need an answer to this or any other questions?

About Writedemy

We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.

How It Works

To make an Order you only need to click on “Place Order” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Are there Discounts?

All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.

Hire a tutor today CLICK HERE to make your first order