Glass classification using KNN algorithm
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn import metrics
from sklearn.preprocessing import MinMaxScaler
glass = pd.read_csv('datasets/glass.csv')
glass.head()
glass.shape
X = glass.iloc[:, 0:9]
X.head()
y = glass.iloc[:,9]
y.head()
X.describe()
y.describe()
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1)
X_train.shape
X_test.shape
knn = KNeighborsClassifier(n_neighbors = 5)
knn.fit(X_train, y_train)
y_pred = knn.predict(X_test)
accuracy = metrics.accuracy_score(y_test, y_pred)
accuracy