int main() { config_parse_remote_servers("servers.txt"); trainingdata_t* data = trainingdata_new(); int t; for(t=0;t<256;t++) { example_t*e = example_new(16); int s; for(s=0;s<16;s++) { e->inputs[s] = variable_new_continuous((lrand48()%256)/256.0); } e->desired_response = variable_new_categorical(t%2); trainingdata_add_example(data, e); } trainingdata_save(data, "/tmp/data.data"); trainingdata_destroy(data); data = trainingdata_load("/tmp/data.data"); model_t*m = model_select(data); char*code = model_generate_code(m, "python"); printf("%s\n", code); free(code); model_destroy(m); trainingdata_destroy(data); }
static PyObject* py_dataset_add(PyObject * _self, PyObject* args, PyObject* kwargs) { DataSetObject*self = (DataSetObject*)_self; static char *kwlist[] = {"input","output",NULL}; PyObject*input=0,*output=0; if (args && !PyArg_ParseTupleAndKeywords(args, kwargs, "OO", kwlist, &input, &output)) return NULL; if(!PyList_Check(input) && !PyDict_Check(input)) // && !PyTuple_Check(input)) return PY_ERROR("first argument to train() must be a list or a dict"); example_t*e = pylist_to_example(input); if(!e) return NULL; if(pyint_check(output)) { e->desired_response = variable_new_categorical(pyint_as_long(output)); } else if(pystring_check(output)) { e->desired_response = variable_new_text(pystring_asstring(output)); } else { return PY_ERROR("output parameter must be an integer or a string"); } trainingdata_add_example(self->data, e); return PY_NONE; }
environment_t test_environment() { row_t*row = row_new(4); row->inputs[0] = variable_new_continuous(1.0); row->inputs[1] = variable_new_continuous(2.0); row->inputs[2] = variable_new_continuous(4.0); row->inputs[3] = variable_new_categorical(5); environment_t e; e.row = row; return e; }
void test() { trainingdata_t* data = trainingdata_new(); int t; for(t=0;t<256;t++) { example_t*e = example_new(16); int s; for(s=0;s<16;s++) { e->inputs[s] = variable_new_continuous((lrand48()%256)/256.0); } e->desired_response = variable_new_categorical(t%2); trainingdata_add_example(data, e); } dataset_t*dataset = trainingdata_sanitize(data); model_t*m = process_job_remotely("dtree", dataset); if(m) { printf("%s\n", m->name); } }