感知机对偶形式(鸢尾花分类)
导入模块
from matplotlib.font_manager import FontProperties
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import random
%matplotlib inline
font = FontProperties(fname='/Library/Fonts/Heiti.ttc')
获取数据
def get_data():
df = pd.read_csv(
'http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data', header=None)
X = df.iloc[0:100, [0, 2]].values
train_data_p = df.iloc[0:50, [0, 2, 4]].values
train_data_n = df.iloc[50:100, [0, 2, 4]].values
train_data_p[:, [2]], train_data_n[:, [2]] = -1, 1
train_data = train_data_p.tolist() + train_data_n.tolist()
return train_data, X
训练模型