如何为不同的实现提取学习到的 ML 模型?

How to extract learned ML model for distinct implementation?

我是一名电子爱好者,他试图使用 ML 对传感器中的误差进行建模,我在 python 中使用 scikit-learn 中的 SVM 在我的 PC 中使用 SVM 对传感器数据模型进行了训练。

但过滤数据的用例是非常即时的,即传感器数据用于维持四轴飞行器的飞行,原始传感器数据应至少以 200 Hz 的速率通过学习模型进行过滤,确定我的电脑可以做到,但我不能把我的电脑放在四轴飞行器上,因此我需要那个模型 运行 在一个很小的 ​​CPU/microcontroller 上但是,我选择的合适的微控制器不支持 python.

那么我如何 get/extract 学习模型的数学本质,换句话说,我如何获得通过训练近似的函数,以便我可以在我选择的任何微控制器中实现它。

只是一个尝试学习的初学者,任何帮助将不胜感激。

由于计算能力有限,也许一个好的选择是使用逻辑回归,它简单,计算成本低,易于重现,它是一个简单的函数,如y = w0 + w1.x1 + w2。 x2 + ... + wn.xn.

要提取函数,您可以使用 scikit-learn LogisticRegression 模型 (http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) 中的以下属性:

Attributes: coef_ : array, shape (1, n_features) or (n_classes, n_features)

Coefficient of the features in the decision function.

coef_ is of shape (1, n_features) when the given problem is binary.

intercept_ : array, shape (1,) or (n_classes,)

Intercept (a.k.a. bias) added to the decision function.

If fit_intercept is set to False, the intercept is set to zero. intercept_ is of shape(1,) when the problem is binary.

如果你仍然想使用 SVM,我认为这个类似的问题可能对你有用:How to extract info from scikits.learn classifier to then use in C code