SVM with Gaussian Kernel & Visualizing the Support Vectors | MATLAB

preview_player
Показать описание
Code:

clc
clear all
close all
warning off
stand_age=(data.Age-mean(data.Age))/std(data.Age);
data.Age=stand_age;
stand_estimted_salary=(data.EstimatedSalary-mean(data.EstimatedSalary))/std(data.EstimatedSalary);
data.EstimatedSalary=stand_estimted_salary;
classification_model=fitcsvm(data,'Purchased~Age+EstimatedSalary','KernelFunction','linear');
e=min(data.Age):0.01:max(data.Age);
f=min(data.EstimatedSalary):0.01:max(data.EstimatedSalary);
[x1 x2]=meshgrid(e,f);
x=[x1(:) x2(:)];
ms=predict(classification_model,x);
gscatter(x1(:),x2(:),ms,'cym');
hold on;
gscatter(data.Age,data.EstimatedSalary,data.Purchased,'rgb','.',30);
title('SVM Classification Visualization using linear kernel');
sv=data(classification_model.IsSupportVector,:);
gs=[sv.Age sv.EstimatedSalary];
plot(gs(:,1),gs(:,2),'ko','MarkerSize',15,'LineWidth',2);
figure;
classification_model=fitcsvm(data,'Purchased~Age+EstimatedSalary','KernelFunction','gaussian');
e=min(data.Age):0.01:max(data.Age);
f=min(data.EstimatedSalary):0.01:max(data.EstimatedSalary);
[x1 x2]=meshgrid(e,f);
x=[x1(:) x2(:)];
ms=predict(classification_model,x);
gscatter(x1(:),x2(:),ms,'cym');
hold on;
gscatter(data.Age,data.EstimatedSalary,data.Purchased,'rgb','.',30);
title('SVM Classification Visualization with Gaussian kernel');
sv=data(classification_model.IsSupportVector,:);
gs=[sv.Age sv.EstimatedSalary];
plot(gs(:,1),gs(:,2),'ko','MarkerSize',15,'LineWidth',2);

Learn Machine Learning using MATLAB:

#MachineLearning #MATLAB
Рекомендации по теме
Комментарии
Автор

most underrated playlist i have ever seen

__SANTHOSHR