当前位置: 首页>>代码示例>>Python>>正文


Python DataModel.loadData方法代码示例

本文整理汇总了Python中DataModel.loadData方法的典型用法代码示例。如果您正苦于以下问题:Python DataModel.loadData方法的具体用法?Python DataModel.loadData怎么用?Python DataModel.loadData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataModel的用法示例。


在下文中一共展示了DataModel.loadData方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: compareImplementations2

# 需要导入模块: import DataModel [as 别名]
# 或者: from DataModel import loadData [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))
开发者ID:sn2234,项目名称:DigitRecognitionPython,代码行数:32,代码来源:DigitRecognitionPython.py

示例2: compareImplementations

# 需要导入模块: import DataModel [as 别名]
# 或者: from DataModel import loadData [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))
开发者ID:sn2234,项目名称:DigitRecognitionPython,代码行数:27,代码来源:DigitRecognitionPython.py

示例3: makeTestPerdictions

# 需要导入模块: import DataModel [as 别名]
# 或者: from DataModel import loadData [as 别名]
def makeTestPerdictions():
    x, _ = DataModel.loadData("..\\test.csv")
    s, th1, th2 = SimpleNN2.loadNetwork("..\\NeuralNetwork.bin")
    
    y = [SimpleNN2.predictClass(s, th1, th2, w) for w in x]
    
    with open("results.csv", "w") as f:
        imageId = 1
        f.write("ImageId,Label\n")
        for i in y:
            f.write("{0},{1}\n".format(imageId, i))
            imageId = imageId + 1
开发者ID:sn2234,项目名称:DigitRecognitionPython,代码行数:14,代码来源:DigitRecognitionPython.py

示例4: test1

# 需要导入模块: import DataModel [as 别名]
# 或者: from DataModel import loadData [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)
开发者ID:sn2234,项目名称:DigitRecognitionPython,代码行数:16,代码来源:DigitRecognitionPython.py

示例5: test2

# 需要导入模块: import DataModel [as 别名]
# 或者: from DataModel import loadData [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)
开发者ID:sn2234,项目名称:DigitRecognitionPython,代码行数:17,代码来源:DigitRecognitionPython.py

示例6: test3

# 需要导入模块: import DataModel [as 别名]
# 或者: from DataModel import loadData [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))
开发者ID:sn2234,项目名称:DigitRecognitionPython,代码行数:19,代码来源:DigitRecognitionPython.py

示例7: trainFullAndSave

# 需要导入模块: import DataModel [as 别名]
# 或者: from DataModel import loadData [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")
开发者ID:sn2234,项目名称:DigitRecognitionPython,代码行数:22,代码来源:DigitRecognitionPython.py


注:本文中的DataModel.loadData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。