{"nwo":"00nanhai\/captchacker2","sha":"7609141b51ff0cf3329608b8101df967cb74752f","path":"svm.py","language":"python","identifier":"toPyModel","parameters":"(model_ptr)","argument_list":"","return_statement":"return m","docstring":"toPyModel(model_ptr) -> svm_model\n\n\tConvert a ctypes POINTER(svm_model) to a Python svm_model","docstring_summary":"toPyModel(model_ptr) -> svm_model","docstring_tokens":["toPyModel","(","model_ptr",")","-",">","svm_model"],"function":"def toPyModel(model_ptr):\n\t\"\"\"\n\ttoPyModel(model_ptr) -> svm_model\n\n\tConvert a ctypes POINTER(svm_model) to a Python svm_model\n\t\"\"\"\n\tif bool(model_ptr) == False:\n\t\traise ValueError(\"Null pointer\")\n\tm = model_ptr.contents\n\tm.__createfrom__ = 'C'\n\treturn m","function_tokens":["def","toPyModel","(","model_ptr",")",":","if","bool","(","model_ptr",")","==","False",":","raise","ValueError","(","\"Null pointer\"",")","m","=","model_ptr",".","contents","m",".","__createfrom__","=","'C'","return","m"],"url":"https:\/\/github.com\/00nanhai\/captchacker2\/blob\/7609141b51ff0cf3329608b8101df967cb74752f\/svm.py#L293-L303"} {"nwo":"00nanhai\/captchacker2","sha":"7609141b51ff0cf3329608b8101df967cb74752f","path":"svmutil.py","language":"python","identifier":"svm_read_problem","parameters":"(data_file_name)","argument_list":"","return_statement":"return (prob_y, prob_x)","docstring":"svm_read_problem(data_file_name) -> [y, x]\n\n\tRead LIBSVM-format data from data_file_name and return labels y\n\tand data instances x.","docstring_summary":"svm_read_problem(data_file_name) -> [y, x]","docstring_tokens":["svm_read_problem","(","data_file_name",")","-",">","[","y","x","]"],"function":"def svm_read_problem(data_file_name):\n\t\"\"\"\n\tsvm_read_problem(data_file_name) -> [y, x]\n\n\tRead LIBSVM-format data from data_file_name and return labels y\n\tand data instances x.\n\t\"\"\"\n\tprob_y = []\n\tprob_x = []\n\tfor line in open(data_file_name):\n\t\tline = line.split(None, 1)\n\t\t# In case an instance with all zero features\n\t\tif len(line) == 1: line += ['']\n\t\tlabel, features = line\n\t\txi = {}\n\t\tfor e in features.split():\n\t\t\tind, val = e.split(\":\")\n\t\t\txi[int(ind)] = float(val)\n\t\tprob_y += [float(label)]\n\t\tprob_x += [xi]\n\treturn (prob_y, prob_x)","function_tokens":["def","svm_read_problem","(","data_file_name",")",":","prob_y","=","[","]","prob_x","=","[","]","for","line","in","open","(","data_file_name",")",":","line","=","line",".","split","(","None",",","1",")","# In case an instance with all zero features","if","len","(","line",")","==","1",":","line","+=","[","''","]","label",",","features","=","line","xi","=","{","}","for","e","in","features",".","split","(",")",":","ind",",","val","=","e",".","split","(","\":\"",")","xi","[","int","(","ind",")","]","=","float","(","val",")","prob_y","+=","[","float","(","label",")","]","prob_x","+=","[","xi","]","return","(","prob_y",",","prob_x",")"],"url":"https:\/\/github.com\/00nanhai\/captchacker2\/blob\/7609141b51ff0cf3329608b8101df967cb74752f\/svmutil.py#L14-L34"} {"nwo":"00nanhai\/captchacker2","sha":"7609141b51ff0cf3329608b8101df967cb74752f","path":"svmutil.py","language":"python","identifier":"svm_load_model","parameters":"(model_file_name)","argument_list":"","return_statement":"return model","docstring":"svm_load_model(model_file_name) -> model\n\n\tLoad a LIBSVM model from model_file_name and return.","docstring_summary":"svm_load_model(model_file_name) -> model","docstring_tokens":["svm_load_model","(","model_file_name",")","-",">","model"],"function":"def svm_load_model(model_file_name):\n\t\"\"\"\n\tsvm_load_model(model_file_name) -> model\n\n\tLoad a LIBSVM model from model_file_name and return.\n\t\"\"\"\n\tmodel = libsvm.svm_load_model(model_file_name.encode())\n\tif not model:\n\t\tprint(\"can't open model file %s\" % model_file_name)\n\t\treturn None\n\tmodel = toPyModel(model)\n\treturn model","function_tokens":["def","svm_load_model","(","model_file_name",")",":","model","=","libsvm",".","svm_load_model","(","model_file_name",".","encode","(",")",")","if","not","model",":","print","(","\"can't open model file %s\"","%","model_file_name",")","return","None","model","=","toPyModel","(","model",")","return","model"],"url":"https:\/\/github.com\/00nanhai\/captchacker2\/blob\/7609141b51ff0cf3329608b8101df967cb74752f\/svmutil.py#L36-L47"} {"nwo":"00nanhai\/captchacker2","sha":"7609141b51ff0cf3329608b8101df967cb74752f","path":"svmutil.py","language":"python","identifier":"svm_save_model","parameters":"(model_file_name, model)","argument_list":"","return_statement":"","docstring":"svm_save_model(model_file_name, model) -> None\n\n\tSave a LIBSVM model to the file model_file_name.","docstring_summary":"svm_save_model(model_file_name, model) -> None","docstring_tokens":["svm_save_model","(","model_file_name","model",")","-",">","None"],"function":"def svm_save_model(model_file_name, model):\n\t\"\"\"\n\tsvm_save_model(model_file_name, model) -> None\n\n\tSave a LIBSVM model to the file model_file_name.\n\t\"\"\"\n\tlibsvm.svm_save_model(model_file_name.encode(), model)","function_tokens":["def","svm_save_model","(","model_file_name",",","model",")",":","libsvm",".","svm_save_model","(","model_file_name",".","encode","(",")",",","model",")"],"url":"https:\/\/github.com\/00nanhai\/captchacker2\/blob\/7609141b51ff0cf3329608b8101df967cb74752f\/svmutil.py#L49-L55"} {"nwo":"00nanhai\/captchacker2","sha":"7609141b51ff0cf3329608b8101df967cb74752f","path":"svmutil.py","language":"python","identifier":"evaluations","parameters":"(ty, pv)","argument_list":"","return_statement":"return (ACC, MSE, SCC)","docstring":"evaluations(ty, pv) -> (ACC, MSE, SCC)\n\n\tCalculate accuracy, mean squared error and squared correlation coefficient\n\tusing the true values (ty) and predicted values (pv).","docstring_summary":"evaluations(ty, pv) -> (ACC, MSE, SCC)","docstring_tokens":["evaluations","(","ty","pv",")","-",">","(","ACC","MSE","SCC",")"],"function":"def evaluations(ty, pv):\n\t\"\"\"\n\tevaluations(ty, pv) -> (ACC, MSE, SCC)\n\n\tCalculate accuracy, mean squared error and squared correlation coefficient\n\tusing the true values (ty) and predicted values (pv).\n\t\"\"\"\n\tif len(ty) != len(pv):\n\t\traise ValueError(\"len(ty) must equal to len(pv)\")\n\ttotal_correct = total_error = 0\n\tsumv = sumy = sumvv = sumyy = sumvy = 0\n\tfor v, y in zip(pv, ty):\n\t\tif y == v:\n\t\t\ttotal_correct += 1\n\t\ttotal_error += (v-y)*(v-y)\n\t\tsumv += v\n\t\tsumy += y\n\t\tsumvv += v*v\n\t\tsumyy += y*y\n\t\tsumvy += v*y\n\tl = len(ty)\n\tACC = 100.0*total_correct\/l\n\tMSE = total_error\/l\n\ttry:\n\t\tSCC = ((l*sumvy-sumv*sumy)*(l*sumvy-sumv*sumy))\/((l*sumvv-sumv*sumv)*(l*sumyy-sumy*sumy))\n\texcept:\n\t\tSCC = float('nan')\n\treturn (ACC, MSE, SCC)","function_tokens":["def","evaluations","(","ty",",","pv",")",":","if","len","(","ty",")","!=","len","(","pv",")",":","raise","ValueError","(","\"len(ty) must equal to len(pv)\"",")","total_correct","=","total_error","=","0","sumv","=","sumy","=","sumvv","=","sumyy","=","sumvy","=","0","for","v",",","y","in","zip","(","pv",",","ty",")",":","if","y","==","v",":","total_correct","+=","1","total_error","+=","(","v","-","y",")","*","(","v","-","y",")","sumv","+=","v","sumy","+=","y","sumvv","+=","v","*","v","sumyy","+=","y","*","y","sumvy","+=","v","*","y","l","=","len","(","ty",")","ACC","=","100.0","*","total_correct","\/","l","MSE","=","total_error","\/","l","try",":","SCC","=","(","(","l","*","sumvy","-","sumv","*","sumy",")","*","(","l","*","sumvy","-","sumv","*","sumy",")",")","\/","(","(","l","*","sumvv","-","sumv","*","sumv",")","*","(","l","*","sumyy","-","sumy","*","sumy",")",")","except",":","SCC","=","float","(","'nan'",")","return","(","ACC",",","MSE",",","SCC",")"],"url":"https:\/\/github.com\/00nanhai\/captchacker2\/blob\/7609141b51ff0cf3329608b8101df967cb74752f\/svmutil.py#L57-L84"} {"nwo":"00nanhai\/captchacker2","sha":"7609141b51ff0cf3329608b8101df967cb74752f","path":"svmutil.py","language":"python","identifier":"svm_train","parameters":"(arg1, arg2=None, arg3=None)","argument_list":"","return_statement":"","docstring":"svm_train(y, x [, options]) -> model | ACC | MSE\n\tsvm_train(prob [, options]) -> model | ACC | MSE\n\tsvm_train(prob, param) -> model | ACC| MSE\n\n\tTrain an SVM model from data (y, x) or an svm_problem prob using\n\t'options' or an svm_parameter param.\n\tIf '-v' is specified in 'options' (i.e., cross validation)\n\teither accuracy (ACC) or mean-squared error (MSE) is returned.\n\toptions:\n\t -s svm_type : set type of SVM (default 0)\n\t 0 -- C-SVC\t\t(multi-class classification)\n\t 1 -- nu-SVC\t\t(multi-class classification)\n\t 2 -- one-class SVM\n\t 3 -- epsilon-SVR\t(regression)\n\t 4 -- nu-SVR\t\t(regression)\n\t -t kernel_type : set type of kernel function (default 2)\n\t 0 -- linear: u'*v\n\t 1 -- polynomial: (gamma*u'*v + coef0)^degree\n\t 2 -- radial basis function: exp(-gamma*|u-v|^2)\n\t 3 -- sigmoid: tanh(gamma*u'*v + coef0)\n\t 4 -- precomputed kernel (kernel values in training_set_file)\n\t -d degree : set degree in kernel function (default 3)\n\t -g gamma : set gamma in kernel function (default 1\/num_features)\n\t -r coef0 : set coef0 in kernel function (default 0)\n\t -c cost : set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)\n\t -n nu : set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)\n\t -p epsilon : set the epsilon in loss function of epsilon-SVR (default 0.1)\n\t -m cachesize : set cache memory size in MB (default 100)\n\t -e epsilon : set tolerance of termination criterion (default 0.001)\n\t -h shrinking : whether to use the shrinking heuristics, 0 or 1 (default 1)\n\t -b probability_estimates : whether to train a SVC or SVR model for probability estimates, 0 or 1 (default 0)\n\t -wi weight : set the parameter C of class i to weight*C, for C-SVC (default 1)\n\t -v n: n-fold cross validation mode\n\t -q : quiet mode (no outputs)","docstring_summary":"svm_train(y, x [, options]) -> model | ACC | MSE\n\tsvm_train(prob [, options]) -> model | ACC | MSE\n\tsvm_train(prob, param) -> model | ACC| MSE","docstring_tokens":["svm_train","(","y","x","[","options","]",")","-",">","model","|","ACC","|","MSE","svm_train","(","prob","[","options","]",")","-",">","model","|","ACC","|","MSE","svm_train","(","prob","param",")","-",">","model","|","ACC|","MSE"],"function":"def svm_train(arg1, arg2=None, arg3=None):\n\t\"\"\"\n\tsvm_train(y, x [, options]) -> model | ACC | MSE\n\tsvm_train(prob [, options]) -> model | ACC | MSE\n\tsvm_train(prob, param) -> model | ACC| MSE\n\n\tTrain an SVM model from data (y, x) or an svm_problem prob using\n\t'options' or an svm_parameter param.\n\tIf '-v' is specified in 'options' (i.e., cross validation)\n\teither accuracy (ACC) or mean-squared error (MSE) is returned.\n\toptions:\n\t -s svm_type : set type of SVM (default 0)\n\t 0 -- C-SVC\t\t(multi-class classification)\n\t 1 -- nu-SVC\t\t(multi-class classification)\n\t 2 -- one-class SVM\n\t 3 -- epsilon-SVR\t(regression)\n\t 4 -- nu-SVR\t\t(regression)\n\t -t kernel_type : set type of kernel function (default 2)\n\t 0 -- linear: u'*v\n\t 1 -- polynomial: (gamma*u'*v + coef0)^degree\n\t 2 -- radial basis function: exp(-gamma*|u-v|^2)\n\t 3 -- sigmoid: tanh(gamma*u'*v + coef0)\n\t 4 -- precomputed kernel (kernel values in training_set_file)\n\t -d degree : set degree in kernel function (default 3)\n\t -g gamma : set gamma in kernel function (default 1\/num_features)\n\t -r coef0 : set coef0 in kernel function (default 0)\n\t -c cost : set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)\n\t -n nu : set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)\n\t -p epsilon : set the epsilon in loss function of epsilon-SVR (default 0.1)\n\t -m cachesize : set cache memory size in MB (default 100)\n\t -e epsilon : set tolerance of termination criterion (default 0.001)\n\t -h shrinking : whether to use the shrinking heuristics, 0 or 1 (default 1)\n\t -b probability_estimates : whether to train a SVC or SVR model for probability estimates, 0 or 1 (default 0)\n\t -wi weight : set the parameter C of class i to weight*C, for C-SVC (default 1)\n\t -v n: n-fold cross validation mode\n\t -q : quiet mode (no outputs)\n\t\"\"\"\n\tprob, param = None, None\n\tif isinstance(arg1, (list, tuple)):\n\t\tassert isinstance(arg2, (list, tuple))\n\t\ty, x, options = arg1, arg2, arg3\n\t\tparam = svm_parameter(options)\n\t\tprob = svm_problem(y, x, isKernel=(param.kernel_type == PRECOMPUTED))\n\telif isinstance(arg1, svm_problem):\n\t\tprob = arg1\n\t\tif isinstance(arg2, svm_parameter):\n\t\t\tparam = arg2\n\t\telse:\n\t\t\tparam = svm_parameter(arg2)\n\tif prob == None or param == None:\n\t\traise TypeError(\"Wrong types for the arguments\")\n\n\tif param.kernel_type == PRECOMPUTED:\n\t\tfor xi in prob.x_space:\n\t\t\tidx, val = xi[0].index, xi[0].value\n\t\t\tif xi[0].index != 0:\n\t\t\t\traise ValueError('Wrong input format: first column must be 0:sample_serial_number')\n\t\t\tif val <= 0 or val > prob.n:\n\t\t\t\traise ValueError('Wrong input format: sample_serial_number out of range')\n\n\tif param.gamma == 0 and prob.n > 0:\n\t\tparam.gamma = 1.0 \/ prob.n\n\tlibsvm.svm_set_print_string_function(param.print_func)\n\terr_msg = libsvm.svm_check_parameter(prob, param)\n\tif err_msg:\n\t\traise ValueError('Error: %s' % err_msg)\n\n\tif param.cross_validation:\n\t\tl, nr_fold = prob.l, param.nr_fold\n\t\ttarget = (c_double * l)()\n\t\tlibsvm.svm_cross_validation(prob, param, nr_fold, target)\n\t\tACC, MSE, SCC = evaluations(prob.y[:l], target[:l])\n\t\tif param.svm_type in [EPSILON_SVR, NU_SVR]:\n\t\t\tprint(\"Cross Validation Mean squared error = %g\" % MSE)\n\t\t\tprint(\"Cross Validation Squared correlation coefficient = %g\" % SCC)\n\t\t\treturn MSE\n\t\telse:\n\t\t\tprint(\"Cross Validation Accuracy = %g%%\" % ACC)\n\t\t\treturn ACC\n\telse:\n\t\tm = libsvm.svm_train(prob, param)\n\t\tm = toPyModel(m)\n\n\t\t# If prob is destroyed, data including SVs pointed by m can remain.\n\t\tm.x_space = prob.x_space\n\t\treturn m","function_tokens":["def","svm_train","(","arg1",",","arg2","=","None",",","arg3","=","None",")",":","prob",",","param","=","None",",","None","if","isinstance","(","arg1",",","(","list",",","tuple",")",")",":","assert","isinstance","(","arg2",",","(","list",",","tuple",")",")","y",",","x",",","options","=","arg1",",","arg2",",","arg3","param","=","svm_parameter","(","options",")","prob","=","svm_problem","(","y",",","x",",","isKernel","=","(","param",".","kernel_type","==","PRECOMPUTED",")",")","elif","isinstance","(","arg1",",","svm_problem",")",":","prob","=","arg1","if","isinstance","(","arg2",",","svm_parameter",")",":","param","=","arg2","else",":","param","=","svm_parameter","(","arg2",")","if","prob","==","None","or","param","==","None",":","raise","TypeError","(","\"Wrong types for the arguments\"",")","if","param",".","kernel_type","==","PRECOMPUTED",":","for","xi","in","prob",".","x_space",":","idx",",","val","=","xi","[","0","]",".","index",",","xi","[","0","]",".","value","if","xi","[","0","]",".","index","!=","0",":","raise","ValueError","(","'Wrong input format: first column must be 0:sample_serial_number'",")","if","val","<=","0","or","val",">","prob",".","n",":","raise","ValueError","(","'Wrong input format: sample_serial_number out of range'",")","if","param",".","gamma","==","0","and","prob",".","n",">","0",":","param",".","gamma","=","1.0","\/","prob",".","n","libsvm",".","svm_set_print_string_function","(","param",".","print_func",")","err_msg","=","libsvm",".","svm_check_parameter","(","prob",",","param",")","if","err_msg",":","raise","ValueError","(","'Error: %s'","%","err_msg",")","if","param",".","cross_validation",":","l",",","nr_fold","=","prob",".","l",",","param",".","nr_fold","target","=","(","c_double","*","l",")","(",")","libsvm",".","svm_cross_validation","(","prob",",","param",",","nr_fold",",","target",")","ACC",",","MSE",",","SCC","=","evaluations","(","prob",".","y","[",":","l","]",",","target","[",":","l","]",")","if","param",".","svm_type","in","[","EPSILON_SVR",",","NU_SVR","]",":","print","(","\"Cross Validation Mean squared error = %g\"","%","MSE",")","print","(","\"Cross Validation Squared correlation coefficient = %g\"","%","SCC",")","return","MSE","else",":","print","(","\"Cross Validation Accuracy = %g%%\"","%","ACC",")","return","ACC","else",":","m","=","libsvm",".","svm_train","(","prob",",","param",")","m","=","toPyModel","(","m",")","# If prob is destroyed, data including SVs pointed by m can remain.","m",".","x_space","=","prob",".","x_space","return","m"],"url":"https:\/\/github.com\/00nanhai\/captchacker2\/blob\/7609141b51ff0cf3329608b8101df967cb74752f\/svmutil.py#L86-L171"} {"nwo":"00nanhai\/captchacker2","sha":"7609141b51ff0cf3329608b8101df967cb74752f","path":"svmutil.py","language":"python","identifier":"svm_predict","parameters":"(y, x, m, options=\"\")","argument_list":"","return_statement":"return pred_labels, (ACC, MSE, SCC), pred_values","docstring":"svm_predict(y, x, m [, options]) -> (p_labels, p_acc, p_vals)\n\n\tPredict data (y, x) with the SVM model m.\n\toptions:\n\t -b probability_estimates: whether to predict probability estimates,\n\t 0 or 1 (default 0); for one-class SVM only 0 is supported.\n\t -q : quiet mode (no outputs).\n\n\tThe return tuple contains\n\tp_labels: a list of predicted labels\n\tp_acc: a tuple including accuracy (for classification), mean-squared\n\t error, and squared correlation coefficient (for regression).\n\tp_vals: a list of decision values or probability estimates (if '-b 1'\n\t is specified). If k is the number of classes, for decision values,\n\t each element includes results of predicting k(k-1)\/2 binary-class\n\t SVMs. For probabilities, each element contains k values indicating\n\t the probability that the testing instance is in each class.\n\t Note that the order of classes here is the same as 'model.label'\n\t field in the model structure.","docstring_summary":"svm_predict(y, x, m [, options]) -> (p_labels, p_acc, p_vals)","docstring_tokens":["svm_predict","(","y","x","m","[","options","]",")","-",">","(","p_labels","p_acc","p_vals",")"],"function":"def svm_predict(y, x, m, options=\"\"):\n\t\"\"\"\n\tsvm_predict(y, x, m [, options]) -> (p_labels, p_acc, p_vals)\n\n\tPredict data (y, x) with the SVM model m.\n\toptions:\n\t -b probability_estimates: whether to predict probability estimates,\n\t 0 or 1 (default 0); for one-class SVM only 0 is supported.\n\t -q : quiet mode (no outputs).\n\n\tThe return tuple contains\n\tp_labels: a list of predicted labels\n\tp_acc: a tuple including accuracy (for classification), mean-squared\n\t error, and squared correlation coefficient (for regression).\n\tp_vals: a list of decision values or probability estimates (if '-b 1'\n\t is specified). If k is the number of classes, for decision values,\n\t each element includes results of predicting k(k-1)\/2 binary-class\n\t SVMs. For probabilities, each element contains k values indicating\n\t the probability that the testing instance is in each class.\n\t Note that the order of classes here is the same as 'model.label'\n\t field in the model structure.\n\t\"\"\"\n\n\tdef info(s):\n\t\tprint(s)\n\n\tpredict_probability = 0\n\targv = options.split()\n\ti = 0\n\twhile i < len(argv):\n\t\tif argv[i] == '-b':\n\t\t\ti += 1\n\t\t\tpredict_probability = int(argv[i])\n\t\telif argv[i] == '-q':\n\t\t\tinfo = print_null\n\t\telse:\n\t\t\traise ValueError(\"Wrong options\")\n\t\ti+=1\n\n\tsvm_type = m.get_svm_type()\n\tis_prob_model = m.is_probability_model()\n\tnr_class = m.get_nr_class()\n\tpred_labels = []\n\tpred_values = []\n\n\tif predict_probability:\n\t\tif not is_prob_model:\n\t\t\traise ValueError(\"Model does not support probabiliy estimates\")\n\n\t\tif svm_type in [NU_SVR, EPSILON_SVR]:\n\t\t\tinfo(\"Prob. model for test data: target value = predicted value + z,\\n\"\n\t\t\t\"z: Laplace distribution e^(-|z|\/sigma)\/(2sigma),sigma=%g\" % m.get_svr_probability());\n\t\t\tnr_class = 0\n\n\t\tprob_estimates = (c_double * nr_class)()\n\t\tfor xi in x:\n\t\t\txi, idx = gen_svm_nodearray(xi, isKernel=(m.param.kernel_type == PRECOMPUTED))\n\t\t\tlabel = libsvm.svm_predict_probability(m, xi, prob_estimates)\n\t\t\tvalues = prob_estimates[:nr_class]\n\t\t\tpred_labels += [label]\n\t\t\tpred_values += [values]\n\telse:\n\t\tif is_prob_model:\n\t\t\tinfo(\"Model supports probability estimates, but disabled in predicton.\")\n\t\tif svm_type in (ONE_CLASS, EPSILON_SVR, NU_SVC):\n\t\t\tnr_classifier = 1\n\t\telse:\n\t\t\tnr_classifier = nr_class*(nr_class-1)\/\/2\n\t\tdec_values = (c_double * nr_classifier)()\n\t\tfor xi in x:\n\t\t\txi, idx = gen_svm_nodearray(xi, isKernel=(m.param.kernel_type == PRECOMPUTED))\n\t\t\tlabel = libsvm.svm_predict_values(m, xi, dec_values)\n\t\t\tif(nr_class == 1):\n\t\t\t\tvalues = [1]\n\t\t\telse:\n\t\t\t\tvalues = dec_values[:nr_classifier]\n\t\t\tpred_labels += [label]\n\t\t\tpred_values += [values]\n\n\tACC, MSE, SCC = evaluations(y, pred_labels)\n\tl = len(y)\n\tif svm_type in [EPSILON_SVR, NU_SVR]:\n\t\tinfo(\"Mean squared error = %g (regression)\" % MSE)\n\t\tinfo(\"Squared correlation coefficient = %g (regression)\" % SCC)\n\telse:\n\t\tinfo(\"Accuracy = %g%% (%d\/%d) (classification)\" % (ACC, int(l*ACC\/100), l))\n\n\treturn pred_labels, (ACC, MSE, SCC), pred_values","function_tokens":["def","svm_predict","(","y",",","x",",","m",",","options","=","\"\"",")",":","def","info","(","s",")",":","print","(","s",")","predict_probability","=","0","argv","=","options",".","split","(",")","i","=","0","while","i","<","len","(","argv",")",":","if","argv","[","i","]","==","'-b'",":","i","+=","1","predict_probability","=","int","(","argv","[","i","]",")","elif","argv","[","i","]","==","'-q'",":","info","=","print_null","else",":","raise","ValueError","(","\"Wrong options\"",")","i","+=","1","svm_type","=","m",".","get_svm_type","(",")","is_prob_model","=","m",".","is_probability_model","(",")","nr_class","=","m",".","get_nr_class","(",")","pred_labels","=","[","]","pred_values","=","[","]","if","predict_probability",":","if","not","is_prob_model",":","raise","ValueError","(","\"Model does not support probabiliy estimates\"",")","if","svm_type","in","[","NU_SVR",",","EPSILON_SVR","]",":","info","(","\"Prob. model for test data: target value = predicted value + z,\\n\"","\"z: Laplace distribution e^(-|z|\/sigma)\/(2sigma),sigma=%g\"","%","m",".","get_svr_probability","(",")",")","nr_class","=","0","prob_estimates","=","(","c_double","*","nr_class",")","(",")","for","xi","in","x",":","xi",",","idx","=","gen_svm_nodearray","(","xi",",","isKernel","=","(","m",".","param",".","kernel_type","==","PRECOMPUTED",")",")","label","=","libsvm",".","svm_predict_probability","(","m",",","xi",",","prob_estimates",")","values","=","prob_estimates","[",":","nr_class","]","pred_labels","+=","[","label","]","pred_values","+=","[","values","]","else",":","if","is_prob_model",":","info","(","\"Model supports probability estimates, but disabled in predicton.\"",")","if","svm_type","in","(","ONE_CLASS",",","EPSILON_SVR",",","NU_SVC",")",":","nr_classifier","=","1","else",":","nr_classifier","=","nr_class","*","(","nr_class","-","1",")","\/\/","2","dec_values","=","(","c_double","*","nr_classifier",")","(",")","for","xi","in","x",":","xi",",","idx","=","gen_svm_nodearray","(","xi",",","isKernel","=","(","m",".","param",".","kernel_type","==","PRECOMPUTED",")",")","label","=","libsvm",".","svm_predict_values","(","m",",","xi",",","dec_values",")","if","(","nr_class","==","1",")",":","values","=","[","1","]","else",":","values","=","dec_values","[",":","nr_classifier","]","pred_labels","+=","[","label","]","pred_values","+=","[","values","]","ACC",",","MSE",",","SCC","=","evaluations","(","y",",","pred_labels",")","l","=","len","(","y",")","if","svm_type","in","[","EPSILON_SVR",",","NU_SVR","]",":","info","(","\"Mean squared error = %g (regression)\"","%","MSE",")","info","(","\"Squared correlation coefficient = %g (regression)\"","%","SCC",")","else",":","info","(","\"Accuracy = %g%% (%d\/%d) (classification)\"","%","(","ACC",",","int","(","l","*","ACC","\/","100",")",",","l",")",")","return","pred_labels",",","(","ACC",",","MSE",",","SCC",")",",","pred_values"],"url":"https:\/\/github.com\/00nanhai\/captchacker2\/blob\/7609141b51ff0cf3329608b8101df967cb74752f\/svmutil.py#L173-L260"} {"nwo":"00nanhai\/captchacker2","sha":"7609141b51ff0cf3329608b8101df967cb74752f","path":"pycaptcha\/modpython_example.py","language":"python","identifier":"test","parameters":"(req, name=Tests.__all__[0])","argument_list":"","return_statement":"return \"\"\"\n
\n\n %s<\/b>:\n %s\n<\/p>\n\n
<\/p>\n
\n