How to classify iris flowers using neural network methods
First of all, there must be data.
Iris provides 150 sets of data. Each set includes four input features: calyx length, calyx width, petal length, and petal width. At the same time, the iris flower category corresponding to this set of input features is given, including three types: 0 Setaria iris, 1 Weed iris, 2 Virginia iris
Install two packages, scikit-learn and pandas
pip install scikit-learn
pip install pandas
code show as below:
from sklearn import datasets
from pandas import DataFrame
import pandas as pd
x_data = datasets.load_iris().data # .data返回iris数据集所有输入特征
y_data = datasets.load_iris().target # .target返回iris数据集所有标签
print("x_data from datasets: \n", x_data)
print("y_data from datasets: \n", y_data)
x_data = DataFrame(x_data, columns=['花萼长度', '花萼宽度', '花瓣长度', '花瓣宽度']) # 为表格增加行索引(左侧)和列标签(上方)
pd.set_option('display.unicode.east_asian_width', True) # 设置列名对齐
print("x_data add index: \n", x_data)
x_data['类别'] = y_data # 新加一列,列标签为‘类别’,数据为y_data
print("x_data add a column: \n", x_data)
#类型维度不确定时,建议用print函数打印出来确认效果
Data Display: