<jupyter_start><jupyter_text>Lesson 04 - Choose your own algorithm![](algorithm.png)<jupyter_code>from prep_terrain_data import makeTerrainData

features_train, labels_train, features_test, labels_test = makeTerrainData()
from sklearn.neighbors import KNeighborsClassifier

clf = KNeighborsClassifier(n_neighbors=4)
clf.fit(features_train, labels_train) 

show_picture()
show_accuracy()
from sklearn.cross_validation import cross_val_score
from sklearn.ensemble import AdaBoostClassifier

all_scores = []
for i in xrange(1, 200):
    clf = AdaBoostClassifier(n_estimators=i)
    scores = cross_val_score(clf, features_train, labels_train)
    all_scores.append(scores.mean())<jupyter_output><empty_output><jupyter_text>Let's plot the accuracy for the various number of estimators<jupyter_code>%matplotlib inline

import matplotlib.pyplot as plt

y = all_scores

plt.plot(range(1, len(y) + 1), y)
plt.show()
clf = AdaBoostClassifier(n_estimators=all_scores.index(max(all_scores)) + 1)
cross_val_score(clf, features_train, labels_train).mean()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09523809523809523, 'fraction_numerical': 0.009337068160597572, 'mean_word_length': 8.241379310344827, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '45574', 'license': 'MIT', 'n_tokens_mistral': 408, 'n_tokens_neox': 378, 'n_words': 72, 'path': 'udacity_data_science_notes/intro_machine_learning/lesson_04/lesson_04.ipynb', 'repo_name': 'anshbansal/anshbansal.github.io', 'size': '1071'}