更改神经网络的输入和输出

时间:2019-06-19 21:06:49

标签: python-3.x numpy neural-network deep-learning artificial-intelligence

目前,我正在使用DL神经网络处理数字数据。我为此使用Keras库,CSV包含912k,如下所示:

    p   u   d    ms          action B   x    y-c pre    area       finger 
0   0   36  3   1334893336790   0   1   262 262 262     0.044444    0.0
1   0   36  3   1334893336790   2   1   262 271 0.32    0.044444    0.0
2   0   36  3   1334893336795   2   1   123 327 0.28    0.044444    0.0
3   0   36  3   1334893336800   1   1   123 327 0.28    0.044444    0.0
4   0   36  3   1334893336885   0   1   216 298 0.34    0.044444    0.0
5   0   36  3   1334893336907   2   1   216 298 0.38    0.044444    0.0
6   0   36  3   1334893336926   2   1   147 312 0.60    0.088889    0.0
7   0   36  3   1334893336949   2   1   115 328 0.63    0.044444    0.0
8   0   36  3   1334893336952   2   1   98  336 0.17    0.133333    0.0
9   0   36  3   1334893336971   1   1   98  336 0.17    0.133333    0.0
1   0   36  3   1334893337798   0   1   108 339 0.48    0.044444    0.0

据我所知,神经网络输入是逐行输入的,这里我试图基于 action列进行输入和输出,就像它以 0 开头时,以 1 结尾 然后包括从行[0到3] 3到神经网络的第一个输入,并且包括[4到9] 9的第二个输入,依此类推...,我已经尝试了很多次,但是对我来说不起作用

#o = no_of_click
o=0
lenf=len(dataset)
for h in dataset.index[dataset.iloc[:, 4] == 0]:
    if dataset.iloc[h+1,4]==1 :
        dataset.iloc[h+1,4]=-1
        dataset.iloc[h , 4] = -1
        o=o+1
dataset=dataset.drop(dataset[dataset.iloc[:, 4] == -1].index)
lenf=(o*2)
X = dataset.iloc[:, 2:].values #here 3to 11 for x
y = dataset.iloc[:, 1].values #here user id 2 only y

binariz = LabelBinarizer()
s = binariz.fit_transform(X[:, 0])
X = np.delete(X, [0], axis=1)
X = np.hstack([s,X])
y = binariz.fit_transform(y)
# X Features scaling
sc_X = StandardScaler()
X = sc_X.fit_transform(X)

# Splitting Data
X_train, X_test,y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)

classifier = Sequential()
# Adding the input layer and the first hidden layer
classifier.add(Dense(units = 50, activation = 'relu', input_dim = X_train.shape[1]))
# Adding the second hidden layer

classifier.add(Dense(units = 50, activation = 'relu'))
# Adding the output layer
classifier.add(Dense(units = y.shape[1], activation = 'softmax'))
# Compiling the ANN
classifier.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])
# Fitting the ANN to the Training set
classifier.fit(X_train, y_train, batch_size = 100, epochs = 10)

0 个答案:

没有答案