ROOT_DIR = os.path.abspath(os.path.dirname(__file__)) sys.path.append(ROOT_DIR + "/../Model") sys.path.append(ROOT_DIR + "/../../0_FeatureMaker") import numpy as np from feature_maker import FeatureMaker from nn import NeuralNetwork from regularizor import L2Regularization from learning_rate import MomentumLearningRate src = ROOT_DIR + '/../../Data/iris/iris_data.csv' feature_types = [1, 1, 1, 1, 0] feature_maker = FeatureMaker(src=src, delimiter=',', types=feature_types, norm=True) X, Y = feature_maker.make(skip_rows=1, skip_cols=1) # print("X : {}".format(X)) # print("Y : {}".format(Y)) train_X, test_X, train_Y, test_Y = feature_maker.train_test_split( X, Y, test_size=0.2, random_state=1234) # train_X, test_X, train_Y, test_Y = train_X[:5,:], test_X[:5,:], train_Y[:5,:], test_Y[:5,:] print("Train X : {}\n...".format(train_X[:5, :])) print("Train Y : {}\n...".format(train_Y[:5, :])) print("Test X : {}".format(test_X)) print("Test Y : {}".format(test_Y)) N_input = np.reshape(X[0], -1).shape[0] N_output = np.reshape(Y[0], -1).shape[0] topo = [N_input, 6, N_output] alpha = 1
# sys.path.append(ROOT_DIR+"/../Model") sys.path.append(ROOT_DIR+"/../../0_FeatureMaker") import numpy as np from feature_maker import FeatureMaker import json from sklearn.svm import LinearSVC from sklearn.metrics import hinge_loss src = ROOT_DIR+'/../../Data/iris/iris_data.csv' feature_types = [1,1,1,1,0] # src = ROOT_DIR+'/../../Data/iris/iris_data.csv' # feature_types = [1,1,1,1,0] feature_maker = FeatureMaker(src=src, delimiter=',', types=feature_types, norm=True) X, Y = feature_maker.make(skip_rows=1, skip_cols=1, one_hot=True) ### 将数据集做成二分类 X = X[Y[:,0]!=1,:] Y = Y[Y[:,0]!=1,:] # print(Y) Y = np.array([[1] if y[0]>1 else [-1] for y in Y]) # Y = Y.flatten() print("X.shape:{}\nY.shape:{}".format(X.shape, Y.shape)) Xtrain, Xtest, Ytrain, Ytest = feature_maker.train_test_split(X, Y, test_size=0.3) Xmarked, Xunmarked, Ymarked, Yunmarked = feature_maker.train_test_split(Xtrain, Ytrain, test_size=6.0/7) Ytest = Ytest.flatten() Ymarked = Ymarked.flatten() Yunmarked = Yunmarked.flatten() print("Xmarked.shape:{} Ymarked.shape:{}\nXunmarked.shape:{} Yunmarked.shape:{}\nXtest.shape:{} Ytest.shape:{}".format(Xmarked.shape, Ymarked, Xunmarked.shape, Yunmarked, Xtest.shape, Ytest))