使用逻辑回归培训本地模型

发布于 2025-01-18 11:28:29 字数 756 浏览 0 评论 0原文

我正在使用 Tensorflow federated 构建联邦学习模型,并且正在遵循官方文档中提供的教程。 正如我所看到的,提供的大多数实现都使用神经网络作为本地机器学习模型。正如我刚刚在下面的代码片段中所做的那样。

def create_keras_model():
  initializer = tf.keras.initializers.Zeros()
  return tf.keras.models.Sequential([
      tf.keras.layers.Input(shape=(9,)),
      tf.keras.layers.Dense(4, kernel_initializer=initializer),
      tf.keras.layers.Softmax(),
  ])
def model_fn():
  keras_model = create_keras_model()
  return tff.learning.from_keras_model(
      keras_model,
      input_spec=train_data[0].element_spec,
      loss=tf.keras.losses.SparseCategoricalCrossentropy(),
      metrics=[tf.keras.metrics.SparseCategoricalAccuracy()])

因为我正在构建一个具有 (9) 个特征和 (4) 个目标标签的多分类模型。 我可以使用不同的 ML 模型进行本地训练,例如(逻辑回归)吗?我该如何调整?

I am building a federated learning model using Tensorflow federated, and I am following the tutorials provided in the official documentation.
As I can see, most of the implementations provided are using a neural network as the local ML model. As I just did in the following snippet.

def create_keras_model():
  initializer = tf.keras.initializers.Zeros()
  return tf.keras.models.Sequential([
      tf.keras.layers.Input(shape=(9,)),
      tf.keras.layers.Dense(4, kernel_initializer=initializer),
      tf.keras.layers.Softmax(),
  ])
def model_fn():
  keras_model = create_keras_model()
  return tff.learning.from_keras_model(
      keras_model,
      input_spec=train_data[0].element_spec,
      loss=tf.keras.losses.SparseCategoricalCrossentropy(),
      metrics=[tf.keras.metrics.SparseCategoricalAccuracy()])

Since I am building a multi-classification model with (9) features and (4) target labels.
Can I use a different ML model for local training, like (logistic regression )? and how can I adjust that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文