-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathexample_iris.py
37 lines (30 loc) · 1013 Bytes
/
example_iris.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from fista import Fista
from sklearn.datasets import load_iris
import numpy as np
data = load_iris()
y = data.target
X = data.data
X = X[y<2]
y = y[y<2]
y[y==0] = -1
K1 = X[:, 0]
K2 = X[:, 1]
K3 = X[:, 2]
K4 = X[:, 3]
K1 = np.dot(K1[:, np.newaxis], K1[:, np.newaxis].transpose())
K2 = np.dot(K2[:, np.newaxis], K2[:, np.newaxis].transpose())
K3 = np.dot(K3[:, np.newaxis], K3[:, np.newaxis].transpose())
K4 = np.dot(K4[:, np.newaxis], K4[:, np.newaxis].transpose())
K = np.concatenate((K1, K2, K3, K4), axis=1)
fista = Fista(loss='squared-hinge', penalty='l11', lambda_=0.1, n_iter=50)
fista.fit(K, y)
print "pourcentage de bonne prediction avec l11: %d " % fista.score(K, y)
fista.penalty='l12'
fista.fit(K, y)
print "pourcentage de bonne prediction avec l12: %d " % fista.score(K, y)
fista.penalty='l21'
fista.fit(K, y)
print "pourcentage de bonne prediction avec l21: %d " % fista.score(K, y)
fista.penalty='l22'
fista.fit(K, y)
print "pourcentage de bonne prediction avec l22: %d " % fista.score(K, y)