The example evaluates a given loan sequence against the two models: model 1 (trained on default loan cases) and model 2 (trained on paid loan cases). The models are trained and referenced from the loan default prediction example from HMMUnsupervised.
Input
The ObservationTable, test_loan_prediction, is a test loan sequence, which HMMEvaluator uses to predict whether this loan is more likely to be paid in full or to default. The ObservationTable does not include observations of 7 (default) or 8 (paid). The sequence of observations in this table is the same for evaluation of both models (that is, model_id = 1 and model_id = 2).
SELECT * FROM test_loan_prediction;
model_id seq_id seq_vertex_id observed_id -------- ------ ------------- ----------- 2 17 0 1 1 17 0 1 2 17 1 1 1 17 1 1 2 17 2 1 1 17 2 1 2 17 3 1 1 17 3 1 2 17 4 1 1 17 4 1 2 17 5 1 1 17 5 1 2 17 6 1 1 17 6 1 2 17 7 2 1 17 7 2 2 17 8 1 1 17 8 1 2 17 9 1 1 17 9 1 2 17 10 1 1 17 10 1 2 17 11 1 1 17 11 1 2 17 12 1 1 17 12 1 2 17 13 1 1 17 13 1 2 17 14 3 1 17 14 3 2 17 15 4 1 17 15 4 2 17 16 5 1 17 16 5 2 17 17 6 1 17 17 6 2 17 18 6 1 17 18 6 2 17 19 6 1 17 19 6 2 17 20 6 1 17 20 6 2 17 21 6 1 17 21 6 2 17 22 6 1 17 22 6 2 17 23 6 1 17 23 6 2 17 24 6 1 17 24 6 2 17 25 6 1 17 25 6
SQL Call
The following SQL call creates the probabilities for each observation of the sequence for each model.
SELECT * FROM HMMEvaluator ( ON pi_loan AS InitialStateProbs PARTITION BY model_id ON A_loan AS TransitionProbs PARTITION BY model_id ON B_loan AS EmissionProbs partition by model_id ON test_loan_prediction AS ObservationTable PARTITION BY model_id ORDER BY seq_id, seq_vertex_id USING InitStateModelColumn ('model_id') InitStateColumn ('state') InitStateProbColumn ('probability') TransAttributeColumn ('model_id') TransFromStateColumn ('from_state') TransToStateColumn ('to_state') TransProbColumn ('probability') EmitModelColumn ('model_id') EmitStateColumn ('state') EmitObsColumn ('observed') EmitProbColumn ('probability') ModelColumn ('model_id') SeqColumn ('seq_id') ObsColumn ('observed_id') ) AS dt order by 1, 2;
Output
model_id seq_id observed_id sequence_probability change_rate -------- ------ ----------- ---------------------- ------------------- 1 17 1 0.7199629735192733 0.14641556009646198 1 17 1 0.524569452874964 0.14641570219132774 1 17 1 0.44776424808406834 0.14641570219149402 1 17 1 0.382204531284593 0.14641570219149438 1 17 1 2.6218579940030134E-4 0.9164498509928408 1 17 1 2.0332062216725988E-4 0.22451703092876893 1 17 1 1.7354363560893247E-4 0.1464533515632843 1 17 1 1.4813410876512106E-4 0.1464157804154217 1 17 1 1.2644494920337679E-4 0.14641570224811787 1 17 1 1.0793142317718651E-4 0.14641570219157365 1 17 3 2.7327134169588977E-6 0.9746810211844171 1 17 5 8.121584523747848E-8 0.8175492857860137 1 17 6 4.923578806530361E-8 0.39376622971371983 1 17 6 2.37312122630068E-8 0.5180088875284977 1 17 6 1.4095131684809992E-8 0.4060509202565236 1 17 6 6.920349698991573E-9 0.5090255377713513 1 17 6 4.0411630946832795E-9 0.4160464036561398 1 17 6 2.014773095161198E-9 0.5014373218908397 1 17 6 1.1600883622892982E-9 0.4242089270124575 1 17 6 5.857921792975991E-10 0.4950452066068425 1 17 6 3.333775769971005E-10 0.43089445578320834 1 17 4 4.4513854378352796E-7 0.8371074913962618 1 17 2 0.003138065012640915 0.9917895661726096 1 17 1 0.6145490893185858 0.14641570202618986 1 17 1 0.8434584088723958 0.14626415486613584 1 17 1 0.9879618077183383 NULL 2 17 1 0.669153384146038 0.17898447381623 2 17 1 0.4356118429863769 0.19530872762923937 2 17 1 0.3497441100278714 0.19711983120071153 2 17 1 0.28057030359673196 0.19778404967456617 2 17 1 0.0038532513323295547 0.31835786370559743 2 17 1 0.0026775402641211945 0.30512182227614054 2 17 1 0.0020790994852560867 0.22350393265197985 2 17 1 0.00162492088322131 0.2184496726854966 2 17 1 0.0012960583920260918 0.20238677131360863 2 17 1 0.00103483642326063 0.2015510800845175 2 17 3 4.792133961354275E-5 0.9536918700034261 2 17 5 5.125335431147303E-7 0.9303325996737426 2 17 6 2.8214609520483855E-8 0.944950706349832 2 17 6 7.783038818895011E-10 0.9724148625440147 2 17 6 3.900458725776822E-11 0.9498851436240096 2 17 6 1.1619713820935578E-12 0.9702093660313728 2 17 6 5.4342848024295455E-14 0.953232197572384 2 17 6 1.7156886827872147E-15 0.9684284363966318 2 17 6 7.6187572104338E-17 0.9555935917345053 2 17 6 2.5133940603566225E-18 0.9670104455236537 2 17 6 1.0734344516127147E-19 0.9572914383564507 2 17 4 7.356863335139522E-6 0.846480432423879 2 17 2 0.0056528948654449495 0.979852126925129 2 17 1 0.5413403350368006 0.1910071026127294 2 17 1 0.8150313396098428 0.1481947099680822 2 17 1 0.9568282201902067 NULL
Download a zip file of all examples and a SQL script file that creates their input tables from the attachment in the left sidebar.