<jupyter_start><jupyter_text>Gender Classification<jupyter_code>from sklearn import tree
clf = tree.DecisionTreeClassifier()

# CHALLENGE - create 3 more classifiers...
# 1
# 2
# 3

# [height, weight, shoe_size]
X = [[181, 80, 44], [177, 70, 43], [160, 60, 38], [154, 54, 37], [166, 65, 40],
     [190, 90, 47], [175, 64, 39],
     [177, 70, 40], [159, 55, 37], [171, 75, 42], [181, 85, 43]]

Y = ['male', 'male', 'female', 'female', 'male', 'male', 'female', 'female',
     'female', 'male', 'male']


# CHALLENGE - ...and train them on our data
clf = clf.fit(X, Y)
prediction = clf.predict([[190, 70, 43]])

# CHALLENGE compare their reusults and print the best one!

print(prediction)<jupyter_output>['male']<jupyter_text>https://www.youtube.com/watch?v=T5pRlIbr6gg&list=PL2-dafEMk2A6QKz1mrk1uIGfHkC1zZ6UU&index=1<jupyter_code>from sklearn import tree
from sklearn.svm import SVC
from sklearn.linear_model import Perceptron
from sklearn.neighbors import KNeighborsClassifier
from sklearn.naive_bayes import GaussianNB

from sklearn.metrics import accuracy_score
# Data and labels
X = [[181, 80, 44], [177, 70, 43], [160, 60, 38], [154, 54, 37], [166, 65, 40], [190, 90, 47], [175, 64, 39],
     [177, 70, 40], [159, 55, 37], [171, 75, 42], [181, 85, 43]]

Y = ['male', 'male', 'female', 'female', 'male', 'male', 'female', 'female', 'female', 'male', 'male']
# Classifiers
# using the default values for all the hyperparameters
clf_tree = tree.DecisionTreeClassifier()
clf_svm = SVC()
clf_perceptron = Perceptron()
clf_KNN = KNeighborsClassifier()
clf_gauss = GaussianNB()
# Training the models
clf = clf_tree.fit(X, Y)
clf_svm = clf_svm.fit(X, Y)
clf_perceptron = clf_perceptron.fit(X, Y)
clf_KNN = clf_KNN.fit(X, Y)
clf_gauss = clf_gauss.fit(X,Y)

# Testing using the same data
pred_tree = clf_tree.predict(X)
acc_tree = accuracy_score(Y, pred_tree)
print('Accuracy for DecisionTree: {}'.format(acc_tree))

pred_svm = clf_svm.predict(X)
acc_svm = accuracy_score(Y, pred_svm)
print('Accuracy for SVM: {}'.format(acc_svm))

pred_per = clf_perceptron.predict(X)
acc_per = accuracy_score(Y, pred_per)
print('Accuracy for perceptron: {}'.format(acc_per))

pred_KNN = clf_KNN.predict(X)
acc_KNN = accuracy_score(Y, pred_KNN)
print('Accuracy for KNN: {}'.format(acc_KNN))

pred_gauss = clf_gauss.predict(X)
acc_gauss = accuracy_score(Y, pred_gauss)
print('Accuracy for gauss: {}'.format(acc_gauss))

# The best classifier from svm, per, KNN
print('For same dataset')
index = np.argmax([acc_svm, acc_per, acc_KNN, acc_gauss])
classifiers = {0: 'SVM', 1: 'Perceptron', 2: 'KNN', 3: 'GaussianNB'}
print('Best gender classifier is {}'.format(classifiers[index]))

print()

_X=[[184,84,44],[198,92,48],[183,83,44],[166,47,36],[170,60,38],[172,64,39],[182,80,42],[180,80,43]]
_Y=['male','male','male','female','female','female','male','male']

pred_tree = clf_tree.predict(_X)
acc_tree = accuracy_score(_Y, pred_tree)
print('Accuracy for DecisionTree: {}'.format(acc_tree))

pred_svm = clf_svm.predict(_X)
acc_svm = accuracy_score(_Y, pred_svm)
print('Accuracy for SVM: {}'.format(acc_svm))

pred_per = clf_perceptron.predict(_X)
acc_per = accuracy_score(_Y, pred_per)
print('Accuracy for perceptron: {}'.format(acc_per))

pred_KNN = clf_KNN.predict(_X)
acc_KNN = accuracy_score(_Y, pred_KNN)
print('Accuracy for KNN: {}'.format(acc_KNN))

pred_gauss = clf_gauss.predict(_X)
acc_gauss = accuracy_score(_Y, pred_gauss)
print('Accuracy for gauss: {}'.format(acc_gauss))

# The best classifier from svm, per, KNN
print('For different dataset')
index = np.argmax([acc_svm, acc_per, acc_KNN, acc_gauss])
classifiers = {0: 'SVM', 1: 'Perceptron', 2: 'KNN', 3: 'GaussianNB'}
print('Best gender classifier is {}'.format(classifiers[index]))<jupyter_output>Accuracy for DecisionTree: 1.0
Accuracy for SVM: 1.0
Accuracy for perceptron: 0.5454545454545454
Accuracy for KNN: 0.7272727272727273
Accuracy for gauss: 0.8181818181818182
For same dataset
Best gender classifier is SVM

Accuracy for DecisionTree: 1.0
Accuracy for SVM: 0.625
Accuracy for perceptron: 0.625
Accuracy for KNN: 0.875
Accuracy for gauss: 1.0
For different dataset
Best gender classifier is GaussianNB
{'fraction_non_alphanumeric': 0.16060679027209246, 'fraction_numerical': 0.0746448350589935, 'mean_word_length': 6.287719298245614, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '588187', 'license': 'MIT', 'n_tokens_mistral': 1967, 'n_tokens_neox': 1639, 'n_words': 407, 'path': 'Gender Classification.ipynb', 'repo_name': 'deepaksood619/DS_ML', 'size': '4153'}