Esempio n. 1
0
except:
    print 'Error: wrong number of features to keep:' + sys.argv[
        2] + ', give me a number!'
    sys.exit()

threadNum = 1
try:
    if len(sys.argv) == 6:
        threadNum = int(sys.argv[5])
except:
    print 'Error: wrong number of features to keep:' + sys.argv[
        2] + ', give me a number!'
    sys.exit()

#prepare the data set parameters
mySet = SampleSet()
fname = sys.argv[1]

#print mySet.parameters
#select metric
import time
starttime = time.time()
selectors = []
for id in range(threadNum):
    selectors.append(FeatureSelector(sys.argv[2], id, threadNum))

events = map(lambda x: x.startProcessing(fname), selectors)
map(lambda x: x.wait(), events)

selector = reduce(lambda x, y: x.combine(y), selectors)
"""
    Testing: random data, arbitrary rules.

"""
from dataManagement import Attribute, RandomAttribute, SampleSet, RandomAttributeFactory
from ruleslearner import RulesLearner

#prepare the data set
mySet = SampleSet()

#the set of attributes that are correlated
att1 = RandomAttribute("WiFi")
att2 = RandomAttribute("time")
att3 = RandomAttribute("location")

#declare attributes
att1.add("off", "on")
att2.add("morning", "afternoon", "evening", "night")
att3.add("home", "work", "other")

#add the attributes
mySet.addDefinition(att1)  # wifi
mySet.addDefinition(att2)  # time
mySet.addDefinition(att3)  # location
parameters = [att1, att2, att3]

#add 10 random attributes
random_factory = RandomAttributeFactory(1000)
for idx in range(1, 10):
    rndatt = random_factory.getNext()
    parameters.append(rndatt)
"""
    Testing: very basic test of interfaces.

"""

from dataManagement import Attribute, SampleSet
from ruleslearner import RulesLearner

mySet = SampleSet()


#declare attributes
att = Attribute("WiFi")
att.add("off", "on")

att2 = Attribute("time")
att2.add("morning", "afternoon", "evening", "night")

att3 = Attribute("location")
att3.add("home", "work", "other")

#add the attributes
mySet.addDefinition(att)   # wifi
mySet.addDefinition(att3)  # location

#select classifier
learner = RulesLearner('full_likelihood', mySet)
learner.setTemplateRuleLearnerName("[WiFi] <= When [Location] ")

#not necessary as learner already has the set
#rule.learner = FullLikelihood(mySet)