利用SVM,sklearn对iris数据集进行分类

摘要

hello,又见面了,这次写的是New York university homework4 ,题目是SVM Classifier with different kernels

首先,了解一下数据集以及目标

Dataset: using the one of most popular classification dataset which is Iris dataset. Iris dataset is having 4 features of iris flower and one target class. The flower species type is the target class which has 3 types.
The idea of implementing SVM classifier in Python is to use the iris features to train an svm classifier and use the trained svm model to predict the Iris species type.

1, Importing Iris dataset from Scikit-Learn and understand Iris dataset

# Required Packages 
from sklearn import datasets
from sklearn import svm
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
import pandas as pd
%matplotlib inline
# import iris data to model Svm classifier (3 points)
iris = datasets.load_iris()
# Using the DESCR key over the iris_dataset to describ the dataset (3 points)
iris.DESCR
# To get the iris features and the target classes (3 points)
X = iris.data
y = iris.target
# To check the target data (3 points)
print(y)

2, Visualizing the Iris dataset

2.1 Visualizing the relationship between sepal and target classes

X = iris.data[:,:2]
y = iris.target
plt.scatter(X[y==0,0],X[y==0,1],color = 'r',marker='o')
plt.scatter(X[y==1,0],X[y==1,1],color = 'b',marker='*')
plt.scatter(X[y==2,0],X[y==2,1],color = 'g',marker='+')
plt.title('the relationship between sepal and target classes')
plt.xlabel('sepal length')
plt.ylabel('sepal width')
plt.show()

结果:
1
2.2 Visualizing the relationship between Petal and target classes

X = iris.data[:,2:]
y = iris.target
plt.scatter(X[y==0,0],X[y==0,1],color = 'r',marker='o')
plt.scatter(X
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值