本文整理汇总了Python中DataModel.splitData方法的典型用法代码示例。如果您正苦于以下问题:Python DataModel.splitData方法的具体用法?Python DataModel.splitData怎么用?Python DataModel.splitData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataModel
的用法示例。
在下文中一共展示了DataModel.splitData方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compareImplementations
# 需要导入模块: import DataModel [as 别名]
# 或者: from DataModel import splitData [as 别名]
def compareImplementations():
(x, y) = DataModel.loadData("..\\train.csv")
y = y.astype(int)
(x_train, x_cv, y_train, y_cv) = DataModel.splitData(x, y)
x_sub = x_train[:500,:]
y_sub = y_train[:500]
s_my = SimpleNN.SimpleNN([784, 70, 10])
s_t = NN_1HL.NN_1HL(reg_lambda = 1, opti_method = 'CG')
np.random.seed(123)
thetas = [s_t.rand_init(784,70), s_t.rand_init(70, 10)]
cost_t = s_t.function(s_t.pack_thetas(thetas[0].copy(), thetas[1].copy()), 784, 70, 10, x_sub, y_sub, 10)
grad_t = s_t.function_prime(s_t.pack_thetas(thetas[0], thetas[1]), 784, 70, 10, x_sub, y_sub, 10)
print(cost_t, np.sum(grad_t));
cost_my = s_my.computeCost(s_my.combineTheta(thetas.copy()), x_sub, y_sub, 10)
grad_my = s_my.computeGrad(s_my.combineTheta(thetas), x_sub, y_sub, 10)
print(cost_my, np.sum(grad_my))
示例2: compareImplementations2
# 需要导入模块: import DataModel [as 别名]
# 或者: from DataModel import splitData [as 别名]
def compareImplementations2():
(x, y) = DataModel.loadData("..\\train.csv")
y = y.astype(int)
(x_train, x_cv, y_train, y_cv) = DataModel.splitData(x, y)
x_sub = x_train[:500,:]
y_sub = y_train[:500]
s_my = SimpleNN2.NeuralNetConfig(784, 70, 10)
s_t = NN_1HL.NN_1HL(reg_lambda = 10, opti_method = 'CG')
np.random.seed(123)
thetas = [s_t.rand_init(784,70), s_t.rand_init(70, 10)]
# Check costs
cost_t = s_t.function(s_t.pack_thetas(thetas[0].copy(), thetas[1].copy()), 784, 70, 10, x_sub, y_sub, 10)
print("Cost test: ", cost_t)
cost_my = SimpleNN2.computeCost(s_my, thetas[0], thetas[1], x_sub, y_sub, 10)
print("Cost my: ", cost_my)
# Check gradients
grad_t = s_t.function_prime(s_t.pack_thetas(thetas[0].copy(), thetas[1].copy()), 784, 70, 10, x_sub, y_sub, 10)
print("Grad sum test: ", np.sum(grad_t))
grad_my1, grad_my2 = SimpleNN2.computeGrad(s_my, thetas[0], thetas[1], x_sub, y_sub, 10)
print("Grad sum my: ", np.sum(grad_my1) + np.sum(grad_my2))
示例3: test1
# 需要导入模块: import DataModel [as 别名]
# 或者: from DataModel import splitData [as 别名]
def test1():
(x, y) = DataModel.loadData("..\\train.csv")
(x_train, x_cv, y_train, y_cv) = DataModel.splitData(x, y)
x_sub = x_train[:500,:]
y_sub = y_train[:500]
s = SimpleNN.SimpleNN([784, 70, 10])
#s = Train.trainGradientDescent(s, x_sub, y_sub, 5)
s = Train.trainSciPy(s, x_sub, y_sub, 5)
acc_cv = accuracy_score(y_cv, [s.predictClass(w) for w in x_cv])
print("Accuracy on CV set: {0}", acc_cv)
示例4: test2
# 需要导入模块: import DataModel [as 别名]
# 或者: from DataModel import splitData [as 别名]
def test2():
(x, y) = DataModel.loadData("..\\train.csv")
y = y.astype(int)
(x_train, x_cv, y_train, y_cv) = DataModel.splitData(x, y)
x_sub = x_train[:500,:]
y_sub = y_train[:500]
s = NN_1HL.NN_1HL(reg_lambda = 1, opti_method = 'CG')
s.fit(x_sub, y_sub)
acc_cv = accuracy_score(y_cv, [s.predict(w) for w in x_cv])
print("Accuracy on CV set: {0}", acc_cv)
示例5: test3
# 需要导入模块: import DataModel [as 别名]
# 或者: from DataModel import splitData [as 别名]
def test3():
(x, y) = DataModel.loadData("..\\train.csv")
(x_train, x_cv, y_train, y_cv) = DataModel.splitData(x, y)
x_sub = x_train[:20000,:]
y_sub = y_train[:20000]
s = SimpleNN2.NeuralNetConfig(784, 70, 10)
regLambda = 6.84
#s = Train.trainGradientDescent(s, x_sub, y_sub, 5)
th1, th2 = Train.trainSciPy2(s, x_sub, y_sub, regLambda)
#th1, th2 = Train.trainGradientDescent2(s, x_sub, y_sub, 5)
acc_cv = accuracy_score(y_cv, [SimpleNN2.predictClass(s, th1, th2, w) for w in x_cv])
print("Accuracy on CV set: {0}".format(acc_cv))
示例6: trainFullAndSave
# 需要导入模块: import DataModel [as 别名]
# 或者: from DataModel import splitData [as 别名]
def trainFullAndSave():
(x, y) = DataModel.loadData("..\\train.csv")
(x_train, x_cv, y_train, y_cv) = DataModel.splitData(x, y)
s = SimpleNN2.NeuralNetConfig(784, 70, 10)
regLambda = 6.84
print("Training neural network on full dataset")
#s = Train.trainGradientDescent(s, x_sub, y_sub, 5)
th1, th2 = Train.trainSciPy2(s, x_train, y_train, regLambda)
#th1, th2 = Train.trainGradientDescent2(s, x_sub, y_sub, 5)
print("Training complete, checking accuracy on CV data")
acc_cv = accuracy_score(y_cv, [SimpleNN2.predictClass(s, th1, th2, w) for w in x_cv])
print("Accuracy on CV set: {0}".format(acc_cv))
SimpleNN2.saveNetwork(s, th1, th2, "..\\NeuralNetwork.bin")