Рет қаралды 536
Dataset & Problem Statement:
www.kaggle.com...
Code :
clc
clear all
close all
warning off
data=readtable('Social_Network_Ads.csv');
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');
figure;
classification_model=fitcsvm(data,'Purchased~Age+EstimatedSalary','KernelFunction','polynomial','PolynomialOrder',5);
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 polynomial kernel');
Learn Machine Learning using MATLAB:
• Importing Dataset | MA...
#MachineLearning #MATLAB