第三节:感知机对偶形式(鸢尾花分类)

感知机对偶形式(鸢尾花分类)

导入模块

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

训练模型

联系管理员微信tutu19192010,注册账号

上一篇
下一篇
Copyright © 2022 Egon的技术星球 egonlin.com 版权所有 青浦区尚茂路798弄 联系方式-13697081366