跳转至

案例-鸢尾花种类预测


1. 数据集介绍

Iris 数据集是常用的分类实验数据集,由Fisher, 1936收集整理。Iris也称鸢尾花卉数据集,是一类多重变量分析的数据集。关于数据集的具体介绍:

2. 案例实现

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC


if __name__ == '__main__':

    # 加载数据集
    x, y = load_iris(return_X_y=True)

    # 数据集分割
    x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, stratify=y)

    # 特征值标准化
    transformer = StandardScaler()
    x_train = transformer.fit_transform(x_train)
    x_test = transformer.transform(x_test)

    # 模型训练
    estimator = SVC()
    estimator.fit(x_train, y_train)

    # 模型预测
    print(estimator.score(x_test, y_test))