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


Python Features.getMatrix方法代码示例

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


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

示例1: main

# 需要导入模块: import Features [as 别名]
# 或者: from Features import getMatrix [as 别名]
def main():
    arguments = validateInput(sys.argv)
    maxIterations, regularization, stepSize, lmbd, featureSet = arguments
    print maxIterations, regularization, stepSize, lmbd, featureSet

    trainData = readFile('train.csv')
    validationData = readFile('validation.csv')
    testData = readFile('test.csv')

    trainSize = trainData.shape[0]
    validationSize = validationData.shape[0]
    testSize = testData.shape[0]

    print "Number of training examples: " + str(trainSize)

    # Extract Features
    Features.extractFeatures(trainData[:,0], featureSet)
    print "Extracted Features:"
    if featureSet == 1 or featureSet == 3:
        print "Unigram: " + str(Features.getLength(1))
    if featureSet == 2 or featureSet == 3:
        print "Bigram: " + str(Features.getLength(2))

    # Construct Input Matrices X
    xTrain = Features.getMatrix(trainData[:,0], featureSet)
    print "Train Matrix built"

    xValidation = Features.getMatrix(validationData[:,0], featureSet)
    print "Validation Matrix built"

    xTest = Features.getMatrix(testData[:,0], featureSet)
    print "Test Matrix built"
    
    yTrain = extractLabel(trainData[:,1])
    yVailidation = extractLabel(validationData[:,1])
    yTest = extractLabel(testData[:,1])

    # Train the model
    theta = GD(xTrain, yTrain, trainSize, maxIterations, regularization, stepSize, lmbd, featureSet)
    print "Final Theta: " + str(theta)

    # Classify
    trainResult = predict(xTrain, trainSize, theta, featureSet)
    print "Train Result: " + str(trainResult)
    validationResult = predict(xValidation, validationSize, theta, featureSet)
    print "Validation Result: " + str(validationResult)
    testResult = predict(xTest, testSize, theta, featureSet)
    print "Test Result: " + str(testResult)

    # Performance
    print "\nPerformance on training data:"
    performance(trainResult, trainData[:,1])
    print "\nPerformance on validation data:"
    performance(validationResult, validationData[:,1])
    print "\nPerformance on test data:"
    performance(testResult, testData[:,1])
开发者ID:aparolia,项目名称:MLProjects,代码行数:58,代码来源:GD.py


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