Code:: Performance Evaluation of Public Bus Service Quality Using Machine Learning
Code:: Performance Evaluation of Public Bus Service Quality Using Machine Learning
Sa ura v Barua
As s istant Professor, Department of Ci vil Engineering,
Da ffodil International University, Dhaka, Bangladesh
Code:
1. Import libraries
# Load libraries
import pandas
Page 1 of 10
Performance evaluation of public bus service quality using machine learning
Sa ura v Barua
As s istant Professor, Department of Ci vil Engineering,
Da ffodil International University, Dhaka, Bangladesh
2. Load Dataset
# Load dataset
names = ['Cleaness','frequency','Fare','behavior','Ventilation','Overall']
# shape
print(dataset.shape)
Output:
(50, 6)
# head
Page 2 of 10
Performance evaluation of public bus service quality using machine learning
Sa ura v Barua
As s istant Professor, Department of Ci vil Engineering,
Da ffodil International University, Dhaka, Bangladesh
print(dataset.head(20))
Output:
Cleaness frequency Fare behavior Ventilation Overall
0 1 2 1 1 1 1
1 1 1 1 1 1 1
2 1 2 1 2 2 1
3 2 2 1 3 2 1
4 1 1 2 2 1 1
5 3 3 2 3 2 2
6 4 2 1 2 2 2
7 3 3 2 3 3 2
8 2 1 2 1 2 2
9 1 1 2 2 3 2
10 2 2 3 3 2 3
11 4 2 3 3 2 3
12 2 3 2 3 2 3
13 2 3 3 2 3 3
14 1 4 2 4 2 4
15 2 3 4 4 3 4
16 3 3 4 3 3 4
17 3 3 2 4 2 4
18 2 1 2 2 4 4
19 5 3 4 3 2 5
# descriptions
print(dataset.describe()
output:
Cleaness frequency Fare behavior Ventilation Overall
count 50.000000 50.000000 50.000000 50.000000 50.000000 50.000000
mean 2.760000 2.440000 2.040000 2.640000 2.420000 2.760000
std 1.436549 0.704504 1.009344 0.875051 0.927802 1.519398
min 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
25% 2.000000 2.000000 1.000000 2.000000 2.000000 1.000000
50% 3.000000 3.000000 2.000000 3.000000 2.000000 2.000000
75% 4.000000 3.000000 3.000000 3.000000 3.000000 4.000000
max 5.000000 4.000000 5.000000 4.000000 4.000000 5.000000
# class distribution
Page 3 of 10
Performance evaluation of public bus service quality using machine learning
Sa ura v Barua
As s istant Professor, Department of Ci vil Engineering,
Da ffodil International University, Dhaka, Bangladesh
print(dataset.groupby('Overall').size())
output:
Overall
1 14
2 12
3 6
4 8
5 10
dtype: int64
4. Data Visualization
plt.show()
# histograms
Page 4 of 10
Performance evaluation of public bus service quality using machine learning
Sa ura v Barua
As s istant Professor, Department of Ci vil Engineering,
Da ffodil International University, Dhaka, Bangladesh
dataset.hist()
plt.show()
Output:
scatter_matrix(dataset)
plt.show()
Page 5 of 10
Performance evaluation of public bus service quality using machine learning
Sa ura v Barua
As s istant Professor, Department of Ci vil Engineering,
Da ffodil International University, Dhaka, Bangladesh
array = dataset.values
X = array[:,0:5]
Y = array[:,5]
validation_size = 0.20
seed = 7
seed = 7
scoring = 'accuracy'
Page 6 of 10
Performance evaluation of public bus service quality using machine learning
Sa ura v Barua
As s istant Professor, Department of Ci vil Engineering,
Da ffodil International University, Dhaka, Bangladesh
models = []
models.append(('LDA', LinearDiscriminantAnalysis()))
models.append(('KNN', KNeighborsClassifier()))
models.append(('CART', DecisionTreeClassifier()))
models.append(('NB', GaussianNB()))
models.append(('SVM', SVC(gamma='auto')))
results = []
names = []
results.append(cv_results)
names.append(name)
print(msg)
Page 7 of 10
Performance evaluation of public bus service quality using machine learning
Sa ura v Barua
As s istant Professor, Department of Ci vil Engineering,
Da ffodil International University, Dhaka, Bangladesh
output:
fig = plt.figure()
fig.suptitle('Algorithm Comparison')
ax = fig.add_subplot(111)
plt.boxplot(results)
ax.set_xticklabels(names)
plt.show()
output:
Page 8 of 10
Performance evaluation of public bus service quality using machine learning
Sa ura v Barua
As s istant Professor, Department of Ci vil Engineering,
Da ffodil International University, Dhaka, Bangladesh
knn = KNeighborsClassifier()
knn.fit(X_train, Y_train)
predictions = knn.predict(X_validation)
print(accuracy_score(Y_validation, predictions))
print(confusion_matrix(Y_validation, predictions))
print(classification_report(Y_validation, predictions))
output:
0.9
[[4 0 0 0 0]
[0 1 0 0 0]
[0 1 1 0 0]
Page 9 of 10
Performance evaluation of public bus service quality using machine learning
Sa ura v Barua
As s istant Professor, Department of Ci vil Engineering,
Da ffodil International University, Dhaka, Bangladesh
[0 0 0 1 0]
[0 0 0 0 2]]
precision recall f1-score support
Reference:
Brownlee, J., February 2019, “Your First Machine Learning Project in Python Step-By-Step”, Python
Machine Learning.
https://machinelearningmastery.com/machine-learning-in-python-step-by-step/
Page 10 of 10