Rohmad Hidayat's Blog


My Notes on Mobile Technology, Python GUI, Python Web Framework, Software Development, Database, Server, Embedded System, Mini Computer

Satu lagi, “Monte – machine learning in Python”

Buat temen2 yang tertarik dengan machine learning, artificial intelligent dengan neural network, k-nearest neighbors, logistic regression, kmeans dst….anda bisa mencoba modul Monte Python.

#This example file shows how to build a simple model using monte, how to
#train the model using the provided trainers, and how to apply the trained
#model to some data.

from numpy import array
from pylab import randn
from monte.arch.crf import ChainCrfLinear #all ready-to-use models reside in monte.arch
from monte.gym import trainer #everything to do with training resides in

#Make a linear-chain CRF:
mycrf = ChainCrfLinear(3,2)

#Make a trainer (that does 5 steps per call), and register mycrf with it:
mytrainer = trainer.Conjugategradients(mycrf,5)

#Produce some stupid toy data for training:
inputs = randn(10,3)
outputs = array([0,1,1,0,0,0,1,0,1,0])

#Train the model. Since we have registered our model with this trainer,
#calling the trainers step-method trains our model (for a number of steps):
for i in range(20):
print mycrf.cost((inputs,outputs),0.001)

#Apply to some stupid test data:
testinputs = randn(15,3)
predictions = mycrf.viterbi(testinputs)
print predictions


Filed under: Programming

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: