# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/syno3/Data-science-portfolio/blob/main/iris_SVM_001.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + id="LHcUwk_bDbPy"
#importing libraries
from sklearn import datasets
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn import svm
from sklearn.metrics import accuracy_score

# + id="n1_nwAqzDkpM"
#load datasets
iris = datasets.load_iris()

# + id="9TE4iSlNDoGj"
#mapping data into x and y
x = iris.data
y = iris.target

# + id="GumAz641DvSc"
classes = ['Iris Setosa', 'Iris Versicolor', 'Iris Virginica']

# + id="eTszPFVODxsg"
#splitting data into training and testing
x_train, x_test, y_train, y_test = train_test_split(x,y, test_size=0.2)

# + colab={"base_uri": "https://localhost:8080/"} id="zQV94FdbD4-J" outputId="406f62c8-a723-4710-dcc3-9bb46b15e81d"
#creating model and training
model = svm.SVC()
model.fit(x_train, y_train)

# + id="JbByAznxD_ib"
#create prediction and checking accuracy level
predictions = model.predict(x_test)
accuracy = accuracy_score(y_test, predictions)

# + colab={"base_uri": "https://localhost:8080/"} id="LPocOVA0EGil" outputId="302992bc-7074-4362-e6bd-760c9d3ad041"
#printing out the data
print('actual; ', y_test)
print('predictions; ', predictions)
print('accuracy ; ', accuracy)

StarcoderdataJupyterScriptsDedupFiltered