File size: 3,173 Bytes
51972b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import os
import sys
from random import randint
import time
import uuid
import argparse
import streamlit as st
sys.path.append(os.path.abspath("../supv"))
from matumizi.util import *
from mcclf import *

def  genVisitHistory(numUsers, convRate, label):
    for i in range(numUsers):
        userID = genID(12)
        userSess = []
        userSess.append(userID)

        conv = randint(0, 100)
        if (conv < convRate):
            #converted
            if (label):
                if (randint(0,100) < 90):
                    userSess.append("T")
                else:
                    userSess.append("F")


            numSession = randint(2, 20)
            for j in range(numSession):
                sess = randint(0, 100)
                if (sess <= 15):
                    elapsed = "H"
                elif (sess > 15 and sess <= 40):
                    elapsed = "M"
                else:
                    elapsed = "L"

                sess = randint(0, 100)
                if (sess <= 15):
                    duration = "L"
                elif (sess > 15 and sess <= 40):
                    duration = "M"
                else:
                    duration = "H"

                sessSummary = elapsed + duration
                userSess.append(sessSummary)


        else:
            #not converted
            if (label):
                if (randint(0,100) < 90):
                    userSess.append("F")
                else:
                    userSess.append("T")

            numSession = randint(2, 12)
            for j in range(numSession):
                sess = randint(0, 100)
                if (sess <= 20):
                    elapsed = "L"
                elif (sess > 20 and sess <= 45):
                    elapsed = "M"
                else:
                    elapsed = "H"

                sess = randint(0, 100)
                if (sess <= 20):
                    duration = "H"
                elif (sess > 20 and sess <= 45):
                    duration = "M"
                else:
                    duration = "L"

                sessSummary = elapsed + duration
                userSess.append(sessSummary)

        print(",".join(userSess))
def trainModel(mlfpath):
    model = MarkovChainClassifier(mlfpath)
    model.train()

def predictModel(mlfpath):
    model = MarkovChainClassifier(mlfpath)
    model.predict()

def main():
    st.title("Markov Chain Classifier")

    # Add input fields for command line arguments
    op = st.selectbox("Operation", ["gen", "train", "pred"])
    numUsers = st.slider("Number of Users", 1, 1000, 100)
    convRate = st.slider("Conversion Rate", 1, 100, 10)
    label = st.checkbox("Add Label")
    mlfpath = st.text_input("ML Config File Path", value="false")

    # Call functions based on selected operation
    if op == "gen":
        st.button("Generate Visit History", on_click=lambda: genVisitHistory(numUsers, convRate, label))
    elif op == "train":
        st.button("Train Model", on_click=lambda: trainModel(mlfpath))
    elif op == "pred":
        st.button("Predict Model", on_click=lambda: predictModel(mlfpath))

if __name__ == "__main__":
    main()