使用SVM而不是NN培训本地模型

发布于 2025-02-04 16:17:28 字数 743 浏览 5 评论 0原文

我有一个具有数字功能和标签的数据集。我正在使用TensorFlow(TFF)建立一个联合学习模型。 基本上,我拥有的模型是(神经网络),它在TFF教程中始终说明。 我想问是否有机会为当地客户(例如SVM)建立另一个模型?由于它适合我的数据集。

我的神经网络:

def create_keras_model():
  initializer = tf.keras.initializers.Zeros()
  return tf.keras.models.Sequential([
      tf.keras.layers.Input(shape=(18,)),
      tf.keras.layers.Dense(128),
      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()]
      )

I have a dataset with numeric features and labels. I am building a federated learning model using TensorFlow (TFF).
Basically, the model that I have is the (neural network) which is always explained in the TFF tutorials.
I want to ask if there is a chance to build another model for the local clients, such as SVM? since it suits my dataset.

My neural network:

def create_keras_model():
  initializer = tf.keras.initializers.Zeros()
  return tf.keras.models.Sequential([
      tf.keras.layers.Input(shape=(18,)),
      tf.keras.layers.Dense(128),
      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()]
      )

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长途伴 2025-02-11 16:17:28

TFF支持多种模型,包括几乎所有您可以在tf.keras中编写的模型。

您还可以通过子类别来直接创建一个TFF模型, https:https:// wwwwwww。 tensorflow.org/federated/api_docs/python/tff/learning/model 带有前向通过的代码。如果您对一种更有功能的方法感兴趣,也可以通过TFF的FunctionalModel

TFF supports a wide variety of models, including just about any model you can write in tf.keras.

You can also create a TFF model directly by subclassing https://www.tensorflow.org/federated/api_docs/python/tff/learning/Model with the code for your forward pass. If you are interested in a more functional approach, you could also define an SVM model via TFF's FunctionalModel https://www.tensorflow.org/federated/api_docs/python/tff/learning/models/FunctionalModel.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文