# Description

Train the Optimum-Path Classifier.

# Load Data and metric type

``` 1 from numpy import *
2 from iaOPF import *
3
4 from scikits.learn import datasets
5
8     labels = iris.target
9     feats = iris['data']
10     return feats, labels
11
12 def euclidian(X, Y):
13     E = X - Y
14     return sqrt(dot(E, E))
15
17 feats = array(feats)
18 labels = array(labels)
19 labels = labels.reshape(150,1)
20
21 data = concatenate((feats,labels), axis=1)
22 data = data[0:100,:]
23 nsamples =5;
24 data = random.permutation(data)
25 data = data[0:nsamples,:]
26 #print data
27 feats = data[:,0:4]
28 labels = data[:,4]
29 labels = labels.reshape(nsamples,1)
30 labels = labels.astype('int')
```

# Calculate the adjacente matrix using euclidian distance

```1 from scipy.spatial import distance
2 from iaOPF import iaprim, iamstseeds, iadijkstra
3 from numpy import array
4
5 A = distance.squareform(distance.pdist(feats,euclidian))
```

# Calculate the MST

```1 B = iaprim(A)
```

# Calculate the MST seeds

```1 P = iamstseeds(B, labels)
2 print 'seeds'
3 print P
```
```seeds
[1, 2]
```

# Dissipate the seeds labels

```1 seeds_labels = labels[P]
2 OPF = iadijkstra(A, P, seeds_labels)
```

# Check results

```1 print 'costs to root: ', OPF[0]
2 print 'parents: ', OPF[1]
3 print 'labels: ', OPF[2]
4
5 #
```
```costs to root:  [ 0.81853528  0.          0.          0.9486833   0.3       ]
parents:  [ 4.  1.  2.  2.  1.]
labels:  [ 0.  0.  1.  1.  0.]
```

Test- Tie Zone