使用SVM而不是NN培训本地模型
我有一个具有数字功能和标签的数据集。我正在使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.