import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.io import loadmat
from sklearn.model_selection import train_test_split
import keras
from keras.models import Sequential
from keras.layers import Dense
# 导入数据
path ='../Data/iris.data'
data = pd.read_csv(path, names=['Sepal.Length','Sepal.Width','Petal.Length','Petal.Width','Species'])
data.head(10)
# 变量初始化# 最后一列为y,其余为x
cols = Data.shape[1]#列数 shape[0]行数 [1]列数
X = Data.iloc[:,0:cols-1]#取前cols-1列,即输入向量
y = Data.iloc[:,cols-1:cols]#取最后一列,即目标变量
X = np.array(X)
y = np.array(y)
y = y.flatten()# 对y进行降维
defrealdata(y,k):
real = np.zeros(shape=(k,len(y)))for i inrange(0,k):
y_i = np.array([1if label == i else0for label in y])
real[i]= y_i
return real.T
y = realdata(y,3)
y