<jupyter_start><jupyter_text>Load Iris data<jupyter_code># import the iris data
iris = datasets.load_iris()

# let's just use two features, so that we can 
# easily visualize them
X = iris.data[:, [0, 2]]
y = iris.target
target_names = iris.target_names
feature_names = iris.feature_names
# get the classes
n_class = len(set(y))
print('We have %d classes in the data'%(n_class))
# let's have a look of the data first
plt.figure(figsize = (10,8))
for i, c, s in (zip(range(n_class), ['b', 'g', 'r'], ['o', '^', '*'])):
    ix = y == i
    plt.scatter(X[:, 0][ix], X[:, 1][ix], color = c, marker = s, s = 60, label = target_names[i])

plt.legend(loc = 2, scatterpoints = 1)
plt.xlabel('Feature 1 - ' + feature_names[0])
plt.ylabel('Feature 2 - ' + feature_names[2])
plt.show()<jupyter_output><empty_output><jupyter_text>Concept of Support Vector Machine (SVM)SVM is a very popular algorithm in machine learning. It is an algorithm based on the intuition. If we have the following two lines to separate the orange squares and blue dots, which one do you think is better?    If you want to know more about SVM, check it on [Qingkai's blog](http://qingkaikong.blogspot.com/2016/12/machine-learning-7-support-vector.html)  Train a SVM<jupyter_code># Initialize SVM classifier
clf = svm.SVC(kernel='linear')

# Train the classifier with data
clf.fit(X,y)<jupyter_output><empty_output><jupyter_text>The training results<jupyter_code>clf.predict(X)<jupyter_output><empty_output><jupyter_text>Let's view the performance on the training data, we will plot the confusion matrix. Also, we will plot the decision boundary, which will help us understand more of the capability of the classifier (since we only have two selected features, this makes us eaiser to view the decision boundary).<jupyter_code># predict results from the test data
predicted = clf.predict(X)

# plot the confusion matrix
cm = confusion_matrix(y,predicted)
plot_confusion_matrix(cm, classes=iris.target_names,
                      title='Confusion matrix, without normalization')
plot_desicion_boundary(X, y, clf)<jupyter_output><empty_output><jupyter_text>ExerciseLet's do the classification using an Artificial Neural Network (ANN). It is another popular algorithm in machine learning, the structure of a standard ANN is: We don't have time to go over the basics of ANN, but you can find more information about it on [Qingkai's blog](http://qingkaikong.blogspot.com/2016/11/machine-learning-3-artificial-neural.html).<jupyter_code>from sklearn.neural_network import MLPClassifier
# Initialize ANN classifier

# create an ANN with two hidden layers, each with 10 neurons
hidden_layer_sizes = 

# using a logistic activation function
activation = 

mlp = MLPClassifier(hidden_layer_sizes= hidden_layer_sizes, activation=activation, \
                    max_iter = 2000, random_state=13)
# Train the classifier with the traning data

# predict results from the test data
predicted = 
# plot the confusion matrix
cm = confusion_matrix(y,predicted)
plot_confusion_matrix(cm, classes=iris.target_names,
                      title='Confusion matrix, without normalization')<jupyter_output><empty_output><jupyter_text>Solution<jupyter_code>%load ../solutions/solution_02.py<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.100920245398773, 'fraction_numerical': 0.01196319018404908, 'mean_word_length': 5.211428571428572, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '314875', 'license': 'CC-BY-3.0', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1010, 'n_words': 336, 'path': 'code_examples/python_regression_classification/notebooks/02_classification.ipynb', 'repo_name': 'matthew-brett/UoB', 'size': '3260'}