# Learning From Data - Homework 1 - A solution in LIONoso

## Courtesy of Giovanni Pellegrini

Among the exercises of Homework1, we provide a sample solution for Exercise 7 about the Perceptron.
Before we provided a skeleton for inserting
a Python script in LIONoso, now we complete the script.

** Before proceeding, be sure to have Python installed on your computer**.

### Connecting the Perceptron Python script to LIONoso

You can download the Perceptron Learning Algorithm script here,
containing our solution
to exercise 7.

**Please see the notes for Windows users
below if the script doesn't work on Windows.**

You can load the script by dragging a **Parametric
table** element into the workbench, and by specifying the filename of your script.

In the above figure we just loaded the script (Exercise7-Perceptron.py).

Depending on the script content, in the left panel you can specify the
parameter values, in our case the number of experiments to
perform (default 1000) and the dimension of the training set (default
10).

By clicking the "Compute" button, the script is launched and a table containing the results of each experiment is produced. The script outputs the number of iterations and the disagreement reached in each experiments, a row for every run.

To compute the average of the results you can open a Bubblechart from the output table (right click on the table generated, select "New panel"->"Bubble") and drag the "Iteration" column on the y axis. Then select the "Advanced properties" tab in the left panel and elect "Show polynomial fit" with 0 degree. A red line will appear on the plot showing the average value.

### Results

The results of the tests are the average of 10 executions for each combination
(10x 1000 tests 10 points, 10x 1000 tests 100 points).
In our runs (your results can of course be somewhat different depending on your
random number generator):

**1000 Tests 10 Points:**

Average number of iterations: 13.578

Average number of disagreement: 0.111427

**1000 Tests 100 Points:**

Average number of iterations: 245.424

Average number of disagreement: 0.013562