Last active
June 22, 2020 13:42
-
-
Save jamiebullock/7f90de0eded28f599994bf6f08e387d1 to your computer and use it in GitHub Desktop.
Simple Fruit Classifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from sklearn.model_selection import train_test_split | |
data = pd.read_csv('fruit_data.csv') | |
types = pd.read_csv('fruit_types.csv', index_col=0) | |
y = data['Label'] | |
X = data[['Mass', 'Width', 'Height']] | |
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0) | |
from sklearn.preprocessing import MinMaxScaler | |
scaler = MinMaxScaler() | |
X_train = scaler.fit_transform(X_train) | |
X_test = scaler.transform(X_test) | |
from sklearn.neighbors import KNeighborsClassifier | |
knn = KNeighborsClassifier() | |
knn.fit(X_train, y_train) | |
print("%d%% accuracy" % (knn.score(X_test, y_test) * 100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment