Fall Semester 2020-21 AI With Python ECE-4031
Fall Semester 2020-21 AI With Python ECE-4031
AI with Python
ECE-4031
if '?' in line:
continue
X = X_encoded[:, :-
1].astype(int) y = X_encoded[:, -
1].astype(int) # Create SVM
classifier
#classifier = OneVsOneClassifier(LinearSVC(random_state=0))
# Train the
classifier
#classifier.fit(X,
y) plt.figure()
# Cross validation
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=5) w=[]
v=[]
#classifier svm classifier =
OneVsOneClassifier(LinearSVC(random_state=0)) f1 =
cross_val_score(classifier, X, y, scoring='f1_weighted', cv=3)
f1=round(100*f1.mean(), 2)
w.append(f1)
#logistic regression classifer
classifier=linear_model.LogisticRegression(solver="liblinear",C=100)
f1 = cross_val_score(classifier, X, y, scoring='f1_weighted', cv=3)
f1=round(100*f1.mean(), 2)
w.append(f1)
for i in range(4):
if i == 0: print(dash)
print('{:20s}{:>12s}'.format("Classifier name","F1 score"))
print(dash)
else:
print('{:<20s}{:>12.1f}'.format(v[i-1],w[i-1]))
index=np.arange(len(v))
plt.bar(index,w,color=['gainsboro','gainsboro','gainsboro'],edgecolor='blue')
plt.xlabel('Classifier')
plt.ylabel('F1 Score')
plt.xticks(index,v)
plt.show()