Classification prediction | Matlab implements CNN-GSSVM convolutional neural network combined with grid search algorithm to optimize support vector machine multi-feature classification prediction

Classification prediction | Matlab implements CNN-GSSVM convolutional neural network combined with grid search algorithm to optimize support vector machine multi-feature classification prediction

predictive effect

1
2
3
4
5

basic introduction

Classification prediction | Matlab implements CNN-GSSVM convolutional neural network combined with grid search algorithm to optimize support vector machine multi-feature classification prediction 1.Matlab
implements CNN-GSSVM convolutional neural network combined with grid search to optimize support vector machine multi-feature classification prediction, run Environment Matlab2020b and above;
2. The command window outputs the classification accuracy rate, and the data and program content can be obtained in the download area.
3. data is a data set, input 12 features, divided into four categories, MainCNN_GSSVMNC is a program, using CNN to extract features, grid search optimization LIBSVM for data classification.

Model description

CNN-GSSVM is a multi-feature classification prediction method that combines convolutional neural network (CNN) with grid search support vector machine (GSSVM). The core idea of ​​this method is to use CNN to extract multiple features, and then use GSSVM to classify and predict these features to improve classification accuracy.
Specifically, the steps of the CNN-GSSVM method are as follows:

  • Use CNN to extract multiple features: First, input training data into CNN for training to obtain multiple feature maps. These feature maps can capture image features at different scales and angles.
  • Feature selection: Through the feature selection method, the most representative feature map is selected to reduce the feature dimension.
  • Grid Search: Use GSSVM to make classification predictions on selected features. In GSSVM, multiple parameters need to be set, such as the penalty parameter C and the kernel function parameter gamma. With a grid search approach, the best combination of parameters can be found to maximize classification accuracy.
  • Model Evaluation: Evaluate model performance using test data. Multiple metrics can be calculated, such as accuracy, etc.

In general, the CNN-GSSVM method can effectively use multiple features extracted by CNN to perform classification prediction through GSSVM and improve classification accuracy. At the same time, through the grid search method, the best combination of parameters can be found to further improve the classification performance.

programming

  • Private letter blogger with complete source code.

The following is the pseudocode of the CNN-GSSVM method:

  1. CNN feature extraction
Input: training data set X_train, test data set X_test
Output: CNN features X_train_cnn for training data, CNN features X_test_cnn for test data
Define the CNN model
Train the training data set X_train to get the CNN model
Feature extraction is performed on the training data set X_train and the test data set X_test respectively
Save the CNN features of the training data as X_train_cnn, and save the CNN features of the test data as X_test_cnn
  1. feature selection
Input: CNN feature X_train_cnn of training data, label y_train of training data
Output: Selected features X_train_selected_cnn, test data selection features X_test_selected_cnn
Perform feature selection on the CNN feature X_train_cnn of the training data
Using feature selection methods, select the most representative features
Save the CNN features of the selected training data as X_train_selected_cnn, and save the selected features of the test data as X_test_selected_cnn
  1. grid search
Input: CNN feature X_train_selected_cnn of selected training data, label y_train of training data, selection feature X_test_selected_cnn of test data, label y_test of test data
Output: the best SVM model model
Define the SVM model
Define the search range C_range of the parameter C
Defines the search range gamma_range for the parameter gamma
Define the evaluation index metric
Use the grid search method to search for the best parameter combination within the parameter range to maximize the evaluation index
Get the best SVM model model
  1. model evaluation
Input: the best SVM model model, the selection feature X_test_selected_cnn of the test data, the label y_test of the test data
Output: model performance evaluation indicators accuracy, recall, F1-score
Predict the selected features of the test data X_test_selected_cnn
Calculation model performance evaluation indicators accuracy, recall, F1-score and other indicators
% 定义CNN模型
net = alexnet;

% 加载数据
imds_train = imageDatastore('train_dir', 'IncludeSubfolders', true, 'LabelSource', 'foldernames');
imds_test = imageDatastore('test_dir', 'IncludeSubfolders', true, 'LabelSource', 'foldernames');

% 提取训练数据的CNN特征
X_train_cnn = activations(net, imds_train, 'fc7', 'MiniBatchSize', 32, 'OutputAs', 'columns');
y_train = imds_train.Labels;

% 提取测试数据的CNN特征
X_test_cnn = activations(net, imds_test, 'fc7', 'MiniBatchSize', 32, 'OutputAs', 'columns');
y_test = imds_test.Labels;
% 定义参数范围和评价指标
C_range = [0.01, 0.1, 1, 10, 100];
gamma_range = [0.001, 0.01, 0.1, 1, 10];
metric = 'accuracy';

% 使用网格搜索方法,搜索最佳参数组合
svm_model = LIBSVM(X_train_selected_cnn, y_train, svm_params);

% 得到最佳的SVM模型
model = svm_model.BestModel;
% 对测试数据进行预测
y_pred = predict(model, X_test_selected_cnn);

% 计算模型性能评估指标
accuracy = sum(y_pred == y_test) / numel(y_test);
C = confusionmat(y_test, y_pred);
precision = diag(C) ./ sum(C, 1)';
recall = diag(C) ./ sum(C, 2);
F1_score = 2 .* precision .* recall ./ (precision + recall);

summarize

The CNN-GSSVM method can effectively use multiple features extracted by CNN to perform classification prediction through GSSVM and improve classification accuracy. At the same time, through the grid search method, the best combination of parameters can be found to further improve the classification performance. CNN-GSSVM is suitable for various image, speech, text and other classification tasks.

Guess you like

Origin blog.csdn.net/kjm13182345320/article/details/130710930
Recommended