Artificial Neural Networks


Artificial Neural Networks

Maria
Let’s begin with the big idea: an artificial neural network, or ANN, is a computing system inspired by the way biological nervous systems process information. Neural networks are one important family of methods within artificial intelligence, and they’re especially useful for learning patterns from data.

Simon
And it helps to place that inside the broader AI landscape. Artificial intelligence is about building systems that perform tasks associated with intelligent behavior. Machine learning uses statistical methods to learn patterns from data, while deep learning is a part of machine learning that uses neural networks with multiple layers.

Maria
A familiar example is recognizing a face. A person doesn’t usually identify someone by checking just one feature; we combine details such as facial shape, hair, and the spacing of features. An AI system can also learn to use many features together, although it does so through computation rather than human reasoning.

Simon
That distinction matters. A computer can calculate a square root extremely quickly, yet asking it to carry out an everyday task in an unfamiliar setting can be much harder. For a machine to act effectively, it needs information about its surroundings and a way to learn how that information relates to its task.

Maria
The history gives us some context. The term artificial intelligence was coined by John McCarthy in 1956 at the Dartmouth Conference. At the time, the computing power and hardware needed for ambitious AI systems were limited. A major public milestone came in the late 1990s, when IBM’s Deep Blue defeated the world chess champion.

Simon
AI is also part of ordinary digital life now. Search engines use information about what people have searched for to help rank or suggest results. Streaming services recommend films based on viewing patterns, and photo services can recognize people in images using information gathered from previous examples.

Maria
Neural networks take their name from biological neural networks, so let’s look briefly at that inspiration. In a biological nervous system, neurons receive signals, process them, and pass signals onward. Dendrites receive signals, an axon carries a signal away from the neuron, and synapses connect neurons and help transmit signals between them.

Simon
The analogy is useful, but it isn’t a claim that artificial neurons are biological cells. In an ANN, inputs correspond loosely to information arriving at a neuron, weights influence how strongly each input counts, and an activation function determines the neuron’s output. Those outputs are passed along connections to other neurons.

Maria
Picture a simple network with an input layer, one or more hidden layers, and an output layer. The input layer receives the features in a data set. Hidden layers transform information as it moves through the network, and the output layer gives the final prediction, such as a class label.

Simon
Each connection has a weight. A larger weight means that, in that part of the computation, the corresponding input has a stronger influence; a smaller weight means less influence. The network combines weighted inputs, usually with a bias as well, before applying an activation function.

Maria
For a tiny numerical example, suppose two inputs are 0.6 and 1.0, and their weights are 0.5 and 0.8. The weighted sum is 0.6 times 0.5 plus 1.0 times 0.8, which equals 1.1. If we use a simple threshold of 1.0 for illustration, the value exceeds the threshold, so the neuron would activate.

Simon
That example is just a way to understand weighted inputs and thresholds. Real networks commonly use activation functions to transform values, rather than relying only on a simple threshold rule. Also, activation happens during the forward pass; backpropagation is a separate learning process that uses the prediction error to adjust the network.

Maria
Biases are another important part of the calculation. They allow a neuron’s output to shift even when the weighted inputs alone don’t capture what’s needed. You can think of a bias as playing a role somewhat like an intercept in a regression equation, though the full network can be much more complex than a single regression.

Simon
A network’s hidden layers are sometimes described as a black box because its internal computations can be difficult to interpret. Even so, the overall process is systematic: inputs pass forward through weighted connections and layers until the network produces an output.

Maria
Now let’s talk about learning. During training, the network receives input examples and produces predictions. It compares those predictions with the desired outputs, calculates an error, and uses that error to update its weights so future predictions can improve.

Simon
Backpropagation is the mechanism that carries information about the error backward through the network. The network uses derivatives to determine how its weights contributed to the error, then adjusts those weights. Training repeats this process across many examples and iterations.

Maria
A learning-rate parameter controls the size of weight updates. If updates are too large, the training process can overshoot useful settings; if they are too small, learning can be slow. The learning rate is a setting the practitioner chooses or tunes, rather than something we should assume the network automatically selects.

Simon
The error function gives training a numerical way to measure how far predictions are from the desired outputs. The source uses the sum of squared errors as an example. Squaring the differences makes the contributions nonnegative and gives a quantity that can be differentiated for the weight-update process.

Maria
Training needs stopping criteria, too. One possibility is a target for the error or its derivative; another is a maximum number of iterations. In the example, these iterations are also called steps or epochs. Without a limit or stopping rule, there would be no clear point at which to end training.

Simon
The number and size of hidden layers affect what a network can represent. The material offers a repeated-square-root calculation as a rough way to think about choosing layer sizes: start from the number of input variables, take a square root, and repeat for additional layers, rounding to practical whole numbers. That’s a heuristic from the example, not a universal rule for designing every network.

Maria
Let’s make the implementation concrete with the Iris data set. It contains 150 flowers, four measurements—sepal length, sepal width, petal length, and petal width—and three possible species. The task is to predict a flower’s species from its four measurements.

Simon
Before fitting a neural network, the categorical target needs to be represented in a suitable numerical form. The example converts the three species into three indicator columns: a flower’s own species is marked with a one, and the other species are marked with zeros. This is commonly called one-hot encoding.

Maria
The example also scales the four measurement variables and shuffles the observations to reduce the chance that the order of the rows creates a misleading split. Then it divides the data into training and test sets: the first 100 rows are used for training and the remaining 50 for testing.

Simon
The distinction is essential. The network learns its weights from the training data. The test data is held aside so we can check how well the trained model predicts examples it wasn’t trained on. The test inputs must be prepared consistently with the training inputs, including the same kind of scaling.

