random_forest_client_sample.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 try:
00004     from ml_classifiers.srv import *
00005     from ml_classifiers.msg import *
00006 except:
00007     import roslib;roslib.load_manifest("ml_classifiers")
00008     from ml_classifiers.srv import *
00009     from ml_classifiers.msg import *
00010 
00011 import rospy
00012 import random
00013 
00014 HEADER = '\033[95m'
00015 OKBLUE = '\033[94m'
00016 OKGREEN = '\033[92m'
00017 WARNING = '\033[93m'
00018 FAIL = '\033[91m'
00019 ENDC = '\033[0m'
00020 
00021 if __name__ == "__main__":
00022     rospy.init_node("random_forest_client")
00023 
00024     rospy.wait_for_service('predict')
00025 
00026     rospy.loginfo("Start Request Service!!")
00027 
00028     predict_data = rospy.ServiceProxy('predict', ClassifyData)
00029 
00030     while not rospy.is_shutdown():
00031         req = ClassifyDataRequest()
00032         req_point = ClassDataPoint()
00033         target = [random.random(), random.random()]
00034         answer = 1
00035         #Check if it is in the circle radius = 1?
00036         if target[0] * target[0] + target[1] * target[1] > 1:
00037             answer = 0
00038         req_point.point = target
00039         req.data.append(req_point)
00040         print OKGREEN,"Send Request         ====================>         Answer",ENDC
00041         print OKGREEN,"    ",req_point.point,"       : ",str(answer),ENDC
00042         response = predict_data(req)
00043         print WARNING,"Get the result : ",ENDC
00044         print WARNING,response.classifications,ENDC
00045         if response.classifications[0].find(str(answer)):
00046             print OKBLUE,"Succeed!!!",ENDC
00047         else:
00048             print FAIL,"FAIL...",FAIL
00049         print "--- --- --- ---"
00050 
00051         rospy.sleep(1)


sklearn
Author(s):
autogenerated on Wed Oct 7 2015 14:06:59