CircuitML
所属分类:Python编程
开发工具:Jinja
文件大小:0KB
下载次数:0
上传日期:2023-10-06 19:59:32
上 传 者:
sh-1993
说明: 从Python的机器学习模型生成微控制器的C代码,
(Generate C code for microcontrollers from Python s machine learning models,)
文件列表:
LICENSE (1073, 2023-10-06)
MANIFEST (2954, 2023-10-06)
circuitml/ (0, 2023-10-06)
circuitml/__init__.py (206, 2023-10-06)
circuitml/__init__.pyc (504, 2023-10-06)
circuitml/circuitml.py (2349, 2023-10-06)
circuitml/decisiontreeclassifier.py (591, 2023-10-06)
circuitml/decisiontreeregressor.py (759, 2023-10-06)
circuitml/gaussiannb.py (505, 2023-10-06)
circuitml/linear_regression.py (518, 2023-10-06)
circuitml/logisticregression.py (545, 2023-10-06)
circuitml/pca.py (387, 2023-10-06)
circuitml/platforms.py (388, 2023-10-06)
circuitml/principalfft.py (584, 2023-10-06)
circuitml/randomforestclassifier.py (691, 2023-10-06)
circuitml/randomforestregressor.py (778, 2023-10-06)
circuitml/rvm.py (836, 2023-10-06)
circuitml/sefr.py (412, 2023-10-06)
circuitml/svm.py (1119, 2023-10-06)
circuitml/templates/ (0, 2023-10-06)
circuitml/templates/__init__.py (44, 2023-10-06)
circuitml/templates/__pycache__/ (0, 2023-10-06)
circuitml/templates/__pycache__/__init__.cpython-37.pyc (160, 2023-10-06)
circuitml/templates/_skeleton.jinja (548, 2023-10-06)
circuitml/templates/classmap.jinja (477, 2023-10-06)
circuitml/templates/decisiontree/ (0, 2023-10-06)
circuitml/templates/decisiontree/__init__.py (45, 2023-10-06)
circuitml/templates/decisiontree/decisiontree.jinja (111, 2023-10-06)
circuitml/templates/decisiontree/decisiontree_regressor.jinja (121, 2023-10-06)
circuitml/templates/decisiontree/tree.jinja (378, 2023-10-06)
circuitml/templates/decisiontree/tree_regressor.jinja (396, 2023-10-06)
circuitml/templates/dot.jinja (550, 2023-10-06)
circuitml/templates/gaussiannb/ (0, 2023-10-06)
circuitml/templates/gaussiannb/__init__.py (44, 2023-10-06)
... ...
# CircuitML
**CircuitML** is a **machine learning** library that allows you to convert machine learning models to micro-controllers and other embedded devices.
## Install
```
pip install circuitml
```
## Supported Models
CircuitML can be used to convert the following machine learning models:
- Linear Regression
- Logistic Regression
- Decision Tree
- GaussianNB
- Support Vector Machines (SVC and OneClassSVM)
- Relevant Vector Machines (from `skbayes.rvm_ard_models` package)
- Random Forest
- GaussianNB
- PCA
- [SEFR](https://arxiv.org/abs/2006.04620)
## Usage
### Basic Usage
```python
from circuitml import port
from sklearn.svm import SVC
from sklearn.datasets import load_iris
iris = load_iris()
X = iris.data
y = iris.target
clf = SVC(kernel='linear').fit(X, y)
print(port(clf))
```
You can pass classmap to `port` function to map class names to integers :
```python
from circuitml import port
from sklearn.svm import SVC
from sklearn.datasets import load_iris
iris = load_iris()
X = iris.data
y = iris.target
clf = SVC(kernel='linear').fit(X, y)
print(port(clf, classmap={
0: 'setosa',
1: 'virginica',
2: 'versicolor'
}))
```
### PCA
```python
from sklearn.decomposition import PCA
from sklearn.datasets import load_iris
from circuitml import port
X = load_iris().data
pca = PCA(n_components=2, whiten=False).fit(X)
print(port(pca))
```
### [SEFR](https://arxiv.org/abs/2006.04620)
```shell script
pip install sefr
```
```python
from sefr import SEFR
from circuitml import port
clf = SEFR()
clf.fit(X, y)
print(port(clf))
```
### DecisionTree and RandomForest
```python
from sklearn.datasets import load_boston,load_iris
from sklearn.tree import DecisionTreeRegressor, DecisionTreeClassifier
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
from circuitml import port
X, y = load_boston(return_X_y=True)
# regr = DecisionTreeRegressor(max_depth=10, min_samples_leaf=5).fit(X, y)
regr = RandomForestRegressor(n_estimators=10, max_depth=10, min_samples_leaf=5).fit(X, y)
with open('RandomForestRegressor.h', 'w') as file:
file.write(port(regr))
X,y = load_iris(return_X_y=True)
# clf = DecisionTreeClassifier(max_depth=10, min_samples_leaf=5).fit(X, y)
clf = RandomForestClassifier(n_estimators=10, max_depth=10, min_samples_leaf=5).fit(X, y)
with open('RandomForestClassifier.h', 'w') as file:
file.write(port(clf))
```
### Use exported model in C++
```cpp
// Arduino sketch
#include "RandomForestRegressor.h"
ML::Port::RandomForestRegressor regressor;
float X[] = {...};
void setup() {
...
}
void loop() {
float y_pred = regressor.predict(X);
}
```
近期下载者:
相关文件:
收藏者: