from sklearn import svm
import matplotlib.pyplot as plt
import numpy as np
from sklearn.datasets import load_iris
import numpy as np
import random
import numpy.random as rand
rand.seed(10)
# 读取鸢尾花数据集,并存储在变量iris中。
iris_data = load_iris()
""" 可视化 """
num_samples, num_features = iris_data['data'].shape
num_classes = 2
# 特征名称
feature_names = ['sepal length',
'sepal width', 'petal length', 'petal width']
# # features times features
# fig, ax = plt.subplots(num_features, num_features, figsize=(16, 16))
markers = '+o^'
# print(iris_data['data'][50:150])
# print(iris_data['target'][50:150])
feature_idx_1 = 2
feature_idx_2 = 3
type_1 = 0
nn = rand.permutation(100)
nn = [i + 50*type_1 for i in nn]
# print(nn)
""" 生成随机排列 """
train_idx = nn[0:90]
test_idx = nn[90:100]
print(train_idx)
print(test_idx)
""" 注意,这是Numpy Matrix的索引
print(type(iris_data['data']))
<class 'numpy.ndarray'>
iris_data['data']如下
[[5.1 3.5 1.4 0.2]
[4.9 3. 1.4 0.2]
[4.7 3.2 1.3 0.2]
[4.6 3.1 1.5 0.2]
[5. 3.6 1.4 0.2]
[5.4 3.9 1.7 0.4]
[4.6 3.4 1.4 0.3]
"""
""" 注意这里高维切片技巧的使用 ""
Python sklearn SVM 超平面可视化
最新推荐文章于 2024-06-11 02:26:51 发布