【问题标题】:Make predictions on new data using a SVM in matlab在 matlab 中使用 SVM 对新数据进行预测
【发布时间】:2018-11-29 02:11:45
【问题描述】:

我使用“fitcsvm”函数训练了一个 SVM 分类模型,并使用测试数据集进行了测试。现在我想用这个模型来预测新的(以前看不见的)数据的类别。应该怎么做?

以下是我使用的代码。

load FeatureLabelsNum.csv
load FeatureOne.csv

X = FeatureOne(1:42,:);
y = FeatureLabelsNum(1:42,:);

%dividing the dataset into training and testing 
rand_num = randperm(42);

%training Set
X_train = X(rand_num(1:34),:);
y_train = y(rand_num(1:34),:);

%testing Set
X_test = X(rand_num(34:end),:);
y_test = y(rand_num(34:end),:);

%preparing validation set out of training set

c = cvpartition(y_train,'k',5);

SVMModel = 
fitcsvm(X_train,y_train,'Standardize',true,'KernelFunction','RBF',...
'KernelScale','auto','OutlierFraction',0.05);

CVSVMModel = crossval(SVMModel);

classLoss = kfoldLoss(CVSVMModel)
classOrder = SVMModel.ClassNames
sv = SVMModel.SupportVectors;

figure
gscatter(X_train(:,1),X_train(:,2),y_train)
hold on
plot(sv(:,1),sv(:,2),'ko','MarkerSize',10)
legend('Resampled','Non','Support Vector')
hold off


X_test_w_best_feature =X_test(:,:);
bp = (predict(SVMModel,X_test)== y_test);

【问题讨论】:

    标签: matlab neural-network svm


    【解决方案1】:

    您已经在脚本中使用了 predict 函数,但是,只需传入新数据, score 就会包含您的预测标签。

    [~,score] = predict(SVMModel,X_new_data);
    

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 2015-08-11
      • 2017-11-20
      • 2019-11-16
      • 2013-04-30
      • 2018-07-27
      • 2018-09-05
      • 2018-10-15
      • 2016-03-13
      相关资源
      最近更新 更多