Python CPT

  • Find the open source code here: https://github.com/NeerajSarwan/CPT
  • To install
    • Type in terminal at the folder you want to save this library: git clone https://github.com/NeerajSarwan/CPT.git
    • Then type cd CPT
    • Now you can write python code as following

In [2]:
from CPT import *
import pandas as pd

In [5]:
train_df = pd.read_csv("train.csv")
train_df


Out[5]:
1 2 3 4 5 6 7 9
'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I'
'A' 'B' 'C' 'D' 'E' 'F' 'X' 'Y' 'Z'
'A' 'B' 'C' 'D' 'E' 'F' 'M' 'N' 'O'
'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'Y'
'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'X'
'E' 'F' 'S' 'M' 'I' 'L' 'I' 'N' 'G'
'S' 'M' 'I' 'L' 'I' 'N' 'G' 'E' 'F'
'S' 'M' 'I' 'L' 'E' 'B' 'A' 'T' 'F'

In [6]:
test_df = pd.read_csv("test.csv")
test_df


Out[6]:
1 2 3
0 'A' 'B' 'C'
1 'S' 'M' 'I'
2 'X' 'A' 'Z'

In [7]:
model = CPT()
train, test = model.load_files("train.csv", "test.csv")
model.train(train)


Out[7]:
True

In [8]:
predictions = model.predict(train,test,2,1)


100%|██████████| 3/3 [00:00<00:00, 2702.52it/s]

In [9]:
predictions


Out[9]:
[["'D'"], ["'N'"], []]