<jupyter_start><jupyter_text>Load Data<jupyter_code>import pandas as pd
df = pd.read_csv("../data/demo1.csv", delimiter=',')
paneldata = df.values<jupyter_output><empty_output><jupyter_text>Group Label Mapping<jupyter_code>mapping = [['AAA', 'AA+', 'AA', 'AA-', 'A+', 'A', 'A-'], 
           ['BBB+', 'BBB', 'BBB-'],
           ['BB+', 'BB', 'BB-'], 
           ['B+', 'B', 'B-']]<jupyter_output><empty_output><jupyter_text>Etimation<jupyter_code>model = PanelCtmc(mapping=mapping)
model = model.fit(paneldata)<jupyter_output><empty_output><jupyter_text>Results<jupyter_code>print("Num Examples: {:d}".format(len(model.datalist)))
print("Num Transitions: {:d}".format(model.transcount.sum()))
print(model.statetime.round(1))
model.transmat.round(3)<jupyter_output>Num Examples: 59
Num Transitions: 136
[198.1 194.6 182.8 152.8  59.5]<jupyter_text>Multi-Step Simulation<jupyter_code>import numpy as np
s0 = np.zeros(shape=(len(model.statetime),))
s0[0] = 1<jupyter_output><empty_output><jupyter_text>Simple one-step prediction<jupyter_code>out = model.predict(s0)
out<jupyter_output><empty_output><jupyter_text>Multi-Step simulation<jupyter_code>out = model.predict(s0, steps=50)
out[:10].round(2)
import matplotlib.pyplot as plt
%matplotlib inline

fig, ax = plt.subplots(dpi=150, facecolor='white')
ax.stackplot(list(range(len(out))), out.T * 100, labels=list(range(len(out[0,:]))));
ax.legend(loc='upper right');
ax.set_xlabel('step');
ax.set_ylabel('percentage');
ax.set_xlim(0, len(out));
ax.set_ylim(0, 100);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19377835385612444, 'fraction_numerical': 0.03240440699935191, 'mean_word_length': 7.674157303370786, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '74398', 'license': 'MIT', 'n_tokens_mistral': 662, 'n_tokens_neox': 624, 'n_words': 86, 'path': 'examples/demo PanelCtmc sklearn API.ipynb', 'repo_name': 'kmedian/panelctmc', 'size': '1543'}