<jupyter_start><jupyter_text>Support Vector Machinecategorize data  By using Kernel tric, data can be categorized in higher dimentional space.  reference: http://momijiame.tumblr.com/post/114751531866/python-iris-%E3%83%87%E3%83%BC%E3%82%BF%E3%82%BB%E3%83%83%E3%83%88%E3%82%92%E3%82%B5%E3%83%9D%E3%83%BC%E3%83%88%E3%83%99%E3%82%AF%E3%82%BF%E3%83%BC%E3%83%9E%E3%82%B7%E3%83%B3%E3%81%A7%E5%88%86%E9%A1%9E%E3%81%97%E3%81%A6%E3%81%BF%E3%82%8B<jupyter_code>import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from sklearn import datasets, svm
# datasets
iris = datasets.load_iris()
data = iris.data
target = iris.target
target_names = iris.target_names
labels = target_names[target]
setosa_pl = data[labels == 'setosa', 2]
setosa_pw = data[labels == 'setosa', 3]
setosa_p = np.c_[setosa_pl, setosa_pw]
versicolor_pl = data[labels == 'versicolor', 2]
versicolor_pw = data[labels == 'versicolor', 3]
versicolor_p = np.c_[versicolor_pl, versicolor_pw]
# visualize data
plt.scatter(setosa_p[:, 0], setosa_p[:, 1], color='red')
plt.scatter(versicolor_p[:, 0], versicolor_p[:, 1], color='blue')
# training data
x_train = np.r_[setosa_p, versicolor_p]
y_train = np.r_[np.zeros(len(setosa_p)), np.ones(len(versicolor_p))]
# define model
lsvc = svm.LinearSVC()
lsvc.fit(x_train, y_train)
# visualize
xx, yy = np.meshgrid(
    np.arange(x_train[:, 0].min()-1, x_train[:, 0].max()+1, 0.02),
    np.arange(x_train[:, 1].min()-1, x_train[:, 1].max()+1, 0.02),
)
z = lsvc.predict(np.c_[xx.ravel(), yy.ravel()]).reshape(xx.shape)
plt.contourf(xx, yy, z, cmap=plt.cm.bone, alpha=0.2)
plt.autoscale()
plt.grid()
plt.scatter(setosa_p[:, 0], setosa_p[:, 1], color='red')
plt.scatter(versicolor_p[:, 0], versicolor_p[:, 1], color='blue')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19189645469893077, 'fraction_numerical': 0.07822172200337647, 'mean_word_length': 7.231481481481482, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '291560', 'license': 'MIT', 'n_tokens_mistral': 883, 'n_tokens_neox': 808, 'n_words': 130, 'path': 'category/svm/iris_01.ipynb', 'repo_name': 'fumiphys/data-science', 'size': '1777'}