Maria
In the R example, the neural-network formula says that the three encoded species columns are outputs, predicted from the four flower measurements. The training data is passed to the fitting function, and the hidden-layer setting specifies the network’s hidden neurons. With four input variables, the demonstration uses one hidden layer containing two neurons.

Simon
The example’s settings include a threshold related to the derivative of the error function, a maximum number of steps, and an option controlling whether the output is linear. It also includes settings for how often training progress is displayed. A sum-of-squares error function is used so the model can track prediction error during training.

Maria
In the reported run, the network stopped after 125 steps rather than using the full allowance of 2,000, because its stopping condition was met. The displayed error fell as training proceeded. That illustrates how the stopping rules can end training before the maximum number of iterations.

Simon
The fitted network has weights and biases connecting its inputs, hidden neurons, and outputs. Those numerical values are learned during training, and they can differ between runs because the initial weights may differ. So don’t expect every run to produce an identical set of weights.

Maria
To evaluate the model, the example uses it to predict the three species scores for each of the 50 test flowers. The scores are then interpreted by choosing the species with the highest score for each flower, and those predicted labels are compared with the actual labels.

Simon
The comparison is summarized in a confusion matrix, which counts correct and incorrect classifications. In the demonstration, 47 of the 50 test flowers are classified correctly, giving 94 percent accuracy. That result describes this particular split and run; it isn’t a guarantee that every run or data set will achieve the same accuracy.

Maria
One optional technique mentioned for larger data sets is to carry learned weights forward as starting weights for another training run. That gives the next run an informed starting point rather than treating it as entirely new. The material notes that this extra step is not particularly useful for its small Iris example.

Simon
After demonstrating the network, the material shifts to exploratory data analysis, using an employee-attrition data set. The point is that model fitting may be quick, but understanding and preparing the data often takes substantial effort. The example has about 2,940 employees, with roughly 474 recorded as having left—around 16 percent.

Maria
Exploratory analysis starts by examining variables individually and asking practical questions: Are there missing values? Are there outliers? Is the distribution strongly skewed? Are variables redundant or uninformative? Those checks help determine whether a feature should be transformed, removed, or included before modeling.

Simon
For a continuous variable such as age, summaries, a box plot, and a histogram show its range and distribution. In this data, ages run from 18 to 60, with a median around 36. The material also compares age distributions for employees with and without attrition and observes that younger employees appear more likely to leave, so age looks potentially informative.

Maria
For a categorical feature such as business travel, the analysis compares attrition counts or proportions across categories. If the proportions are broadly similar, the feature may have little apparent relationship with attrition in this data. The example judges business travel that way and suggests it could be left out.

Simon
The daily-rate variable is another example. Its values range broadly, and the analysis finds little meaningful difference between employees who left and those who stayed. On that evidence, daily rate also appears less useful for predicting attrition.

Maria
Department is checked in a similar way by comparing attrition within each department. The lesson is to look for differences in rates, not just raw counts: departments can have different numbers of employees. In the example, the observed departmental differences are not considered strong enough to make department a useful feature.

Simon
Distance from home, by contrast, appears to show a relationship: the analysis suggests that employees with longer commutes are more likely to have attrition. Education level and education field are categorical variables, so the same general approach applies—compare the attrition pattern across their categories and keep them if meaningful differences appear.

Maria
The analysis also warns against keeping variables that add no real information. Employee count, for example, is one for every row, so it cannot distinguish employees or explain different outcomes. A model might accept it as an input, but a person inspecting the data can recognize that it is useless.

Simon
Redundant features deserve attention, too. If a data set contains monthly salaries and a total salary that is calculated from those monthly values, the total already captures information from the components. Including all of them may add unnecessary overlap, so the example recommends considering the total rather than automatically including every related column.

Maria
Distribution shape can matter as well. Monthly income is described as strongly right-skewed, with many employees in lower ranges and fewer at higher values. The material suggests transforming a skewed variable, for example by using its logarithm, and then using the transformed feature rather than the raw value.

Simon
A similar concern applies to salary hike, which is also described as skewed. The example considers a Box–Cox transformation to make its distribution more suitable for modeling. The broader takeaway is to inspect distributions and consider a sensible transformation when a feature’s scale or skew could make learning less balanced.

Maria
Some features may be constant or nearly constant. The example notes that standard hours has the same value for everyone, so it offers no distinction and can be omitted. It also checks for missing values across columns with a single summary, rather than relying only on a visual inspection.

Simon
Feature screening is especially important for a neural network in the material’s workflow. A neural network will calculate and learn from all the inputs it is given; it doesn’t automatically know that a column is an employee identifier, constant, redundant, or irrelevant. Careful analysis can therefore prevent unhelpful inputs from muddying the model.

Maria
Other algorithms, such as the random forests and decision trees mentioned in the material, may have procedures that help select useful variables while building the model. But that doesn’t make data checks unnecessary. Understanding what each column represents can reveal problems an automated procedure won’t recognize.

Simon
So the complete workflow is bigger than the neural-network command itself: understand the problem, inspect and prepare the data, encode categories, scale where appropriate, choose a network structure and training settings, train with backpropagation, and evaluate on held-out data. Then investigate errors and refine the analysis rather than assuming the first model is the final answer.

Maria
That brings the core ideas together. Artificial neural networks use weighted connections, biases, layers, and activation functions to turn inputs into predictions. They learn by measuring error and updating weights through backpropagation, while thoughtful data preparation and independent testing help us judge whether the learned patterns are actually useful.

Ask anything
We've read this whole study set, so questions about it get the best answers.