print(type(Ytrain))

print(type(X[0]))
print(type(X[0][0]))
print(type(Ytrain[0]))

assert (len(X) == len(Ytrain))
nnet.fit(X, Ytrain)

from sklearn.model_selection import cross_val_predict

# ytrain_pred = cross_val_predict(nnet, X, Ytrain,cv=5)

print("Training done")

Ytrain_pred = nnet.predict(X)
correct = 0
for i in range(len(X)):
    if (Ytrain_pred[i] == Ytrain[i]):
        correct += 1

print(Ytrain_pred)
print("Training Accuracy={}%".format(correct / len(X) * 100))

tX = np.load("./test/test.npy")
testX = []
for a in tX:
    # c = []
    # for b in a:
    # 	c.append(np.float32(b))
    c = np.array(list(a))
示例#2
0
        x = F.dropout(x, training=self.training)
        x = self.fc2(x)
        x = F.softmax(x, dim=-1)
        return x
    
cnn = NeuralNetClassifier(
    Cnn,
    max_epochs=8,
    lr=1,
    optimizer=torch.optim.Adadelta,
    # device='cuda',  # uncomment this to train with CUDA
)
#train the module
cnn.fit(XCnn_train, y_train);
#Use validation set to see the accuracy
cnn_pred = cnn.predict(XCnn_test)
print(np.mean(cnn_pred == y_test))
#predict the test set
cnn_pred_test = cnn.predict(test)


# In[80]:

#write to .csv file
ID = np.arange(1,20001)
ID = ID.tolist()
data = zip(ID,cnn_pred_test)
with open('CNN_v6.csv', 'w',newline='') as outfile:
    mywriter = csv.writer(outfile)
    # manually add header