예제 #1
0
파일: log_reg.py 프로젝트: neuronalX/esn-lm
import numpy as np
import matplotlib.pyplot as plt
from esnlm.readouts import LogisticRegression

input_dim, output_dim = 2, 2
x = np.random.rand(300, input_dim - 1)
x = np.hstack([x, np.ones((x.shape[0], 1))])
dmodel = LogisticRegression(input_dim, output_dim)
pyr = dmodel.py_given_x(x)
y = dmodel.sample_y_given_x(x)

model = LogisticRegression(input_dim, output_dim)
model.fit(x, y, method='Newton-Raphson', nb_iter=20)
py = model.py_given_x(x)
plt.plot(x[:, 0], pyr[:, 0], 'x', color='black')
plt.plot(x[:, 0], pyr[:, 1], 'x', color='black')
plt.plot(x[:, 0], py[:, 0], 'xb')
plt.plot(x[:, 0], py[:, 1], 'xg')
plt.show()
예제 #2
0
파일: log_reg.py 프로젝트: zermelozf/esn-lm
import numpy as np
import matplotlib.pyplot as plt
from esnlm.readouts import LogisticRegression

input_dim, output_dim = 2, 2
x = np.random.rand(300, input_dim-1)
x = np.hstack([x, np.ones((x.shape[0], 1))])
dmodel = LogisticRegression(input_dim, output_dim)
pyr = dmodel.py_given_x(x)
y = dmodel.sample_y_given_x(x)
 
model = LogisticRegression(input_dim, output_dim)
model.fit(x,y, method='Newton-Raphson', nb_iter=20)
py = model.py_given_x(x)
plt.plot( x[:,0], pyr[:,0], 'x', color='black')
plt.plot( x[:,0], pyr[:,1], 'x', color='black')
plt.plot( x[:,0], py[:,0], 'xb')
plt.plot( x[:,0], py[:,1], 'xg')
plt.show()
예제 #3
0
       
initial_params = np.array(m.params)
m.log_likelihood(x, y)
method = 'CG'
print "... training using", method, ":",
m.fit(x, y, method=method)

print ""
print "Model Ini ->", init_value
print "Model Fin ->", m.log_likelihood(x, y) 
print "Model Rea ->", dm.log_likelihood(x, y)

##############
#### PLOT ####
##############
from matplotlib.pyplot import plot, get_cmap, title, show

py1 = dm.py_given_x(x)
py2 = m.py_given_x(x)

for i in range(py1.shape[1]):
    plot(x[:,0], py1[:, i], 'x', color='black')

cm = get_cmap('gist_rainbow')
NUM_COLORS = py2.shape[1]
for i in range(py2.shape[1]):
    col = cm(1.*i/NUM_COLORS)
    plot(x[:,0], py2[:, i], 'x', color=col)
    
title("Multivariable Logistic Regression")
show()
예제 #4
0
initial_params = np.array(m.params)
m.log_likelihood(x, y)
method = 'CG'
print "... training using", method, ":",
m.fit(x, y, method=method)

print ""
print "Model Ini ->", init_value
print "Model Fin ->", m.log_likelihood(x, y)
print "Model Rea ->", dm.log_likelihood(x, y)

##############
#### PLOT ####
##############
from matplotlib.pyplot import plot, get_cmap, title, show

py1 = dm.py_given_x(x)
py2 = m.py_given_x(x)

for i in range(py1.shape[1]):
    plot(x[:, 0], py1[:, i], 'x', color='black')

cm = get_cmap('gist_rainbow')
NUM_COLORS = py2.shape[1]
for i in range(py2.shape[1]):
    col = cm(1. * i / NUM_COLORS)
    plot(x[:, 0], py2[:, i], 'x', color=col)

title("Multivariable Logistic Regression")
show()