##########

#For linear
import linear
h = linear.LinearClassifier({'lossFunction': linear.SquaredLoss(), 'lambda': 0, 'numIter': 100, 'stepSize': 0.5})


runClassifier.trainTestSet(h, datasets.TwoDAxisAligned)

X = datasets.TwoDAxisAligned.X
Y = datasets.TwoDAxisAligned.Y

#mlGraphics.plotLinearClassifier(h, X, Y)

h = linear.LinearClassifier({'lossFunction': linear.SquaredLoss(), 'lambda': 10, 'numIter': 100, 'stepSize': 0.5})
runClassifier.trainTestSet(h, datasets.TwoDAxisAligned)


h = linear.LinearClassifier({'lossFunction': linear.SquaredLoss(), 'lambda': 10, 'numIter': 100, 'stepSize': 0.5})
runClassifier.trainTestSet(h, datasets.TwoDDiagonal)

h = linear.LinearClassifier({'lossFunction': linear.HingeLoss(), 'lambda': 1, 'numIter': 100, 'stepSize': 0.5})
runClassifier.trainTestSet(h, datasets.TwoDDiagonal)

log = linear.LinearClassifier({'lossFunction': linear.LogisticLoss(), 'lambda': 1, 'numIter': 100, 'stepSize': 0.5})
runClassifier.trainTestSet(log, datasets.TwoDDiagonal)
        

        
Esempio n. 2
0
# # Training accuracy 0.98, test accuracy 0.86
# print(f)
# # w=array([ 1.17110065,  4.67288657])
#
# # LogisticLoss
#
# f = linear.LinearClassifier({'lossFunction': linear.LogisticLoss(), 'lambda': 10, 'numIter': 100, 'stepSize': 0.5})
# runClassifier.trainTestSet(f, datasets.TwoDDiagonal)
# # Training accuracy 0.99, test accuracy 0.86
# print(f)
# # w=array([ 0.29809083,  1.01287561])

# WU5
print("Logistic:")
f = linear.LinearClassifier({
    'lossFunction': linear.LogisticLoss(),
    'lambda': 1,
    'numIter': 100,
    'stepSize': 0.5
})
runClassifier.trainTestSet(f, datasets.WineDataBinary)

large = [
    0.606423261902, 0.689199007903, 0.710890552154, 0.770124769156,
    0.883289753118
]

small = [
    -1.1695212164, -0.765309390643, -0.683593167789, -0.629590728143,
    -0.532191672468
]