Machine learning package for state based ML.
Project description
statebasedml
Overview
statebasedml is a Python library for training data on state based machine learning data.
Installation instructions
python3 -m pip install --upgrade pip
python3 -m pip install statebasedml
Basic Example
I start here with an example - detailed documentation is below. Here we train the model which numbers are even and which numbers are odd. If you run this script, you should get an accuracy of over 0.99.
model = {}
for i in range(10000):
x = random.randint(0,9)
guess = random.randint(0,1)
if guess == x%2:
result = "correct"
else:
result = "wrong"
test_dict = {
str(x): {
"result": result,
"options": ["0","1"],
"choice": str(guess)
}
}
model = data.update(datadict=test_dict,model=model)
accuracy = 0
for i in range(1000):
x = random.randint(0,9)
test_dict = {
str(x) : {
"options": ["0","1"],
"desired_result": "correct"
}
}
classify_dict = data.classify(datadict=test_dict,model=model)
classification = classify_dict[str(x)]
if classification == str(x%2):
accuracy = (accuracy*i + 1)/(i+1)
else:
accuracy = (accuracy*i)/(i+1)
return accuracy
print(odd_even_test())
Classes
The statebasedml library has two classes:
bitfold
: compresses states in order to shrink big datadata
: trains, tests, and classifies input datasets
bitfold
Import statebasedml.bitfold
from statebasedml import bitfold
bitfold has 2 methods
gen_param()
: generates the parameters for a foldfold()
: actually folds the input data
gen_param
request syntax
fold_parameters = bitfold.gen_param(
size = 256
)
parameters
size
(integer): The number of bits of the largest sized string that you want to fold. You can determine the bit size of a string with8*len(string)
response syntax
```python
{
"mapping":mapping,
"ops":ops
}
```
fold
request syntax
folded_value = bitfold.fold(
value = string,
new_size = 123,
mapping = [1, 2, 3],
ops = [1, 2, 3]
)
parameters
value
(string): This is simply the input value that you want to shrink.new_size
(integer): The number of bits of the new string that you want to be generated. If you want to output strings of lengthl
then this value isl * 8
.mapping
(list): This is a mapping of the bits to be folded. This paramater is generated withfold_parameters = bitfold.gen_param()
. Then you should havemapping = fold_parameters["mapping"]
.ops
(list): This is a list of the operations to be perfomed on the mapping. This paramater is generated withfold_parameters = bitfold.gen_param()
. Then you should haveops = fold_parameters["ops"]
.
response syntax
The fold()
function simply outputs a folded string.
data
Import statebasedml.data
from statebasedml import data
data has 4 methods
train()
: generates a model based on tagged input dataupdate()
: updates a model with new tagged input datatest()
: tests a trained model based on additional tagged input dataclassify()
: classifies untagged data using a provided model
train
request syntax
trained_model = data.train(
datadict = {
"key1": {
"result": string,
"options": [option1, option2, ..., optionN],
"choice": optionN
},
...,
"keyN": ...
}
)
parameters
datadict
(dict): The function takes a single dictionary with the below values.key
(string): The dictionary should include one or more keys. The key is the measured state of the system that you want to capture.result
(string): Result is the tag for that key and, if applicable, choice.options
(list) [OPTIONAL]: .choice
(string) [OPTIONAL]: .
response syntax
```python
{
"key1": {
"option_dict": {
"option1": {
"count": 123,
"result_dict": {
"result1":count1,
"result2":count2,
...,
"resultN":countN
}
},
...,
"optionN": ...
}
},
...,
"keyN": {
"count": 123,
"result_dict": {
"result1": count1,
...,
"resultN": countN
}
}
}
```
update
The update function is similar to the train function, except you add a model to the second argument. In fact, the train function can operate as the update function if you pass a model to it as a model=model
argument. I just added update()
for syntatic convenience.
request syntax
updated model = data.update(
datadict = datadict,
model = model
)
parameters
datadict
(dict): This takes the same format as the input specified in thetrain()
function above.model
(dict): This takes the same format as the output specified in thetrain()
function above.
response syntax
The update()
function outputs a model with the same format as the train()
function above.
test
classify
request syntax
classifications = data.classify(
datadict = {
"key1": {
"options": [option1, option2, ..., optionN],
"desired_result": result
},
...,
"keyN": {
"results": [result1, result2, result3]
}
},
model = model,
)
response syntax
```python
{
"key1": "string",
"key2": "string",
...,
"keyN": "string"
}
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for statebasedml-0.0.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85c4a89744320f8e37e338fb135e00a50071ba8266f55312a24e9dd7e3abb263 |
|
MD5 | 2979f0671b1791389a074fc0150cee15 |
|
BLAKE2b-256 | 6846f8378992cd8d113cf903835b06b69ad3b86811ab62bc523a319103b25a4f |