from random import sample from sklearn.datasets import load_iris ##导入鸢尾花数集 from sklearn.neural_network import MLPClassifier ## 导入神经网络包 yuanweihua = load_iris() #print(yuanweihua) chouyang1 = sample(range(0,50),40) chouyang1.extend(sample(range(50,100),40)) chouyang1.extend(sample(range(100,150),40)) ##抽样集训练样本编号 jianceji = [ i for i in chouyang1 if i not in chouyang1] tr_in = yuanweihua.data[chouyang1] tr_out = yuanweihua.target[chouyang1] te_in = yuanweihua.data[jianceji] te_out = yuanweihua.target[jianceji] modle = MLPClassifier(hidden_layer_sizes = 10 , max_iter = 10000).fit(tr_in,tr_out) res = modle.predict(te_in) #print(res) #print(te_out) #print(sum(res == te_out) / len(res))