资源简介
这是pso优化的支持向量机程序,主要用于各种数据的分类
代码片段和文件信息
%% 清空环境变量
function chapter_PSO
close all;
clear;
clc;
format compact;
%% 数据提取
%wine=xlsread(‘C:\Users\Administrator\Desktop\聚类1.xlsx‘‘A1:D649‘)
%wine_labels=xlsread(‘C:\Users\Administrator\Desktop\聚类1.xlsx‘‘E1:E649‘)
%train_wine = [wine(1:200:);wine(249:290:);wine(305:380:);wine(392:590:);wine(635:645:)];
%train_wine_labels = [wine_labels(1:200);wine_labels(249:290);wine_labels(305:380);wine_labels(392:590:);wine_labels(635:645:)];
%test_wine = [wine(201:248:);wine(291:304:);wine(381:391:);wine(591:634:);wine(646:649:)];
%test_wine_labels = [wine_labels(201:248);wine_labels(291:304);wine_labels(381:391);wine_labels(591:634);wine_labels(646:649)];
%wine=xlsread(‘C:\Users\Administrator\Desktop\新处理3聚类升序.xlsx‘‘E1:G1650‘)
%wine_labels=xlsread(‘C:\Users\Administrator\Desktop\新处理3聚类升序.xlsx‘‘H1:H1650‘)
wine=xlsread(‘C:\Users\Administrator\Desktop\归一化\pso.xlsx‘‘A1:D150200‘)
wine_labels=xlsread(‘C:\Users\Administrator\Desktop\归一化\pso.xlsx‘‘E1:E150200‘)
train_wine = [wine(1:1000:);wine(100001:101000:);wine(144500:145000:);wine(149650:150150:)];
train_wine_labels = [wine_labels(1:1000);wine_labels(100001:101000);wine_labels(144500:145000:);wine_labels(149650:150150:)];
test_wine = [wine(1001:1050:);wine(101001:101050:);wine(145001:145050:);wine(150150:150200:)];
test_wine_labels = [wine_labels(1001:1050);wine_labels(101001:101050);wine_labels(145001:145050);wine_labels(150150:150200)];
%train_wine = [wine(1:20000:);wine(10000:110000:);wine(141000:143000:);wine(148000:150000:)];
%train_wine_labels = [wine_labels(1:20000);wine_labels(10000:110000);wine_labels(141000:143000:);wine_labels(148000:150000:)];
%test_wine = [wine(20001:22000:);wine(110001:111000:);wine(143001:143100:);wine(150001:150200:)];
%test_wine_labels = [wine_labels(20001:22000);wine_labels(110001:111000);wine_labels(143001:143100);wine_labels(150001:150200)];
%train_wine = [wine(1:500:);wine(551:1050:);wine(1111:1600:);wine(1651:2150:)];
%train_wine_labels = [wine_labels(1:500);wine_labels(551:1050);wine_labels(1111:1600:);wine_labels(1651:2150:)];
%test_wine = [wine(501:550:);wine(1051:1100:);wine(1601:1650:);wine(2151:2200:)];
%test_wine_labels = [wine_labels(501:550);wine_labels(1051:1100);wine_labels(2151:2200)];
%% 数据预处理
% 数据预处理将训练集和测试集归一化到[01]区间
[mtrainntrain] = size(train_wine);
[mtestntest] = size(test_wine);
dataset = [train_wine;test_wine];
% mapminmax为MATLAB自带的归一化函数
[dataset_scaleps] = mapminmax(dataset‘01);
dataset_scale = dataset_scale‘;
train_wine = dataset_scale(1:mtrain:);
test_wine = dataset_scale( (mtrain+1):(mtrain+mtest): );
%% 选择最佳的SVM参数c&g
[bestaccbestcbestg] = psoSVMcgForClass(train_wine_labelstrain_wine);
% 打印选择结果
disp(‘打印选择结果‘);
str = sprintf( ‘Best Cross Validation Accuracy = %g%% Best c = %g Best g = %g‘bestaccbestcbestg);
%str = sprintf( ‘Best c = %g Best g = %g‘bestcbestg);
disp(str);
%% 利用最佳的参数进行SVM网络训练
cmd = [‘-c ‘num2str(bestc)‘
相关资源
- matlab开发-能带计算
- matlab开发-FlockingAlgorithm
- 监督分类最大似然法MATLAB.zip
- 最大似然法_监督分类_遥感影像
- 基于贝叶斯决策的分类
- 贝叶斯分类器Matlab实现113478
- 科研常用代码预测分类评价
- matlab开发-MuellerStokesJonesCalculus
- 基于MATLAB的柑橘果实分类图像朴素贝
- hog+svm图像二分类
- MATLAB的EEG分类算法
- 多个随机森林的matlab代码 含有
- 用身高和/或体重数据进行性别分类的
- matlab开发-HX711的自定义数据库
- matlab开发-SMOTEBoost
- matlab开发-果蝇优化算法第二版
- matlab开发-多变量决策树
- matlab开发-水轮发电机模型
- matlab开发-交通警告标志识别标签代码
- matlab开发-RUSBoost
- matlab开发-基于遗传算法的机器人运动
- matlab开发-MPU6050加速度陀螺仪
- MATLAB水果分级[GUI界面,面积,直径,
- SVM分类与回归的matlab代码
- libsvm - 支持多类别分类的svm工具箱m
- bayes分类器完整版代码
- 谱聚类算法对数据点进行分类
- SVM算法对MNIST数据集分类
- 基于matlab的图像分类
- 基于Matlab的遥感影像BP神经网络分类算
评论
共有 条评论