<jupyter_start><jupyter_text>Support Vector Machineusing uci breast cancer dataset (again)way better than k nearest neigbors but algo is much more complex@TODO: learn linear algebra lolISO<jupyter_code>import numpy as np
from sklearn import preprocessing, svm
from sklearn.model_selection import train_test_split
import pandas as pd
import pickle<jupyter_output><empty_output><jupyter_text>%load breast-cancer-wisconsin.data.txt<jupyter_code>df = pd.read_csv('breast-cancer-wisconsin.data.txt')
# replace unkown data with outliers
df.replace('?',-99999, inplace=True)
# irrelevent feature
df.drop(['id'], 1, inplace=True)
# feature data
X = np.array(df.drop(['class'], 1))
# class / label data
y = np.array(df['class'])
# separate training and testing chunks
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
# define classifier
clf = svm.SVC()

# train classifier
clf.fit(X_train, y_train)
# test
accuracy = clf.score(X_test, y_test)
print('accuracy:', accuracy)
# about 96% accuracy without any tweaks
# If you want to save the classier you'd pickle it
example_measures = np.array([[4,2,1,1,1,2,3,2,1],[4,2,1,1,1,2,3,2,1], [1,0,6,1,5,1,2,4,2]])
example_measures = example_measures.reshape(len(example_measures), -1)
prediction = clf.predict(example_measures)
print('example class outputs: ', prediction)<jupyter_output>example class outputs:  [2 2 4]
{'fraction_non_alphanumeric': 0.12945454545454546, 'fraction_numerical': 0.030545454545454546, 'mean_word_length': 7.0, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '175127', 'license': 'Apache-2.0', 'n_tokens_mistral': 517, 'n_tokens_neox': 494, 'n_words': 124, 'path': '002-support-vector-machine/sklearn-support-vector-machine.ipynb', 'repo_name': 'MuhamedEssam/deeplearning', 'size': '1375'}