Glass classification done

master
Orion Stark 6 years ago
parent 4536ebc6cf
commit bb6f6deaa4
  1. 38
      glass-classification/index.py

@ -24,7 +24,6 @@ import pandas
import numpy
from pandas.plotting import scatter_matrix
import matplotlib.pyplot as plt
import sys
from sklearn import model_selection
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
@ -35,16 +34,45 @@ from sklearn.neighbors import KNeighborsClassifier
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC
sys.path.append('..')
from utils.models_evaluation import ModelsEvaluation
from utils.model import Model
def getGlassesClassText(number):
return {
1.0 : 'Building windows float processed',
2.0 : 'Building windows non-float processed',
3.0 : 'Vehicle windows float processed',
4.0 : 'Vehicle windows non-float processed',
5.0 : 'Containers',
6.0 : 'Tableware',
7.0 : 'Headlamps'
}.get(number, None)
# Load the dataset
path = "../datasets/Glass Dataset/glass.data"
names = ['id', 'RI', 'Na', 'Mg', 'Al', 'Si', 'K', 'Ca', 'Ba', 'Fe', 'class']
dataset = pandas.read_csv(path, names = names)
array = dataset.values
X = array[:, 1:9]
X = array[:, 1:10]
Y = array[:, 10]
print(X)
print(Y)
# validation_size = 0.20
# seed = 7
# X_train, X_validation, Y_train, Y_validation = model_selection.train_test_split(X, Y, test_size = validation_size, random_state = seed)
MODEL_EVALUATION = ModelsEvaluation(X, Y)
HIGHEST_ACC_MODEL_NAME = MODEL_EVALUATION.evaluateAccuracy().name
HIGHEST_ACC_MODEL_SCORE = MODEL_EVALUATION.evaluateAccuracy().mean
HIGHEST_MODEL = Model.getAlgorithmModel(HIGHEST_ACC_MODEL_NAME)
HIGHEST_MODEL.fit(X, Y)
predict_data = [
[ 1.51755, 13.00, 3.60, 1.36, 72.99, 0.57, 8.40, 0.00, 0.11 ],
[ 1.51574, 14.86, 3.67, 1.74, 71.87, 0.16, 7.36, 0.00, 0.12 ],
[ 1.51593, 13.09, 3.59, 1.52, 73.10, 0.67, 7.83, 0.00, 0.00 ]
]
if ( HIGHEST_MODEL is not None ):
prediction = HIGHEST_MODEL.predict(predict_data)
print("Matching algorithm is " + HIGHEST_ACC_MODEL_NAME)
for i in range(0, len(prediction)):
print(getGlassesClassText(prediction[i]))
else:
print("Didn't get matching algorithm")

Loading…
Cancel
Save