在Keras中应用SVM的不同方法
我想使用KERAS构建一个多级分类模型。 我的数据包含7个功能和4个标签。 如果我使用的是Keras,我已经看到了两种应用支持向量机(SVM)算法的方法。
首先: keras中的准SVM 通过使用(RandomFourierFeatures图层)呈现在这里 我已经建立了以下模型:
def create_keras_model():
initializer = tf.keras.initializers.GlorotNormal()
return tf.keras.models.Sequential([
layers.Input(shape=(7,)),
RandomFourierFeatures(output_dim=4822, kernel_initializer=initializer),
layers.Dense(units=4, activation='softmax'),
])
第二: 使用网络中的最后一层如所述在
def create_keras_model():
return tf.keras.models.Sequential([
tf.keras.layers.Input(shape=(7,)),
tf.keras.layers.Dense(64),
tf.keras.layers.Dense(4, kernel_regularizer=l2(0.01)),
tf.keras.layers.Softmax()
])
这里()用作损失函数。 我的问题是:这些方法是否适当,可以定义为应用SVM模型,还是仅仅是模型体系结构的近似值?简而言之,我可以说这是SVM模型的应用吗?
I want to build a multi-class classification model using Keras.
My data is containing 7 features and 4 labels.
If I am using Keras I have seen two ways to apply the Support vector Machine (SVM) algorithm.
First:
A Quasi-SVM in Keras
By using the (RandomFourierFeatures layer) presented here
I have built the following model:
def create_keras_model():
initializer = tf.keras.initializers.GlorotNormal()
return tf.keras.models.Sequential([
layers.Input(shape=(7,)),
RandomFourierFeatures(output_dim=4822, kernel_initializer=initializer),
layers.Dense(units=4, activation='softmax'),
])
Second:
Using the last layer in the network as described here as follows:
def create_keras_model():
return tf.keras.models.Sequential([
tf.keras.layers.Input(shape=(7,)),
tf.keras.layers.Dense(64),
tf.keras.layers.Dense(4, kernel_regularizer=l2(0.01)),
tf.keras.layers.Softmax()
])
note: CategoricalHinge()
was used as the loss function.
My question is: are these approaches appropriate and can be defined as applying of SVM model or it is just an approximation of the model architecture? in short, can I say this is applying of SVM model?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在数据上检查两个模型,如下所示:
我检查
MNIST
数据集并获得以下结果:输出:( colab )
< a href =“ https://i.sstatic.net/jgtkx.png” rel =“ nofollow noreferrer”>
You can check two models on your data like below:
I check on
mnist
dataset and get the below result:Output: (benchmark on colab)
我认为这只是SVM模型的近似值,因为SVM的纯定义位于该定理上,我们必须使用原始的二键优化方法来计算支持向量,并使用此支持向量来绘制最大净金度超平面。但是在神经网络和框架中,例如Keras(通常是Tensorflow)主要使用梯度下降优化方法来查找最佳参数。此外,我认为我们必须在纯SVM中优化的参数数量与神经网络有所不同,就像您在问题中所写的那样。
I think it's just an approximation of the SVM model, because the pure definition of SVM stand on this theorem that, we have to compute the support vector with the Primal-Dual Optimization approach and use this support vector for draw maximum-margin hyperplane. but in the neural network and the framework like Keras(in general tensorflow) mostly use the gradient descent optimization approach to find optimal parameter. Besides, I think the number of parameters, which we have to optimize in pure SVM is different with the neural network, like which you have been wrote in the question.