MINI PROJECT - Merged
MINI PROJECT - Merged
import numpy as np
import pandas as pd
data = {
'sepal_length': [5.1, 4.9, 4.7, 4.6, 5.0, ...], # List of sepal lengths
'sepal_width': [3.5, 3.0, 3.2, 3.1, 3.6, ...], # List of sepal widths
'petal_length': [1.4, 1.4, 1.3, 1.5, 1.4, ...], # List of petal lengths
'petal_width': [0.2, 0.2, 0.2, 0.2, 0.2, ...], # List of petal widths
iris_data = pd.DataFrame(data)
#STEP 3 : Display the first 5 rows of the dataset
print(iris_data.head())
#STEP 4 : Split the dataset into features (X) and target (y)
X = iris_data.drop('species', axis=1)
y = iris_data['species']
knn = KNeighborsClassifier(n_neighbors=3)
knn.fit(X_train, y_train)
y_pred = knn.predict(X_test)
print("Accuracy:", accuracy)
print("Classification Report:")
print(classification_report(y_test, y_pred))
print("Confusion Matrix:")
print(confusion_matrix(y_test, y_pred))
OUTPUT :
Accuracy: 0.9666666666666667
Classification Report:
accuracy 0.97 32
Confusion Matrix:
[[10 0 0]
[ 0 12 1]
[0 0 9]]
The output includes the first 150 rows of the Iris dataset, the accuracy, classification report, and
confusion matrix
Accuracy: 0.9666666666666667
Classification Report:
accuracy 0.97 32
Confusion Matrix:
[[10 0 0]
[ 0 12 1]
[0 0 9]]
***THE END***