0% found this document useful (0 votes)
4 views2 pages

Analyzing the Iris Dataset in Python

The document demonstrates how to load the Iris dataset using pandas and sklearn, create a DataFrame, and visualize the data with a scatter plot. It also outlines the process of splitting the data into training and testing sets, training a Support Vector Classifier (SVC) model, and evaluating its performance. Additionally, it discusses tuning model parameters such as regularization, gamma, and kernel type.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Analyzing the Iris Dataset in Python

The document demonstrates how to load the Iris dataset using pandas and sklearn, create a DataFrame, and visualize the data with a scatter plot. It also outlines the process of splitting the data into training and testing sets, training a Support Vector Classifier (SVC) model, and evaluating its performance. Additionally, it discusses tuning model parameters such as regularization, gamma, and kernel type.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import pandas as pd

from [Link] import load_iris


iris = load_iris()

iris.feature_names

[Link]

iris.target_names

df = [Link]([Link],columns=iris.feature_names)
[Link]()

df['target'] = [Link]
[Link]()

df[[Link]==1].head()

df[[Link]==2].head()

df0 = df[:50]
df1 = df[50:100]
df2 = df[100:]

# Commented out IPython magic to ensure Python compatibility.


import [Link] as plt
%matplotlib inline

#Sepal length vs Sepal Width (Setosa vs Versicolor)


[Link]('Sepal Length')
[Link]('Sepal Width')
[Link](df0['sepal length (cm)'], df0['sepal width (cm)'],color="green",marker='+')
[Link](df1['sepal length (cm)'], df1['sepal width (cm)'],color="blue",marker='.')

from sklearn.model_selection import train_test_split


X = [Link](['target'], axis='columns')
y = [Link]

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,random_state=10)

len(X_train)
len(X_test)

from [Link] import SVC


model = SVC()

[Link](X_train, y_train)

[Link](X_test, y_test)

[Link]([[4.8,3.0,1.5,0.3]])

#Tune parameters
#1. Regularization (C)
model = SVC(C=10)
[Link](X_train, y_train)
[Link](X_test,y_test)

#2. Gamma
model = SVC(gamma=100)
[Link](X_train, y_train)
[Link](X_test,y_test)

#3. Kernel
model = SVC(kernel='linear')
[Link](X_train, y_train)
[Link](X_test,y_test)

You might also like