Practical 5
Practical 5
Mounted at /content/drive
dataset.shape
(150, 6)
dataset.describe()
GCETIT
Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm
# Let’s now take a look at the number of instances (rows) that belong to
each class. We can view this as an absolute count.
dataset.groupby('Species').size()
0
Species
Iris-setosa 50
Iris-versicolor 50
Iris-virginica 50
GCETIT
dtype: int64
plt.figure()
sns.pairplot(dataset.drop("Id", axis=1), hue = "Species", size=3,
markers=["o", "s", "D"]) plt.show()
GCETIT
/usr/local/lib/python3.11/dist-packages/seaborn/axisgrid.py:2100:
UserWarning: The `size` parameter has been renamed to `height`;
warnings.warn(msg, UserWarning)
<Figure size 640x480 with 0 Axes>
plt.figure()
dataset.drop("Id", axis=1).boxplot(by="Species", figsize=(15, 10))
plt.show()
GCETIT
Machine Learning 42302880501053
GCETIT
Machine Learning 42302880501053
GCETIT
Machine Learning 42302880501053
▾ KNeighborsClassifier i ?
KNeighborsClassifier(n_neighbors=50)
KNeighborsClassifier(n_neighbors=3)
GCETIT
Machine Learning 42302880501053
import numpy as np
import pandas as pd
# Importing the dataset
dataset = pd.read_csv("/content/drive/MyDrive/Iris.csv")
dataset.shape
dataset.describe()
GCETIT
Machine Learning 42302880501053
X = dataset[feature_columns].values
y = dataset['Species'].values
X = dataset.iloc[:, 1:5].values
y = dataset.iloc[:, 5].values
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
y = le.fit_transform(y)
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
plt.figure()
sns.pairplot(dataset.drop("Id", axis=1), hue = "Species",
size=3, markers=["o", "s", "D"])
plt.show()
plt.figure()
dataset.drop("Id", axis=1).boxplot(by="Species", figsize=(15,
10))
plt.show()
# Importing necessary libraries
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_iris
from sklearn.neighbors import KNeighborsClassifier
GCETIT
Machine Learning 42302880501053
GCETIT
Machine Learning 42302880501053
GCETIT