_id
stringlengths 2
7
| title
stringlengths 1
88
| partition
stringclasses 3
values | text
stringlengths 75
19.8k
| language
stringclasses 1
value | meta_information
dict |
|---|---|---|---|---|---|
q1600
|
MultiFilter.filters
|
train
|
def filters(self):
"""
Returns the list of base filters.
:return: the filter list
:rtype: list
"""
objects = javabridge.get_env().get_object_array_elements(
javabridge.call(self.jobject, "getFilters", "()[Lweka/filters/Filter;"))
result = []
for obj in objects:
result.append(Filter(jobject=obj))
return result
|
python
|
{
"resource": ""
}
|
q1601
|
MultiFilter.filters
|
train
|
def filters(self, filters):
"""
Sets the base filters.
:param filters: the list of base filters to use
:type filters: list
"""
obj = []
for fltr in filters:
obj.append(fltr.jobject)
javabridge.call(self.jobject, "setFilters", "([Lweka/filters/Filter;)V", obj)
|
python
|
{
"resource": ""
}
|
q1602
|
Container.generate_help
|
train
|
def generate_help(self):
"""
Generates a help string for this container.
:return: the help string
:rtype: str
"""
result = []
result.append(self.__class__.__name__)
result.append(re.sub(r'.', '=', self.__class__.__name__))
result.append("")
result.append("Supported value names:")
for a in self.allowed:
result.append(a)
return '\n'.join(result)
|
python
|
{
"resource": ""
}
|
q1603
|
plot_dot_graph
|
train
|
def plot_dot_graph(graph, filename=None):
"""
Plots a graph in graphviz dot notation.
:param graph: the dot notation graph
:type graph: str
:param filename: the (optional) file to save the generated plot to. The extension determines the file format.
:type filename: str
"""
if not plot.pygraphviz_available:
logger.error("Pygraphviz is not installed, cannot generate graph plot!")
return
if not plot.PIL_available:
logger.error("PIL is not installed, cannot display graph plot!")
return
agraph = AGraph(graph)
agraph.layout(prog='dot')
if filename is None:
filename = tempfile.mktemp(suffix=".png")
agraph.draw(filename)
image = Image.open(filename)
image.show()
|
python
|
{
"resource": ""
}
|
q1604
|
Stemmer.stem
|
train
|
def stem(self, s):
"""
Performs stemming on the string.
:param s: the string to stem
:type s: str
:return: the stemmed string
:rtype: str
"""
return javabridge.get_env().get_string(self.__stem(javabridge.get_env().new_string_utf(s)))
|
python
|
{
"resource": ""
}
|
q1605
|
Instances.attribute_by_name
|
train
|
def attribute_by_name(self, name):
"""
Returns the specified attribute, None if not found.
:param name: the name of the attribute
:type name: str
:return: the attribute or None
:rtype: Attribute
"""
att = self.__attribute_by_name(javabridge.get_env().new_string(name))
if att is None:
return None
else:
return Attribute(att)
|
python
|
{
"resource": ""
}
|
q1606
|
Instances.add_instance
|
train
|
def add_instance(self, inst, index=None):
"""
Adds the specified instance to the dataset.
:param inst: the Instance to add
:type inst: Instance
:param index: the 0-based index where to add the Instance
:type index: int
"""
if index is None:
self.__append_instance(inst.jobject)
else:
self.__insert_instance(index, inst.jobject)
|
python
|
{
"resource": ""
}
|
q1607
|
Instances.set_instance
|
train
|
def set_instance(self, index, inst):
"""
Sets the Instance at the specified location in the dataset.
:param index: the 0-based index of the instance to replace
:type index: int
:param inst: the Instance to set
:type inst: Instance
:return: the instance
:rtype: Instance
"""
return Instance(
self.__set_instance(index, inst.jobject))
|
python
|
{
"resource": ""
}
|
q1608
|
Instances.delete
|
train
|
def delete(self, index=None):
"""
Removes either the specified Instance or all Instance objects.
:param index: the 0-based index of the instance to remove
:type index: int
"""
if index is None:
javabridge.call(self.jobject, "delete", "()V")
else:
javabridge.call(self.jobject, "delete", "(I)V", index)
|
python
|
{
"resource": ""
}
|
q1609
|
Instances.insert_attribute
|
train
|
def insert_attribute(self, att, index):
"""
Inserts the attribute at the specified location.
:param att: the attribute to insert
:type att: Attribute
:param index: the index to insert the attribute at
:type index: int
"""
javabridge.call(self.jobject, "insertAttributeAt", "(Lweka/core/Attribute;I)V", att.jobject, index)
|
python
|
{
"resource": ""
}
|
q1610
|
Instances.train_cv
|
train
|
def train_cv(self, num_folds, fold, random=None):
"""
Generates a training fold for cross-validation.
:param num_folds: the number of folds of cross-validation, eg 10
:type num_folds: int
:param fold: the current fold (0-based)
:type fold: int
:param random: the random number generator
:type random: Random
:return: the training fold
:rtype: Instances
"""
if random is None:
return Instances(
javabridge.call(self.jobject, "trainCV", "(II)Lweka/core/Instances;",
num_folds, fold))
else:
return Instances(
javabridge.call(self.jobject, "trainCV", "(IILjava/util/Random;)Lweka/core/Instances;",
num_folds, fold, random.jobject))
|
python
|
{
"resource": ""
}
|
q1611
|
Instances.copy_instances
|
train
|
def copy_instances(cls, dataset, from_row=None, num_rows=None):
"""
Creates a copy of the Instances. If either from_row or num_rows are None, then all of
the data is being copied.
:param dataset: the original dataset
:type dataset: Instances
:param from_row: the 0-based start index of the rows to copy
:type from_row: int
:param num_rows: the number of rows to copy
:type num_rows: int
:return: the copy of the data
:rtype: Instances
"""
if from_row is None or num_rows is None:
return Instances(
javabridge.make_instance(
"weka/core/Instances", "(Lweka/core/Instances;)V",
dataset.jobject))
else:
dataset = cls.copy_instances(dataset)
return Instances(
javabridge.make_instance(
"weka/core/Instances", "(Lweka/core/Instances;II)V",
dataset.jobject, from_row, num_rows))
|
python
|
{
"resource": ""
}
|
q1612
|
Instances.template_instances
|
train
|
def template_instances(cls, dataset, capacity=0):
"""
Uses the Instances as template to create an empty dataset.
:param dataset: the original dataset
:type dataset: Instances
:param capacity: how many data rows to reserve initially (see compactify)
:type capacity: int
:return: the empty dataset
:rtype: Instances
"""
return Instances(
javabridge.make_instance(
"weka/core/Instances", "(Lweka/core/Instances;I)V", dataset.jobject, capacity))
|
python
|
{
"resource": ""
}
|
q1613
|
Instances.create_instances
|
train
|
def create_instances(cls, name, atts, capacity):
"""
Creates a new Instances.
:param name: the relation name
:type name: str
:param atts: the list of attributes to use for the dataset
:type atts: list of Attribute
:param capacity: how many data rows to reserve initially (see compactify)
:type capacity: int
:return: the dataset
:rtype: Instances
"""
attributes = []
for att in atts:
attributes.append(att.jobject)
return Instances(
javabridge.make_instance(
"weka/core/Instances", "(Ljava/lang/String;Ljava/util/ArrayList;I)V",
name, javabridge.make_list(attributes), capacity))
|
python
|
{
"resource": ""
}
|
q1614
|
Instance.dataset
|
train
|
def dataset(self):
"""
Returns the dataset that this instance belongs to.
:return: the dataset or None if no dataset set
:rtype: Instances
"""
dataset = javabridge.call(self.jobject, "dataset", "()Lweka/core/Instances;")
if dataset is None:
return None
else:
return Instances(dataset)
|
python
|
{
"resource": ""
}
|
q1615
|
Instance.create_sparse_instance
|
train
|
def create_sparse_instance(cls, values, max_values, classname="weka.core.SparseInstance", weight=1.0):
"""
Creates a new sparse instance.
:param values: the list of tuples (0-based index and internal format float). The indices of the
tuples must be in ascending order and "max_values" must be set to the maximum
number of attributes in the dataset.
:type values: list
:param max_values: the maximum number of attributes
:type max_values: int
:param classname: the classname of the instance (eg weka.core.SparseInstance).
:type classname: str
:param weight: the weight of the instance
:type weight: float
"""
jni_classname = classname.replace(".", "/")
indices = []
vals = []
for (i, v) in values:
indices.append(i)
vals.append(float(v))
indices = numpy.array(indices, dtype=numpy.int32)
vals = numpy.array(vals)
return Instance(
javabridge.make_instance(
jni_classname, "(D[D[II)V",
weight, javabridge.get_env().make_double_array(vals),
javabridge.get_env().make_int_array(indices), max_values))
|
python
|
{
"resource": ""
}
|
q1616
|
Attribute.type_str
|
train
|
def type_str(self, short=False):
"""
Returns the type of the attribute as string.
:return: the type
:rtype: str
"""
if short:
return javabridge.static_call(
"weka/core/Attribute", "typeToStringShort", "(Lweka/core/Attribute;)Ljava/lang/String;",
self.jobject)
else:
return javabridge.static_call(
"weka/core/Attribute", "typeToString", "(Lweka/core/Attribute;)Ljava/lang/String;",
self.jobject)
|
python
|
{
"resource": ""
}
|
q1617
|
Attribute.copy
|
train
|
def copy(self, name=None):
"""
Creates a copy of this attribute.
:param name: the new name, uses the old one if None
:type name: str
:return: the copy of the attribute
:rtype: Attribute
"""
if name is None:
return Attribute(
javabridge.call(self.jobject, "copy", "()Ljava/lang/Object;"))
else:
return Attribute(
javabridge.call(self.jobject, "copy", "(Ljava/lang/String;)Lweka/core/Attribute;", name))
|
python
|
{
"resource": ""
}
|
q1618
|
Attribute.create_nominal
|
train
|
def create_nominal(cls, name, labels):
"""
Creates a nominal attribute.
:param name: the name of the attribute
:type name: str
:param labels: the list of string labels to use
:type labels: list
"""
return Attribute(
javabridge.make_instance(
"weka/core/Attribute", "(Ljava/lang/String;Ljava/util/List;)V", name, javabridge.make_list(labels)))
|
python
|
{
"resource": ""
}
|
q1619
|
Attribute.create_relational
|
train
|
def create_relational(cls, name, inst):
"""
Creates a relational attribute.
:param name: the name of the attribute
:type name: str
:param inst: the structure of the relational attribute
:type inst: Instances
"""
return Attribute(
javabridge.make_instance(
"weka/core/Attribute", "(Ljava/lang/String;Lweka/core/Instances;)V", name, inst.jobject))
|
python
|
{
"resource": ""
}
|
q1620
|
add_bundled_jars
|
train
|
def add_bundled_jars():
"""
Adds the bundled jars to the JVM's classpath.
"""
# determine lib directory with jars
rootdir = os.path.split(os.path.dirname(__file__))[0]
libdir = rootdir + os.sep + "lib"
# add jars from lib directory
for l in glob.glob(libdir + os.sep + "*.jar"):
if l.lower().find("-src.") == -1:
javabridge.JARS.append(str(l))
|
python
|
{
"resource": ""
}
|
q1621
|
add_system_classpath
|
train
|
def add_system_classpath():
"""
Adds the system's classpath to the JVM's classpath.
"""
if 'CLASSPATH' in os.environ:
parts = os.environ['CLASSPATH'].split(os.pathsep)
for part in parts:
javabridge.JARS.append(part)
|
python
|
{
"resource": ""
}
|
q1622
|
get_class
|
train
|
def get_class(classname):
"""
Returns the class object associated with the dot-notation classname.
Taken from here: http://stackoverflow.com/a/452981
:param classname: the classname
:type classname: str
:return: the class object
:rtype: object
"""
parts = classname.split('.')
module = ".".join(parts[:-1])
m = __import__(module)
for comp in parts[1:]:
m = getattr(m, comp)
return m
|
python
|
{
"resource": ""
}
|
q1623
|
get_jclass
|
train
|
def get_jclass(classname):
"""
Returns the Java class object associated with the dot-notation classname.
:param classname: the classname
:type classname: str
:return: the class object
:rtype: JB_Object
"""
try:
return javabridge.class_for_name(classname)
except:
return javabridge.static_call(
"Lweka/core/ClassHelper;", "forName",
"(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Class;",
javabridge.class_for_name("java.lang.Object"), classname)
|
python
|
{
"resource": ""
}
|
q1624
|
get_static_field
|
train
|
def get_static_field(classname, fieldname, signature):
"""
Returns the Java object associated with the static field of the specified class.
:param classname: the classname of the class to get the field from
:type classname: str
:param fieldname: the name of the field to retriev
:type fieldname: str
:return: the object
:rtype: JB_Object
"""
try:
return javabridge.get_static_field(classname, fieldname, signature)
except:
return javabridge.static_call(
"Lweka/core/ClassHelper;", "getStaticField",
"(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;",
classname, fieldname)
|
python
|
{
"resource": ""
}
|
q1625
|
get_classname
|
train
|
def get_classname(obj):
"""
Returns the classname of the JB_Object, Python class or object.
:param obj: the java object or Python class/object to get the classname for
:type obj: object
:return: the classname
:rtype: str
"""
if isinstance(obj, javabridge.JB_Object):
cls = javabridge.call(obj, "getClass", "()Ljava/lang/Class;")
return javabridge.call(cls, "getName", "()Ljava/lang/String;")
elif inspect.isclass(obj):
return obj.__module__ + "." + obj.__name__
else:
return get_classname(obj.__class__)
|
python
|
{
"resource": ""
}
|
q1626
|
is_instance_of
|
train
|
def is_instance_of(obj, class_or_intf_name):
"""
Checks whether the Java object implements the specified interface or is a subclass of the superclass.
:param obj: the Java object to check
:type obj: JB_Object
:param class_or_intf_name: the superclass or interface to check, dot notation or with forward slashes
:type class_or_intf_name: str
:return: true if either implements interface or subclass of superclass
:rtype: bool
"""
class_or_intf_name = class_or_intf_name.replace("/", ".")
classname = get_classname(obj)
# array? retrieve component type and check that
if is_array(obj):
jarray = JavaArray(jobject=obj)
classname = jarray.component_type()
result = javabridge.static_call(
"Lweka/core/InheritanceUtils;", "isSubclass",
"(Ljava/lang/String;Ljava/lang/String;)Z",
class_or_intf_name, classname)
if result:
return True
return javabridge.static_call(
"Lweka/core/InheritanceUtils;", "hasInterface",
"(Ljava/lang/String;Ljava/lang/String;)Z",
class_or_intf_name, classname)
|
python
|
{
"resource": ""
}
|
q1627
|
from_commandline
|
train
|
def from_commandline(cmdline, classname=None):
"""
Creates an OptionHandler based on the provided commandline string.
:param cmdline: the commandline string to use
:type cmdline: str
:param classname: the classname of the wrapper to return other than OptionHandler (in dot-notation)
:type classname: str
:return: the generated option handler instance
:rtype: object
"""
params = split_options(cmdline)
cls = params[0]
params = params[1:]
handler = OptionHandler(javabridge.static_call(
"Lweka/core/Utils;", "forName",
"(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/String;)Ljava/lang/Object;",
javabridge.class_for_name("java.lang.Object"), cls, params))
if classname is None:
return handler
else:
c = get_class(classname)
return c(jobject=handler.jobject)
|
python
|
{
"resource": ""
}
|
q1628
|
complete_classname
|
train
|
def complete_classname(classname):
"""
Attempts to complete a partial classname like '.J48' and returns the full
classname if a single match was found, otherwise an exception is raised.
:param classname: the partial classname to expand
:type classname: str
:return: the full classname
:rtype: str
"""
result = javabridge.get_collection_wrapper(
javabridge.static_call(
"Lweka/Run;", "findSchemeMatch",
"(Ljava/lang/String;Z)Ljava/util/List;",
classname, True))
if len(result) == 1:
return str(result[0])
elif len(result) == 0:
raise Exception("No classname matches found for: " + classname)
else:
matches = []
for i in range(len(result)):
matches.append(str(result[i]))
raise Exception("Found multiple matches for '" + classname + "':\n" + '\n'.join(matches))
|
python
|
{
"resource": ""
}
|
q1629
|
JSONObject.to_json
|
train
|
def to_json(self):
"""
Returns the options as JSON.
:return: the object as string
:rtype: str
"""
return json.dumps(self.to_dict(), sort_keys=True, indent=2, separators=(',', ': '))
|
python
|
{
"resource": ""
}
|
q1630
|
JSONObject.from_json
|
train
|
def from_json(cls, s):
"""
Restores the object from the given JSON.
:param s: the JSON string to parse
:type s: str
:return: the
"""
d = json.loads(s)
return get_dict_handler(d["type"])(d)
|
python
|
{
"resource": ""
}
|
q1631
|
Configurable.from_dict
|
train
|
def from_dict(cls, d):
"""
Restores its state from a dictionary, used in de-JSONification.
:param d: the object dictionary
:type d: dict
"""
conf = {}
for k in d["config"]:
v = d["config"][k]
if isinstance(v, dict):
conf[str(k)] = get_dict_handler(d["config"]["type"])(v)
else:
conf[str(k)] = v
return get_class(str(d["class"]))(config=conf)
|
python
|
{
"resource": ""
}
|
q1632
|
Configurable.logger
|
train
|
def logger(self):
"""
Returns the logger object.
:return: the logger
:rtype: logger
"""
if self._logger is None:
self._logger = self.new_logger()
return self._logger
|
python
|
{
"resource": ""
}
|
q1633
|
Configurable.generate_help
|
train
|
def generate_help(self):
"""
Generates a help string for this actor.
:return: the help string
:rtype: str
"""
result = []
result.append(self.__class__.__name__)
result.append(re.sub(r'.', '=', self.__class__.__name__))
result.append("")
result.append("DESCRIPTION")
result.append(self.description())
result.append("")
result.append("OPTIONS")
opts = sorted(self.config.keys())
for opt in opts:
result.append(opt)
helpstr = self.help[opt]
if helpstr is None:
helpstr = "-missing help-"
result.append("\t" + helpstr)
result.append("")
return '\n'.join(result)
|
python
|
{
"resource": ""
}
|
q1634
|
JavaObject.classname
|
train
|
def classname(self):
"""
Returns the Java classname in dot-notation.
:return: the Java classname
:rtype: str
"""
cls = javabridge.call(self.jobject, "getClass", "()Ljava/lang/Class;")
return javabridge.call(cls, "getName", "()Ljava/lang/String;")
|
python
|
{
"resource": ""
}
|
q1635
|
JavaObject.enforce_type
|
train
|
def enforce_type(cls, jobject, intf_or_class):
"""
Raises an exception if the object does not implement the specified interface or is not a subclass.
:param jobject: the Java object to check
:type jobject: JB_Object
:param intf_or_class: the classname in Java notation (eg "weka.core.DenseInstance")
:type intf_or_class: str
"""
if not cls.check_type(jobject, intf_or_class):
raise TypeError("Object does not implement or subclass " + intf_or_class + ": " + get_classname(jobject))
|
python
|
{
"resource": ""
}
|
q1636
|
JavaObject.new_instance
|
train
|
def new_instance(cls, classname):
"""
Creates a new object from the given classname using the default constructor, None in case of error.
:param classname: the classname in Java notation (eg "weka.core.DenseInstance")
:type classname: str
:return: the Java object
:rtype: JB_Object
"""
try:
return javabridge.static_call(
"Lweka/core/Utils;", "forName",
"(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/String;)Ljava/lang/Object;",
javabridge.class_for_name("java.lang.Object"), classname, [])
except JavaException as e:
print("Failed to instantiate " + classname + ": " + str(e))
return None
|
python
|
{
"resource": ""
}
|
q1637
|
Environment.add_variable
|
train
|
def add_variable(self, key, value, system_wide=False):
"""
Adds the environment variable.
:param key: the name of the variable
:type key: str
:param value: the value
:type value: str
:param system_wide: whether to add the variable system wide
:type system_wide: bool
"""
if system_wide:
javabridge.call(self.jobject, "addVariableSystemWide", "(Ljava/lang/String;Ljava/lang/String;)V", key, value)
else:
javabridge.call(self.jobject, "addVariable", "(Ljava/lang/String;Ljava/lang/String;)V", key, value)
|
python
|
{
"resource": ""
}
|
q1638
|
Environment.variable_names
|
train
|
def variable_names(self):
"""
Returns the names of all environment variables.
:return: the names of the variables
:rtype: list
"""
result = []
names = javabridge.call(self.jobject, "getVariableNames", "()Ljava/util/Set;")
for name in javabridge.iterate_collection(names):
result.append(javabridge.to_string(name))
return result
|
python
|
{
"resource": ""
}
|
q1639
|
JavaArray.component_type
|
train
|
def component_type(self):
"""
Returns the classname of the elements.
:return: the class of the elements
:rtype: str
"""
cls = javabridge.call(self.jobject, "getClass", "()Ljava/lang/Class;")
comptype = javabridge.call(cls, "getComponentType", "()Ljava/lang/Class;")
return javabridge.call(comptype, "getName", "()Ljava/lang/String;")
|
python
|
{
"resource": ""
}
|
q1640
|
JavaArray.new_instance
|
train
|
def new_instance(cls, classname, length):
"""
Creates a new array with the given classname and length; initial values are null.
:param classname: the classname in Java notation (eg "weka.core.DenseInstance")
:type classname: str
:param length: the length of the array
:type length: int
:return: the Java array
:rtype: JB_Object
"""
return javabridge.static_call(
"Ljava/lang/reflect/Array;",
"newInstance",
"(Ljava/lang/Class;I)Ljava/lang/Object;",
get_jclass(classname=classname), length)
|
python
|
{
"resource": ""
}
|
q1641
|
Enum.values
|
train
|
def values(self):
"""
Returns list of all enum members.
:return: all enum members
:rtype: list
"""
cls = javabridge.call(self.jobject, "getClass", "()Ljava/lang/Class;")
clsname = javabridge.call(cls, "getName", "()Ljava/lang/String;")
l = javabridge.static_call(clsname.replace(".", "/"), "values", "()[L" + clsname.replace(".", "/") + ";")
l = javabridge.get_env().get_object_array_elements(l)
result = []
for item in l:
result.append(Enum(jobject=item))
return result
|
python
|
{
"resource": ""
}
|
q1642
|
Random.next_int
|
train
|
def next_int(self, n=None):
"""
Next random integer. if n is provided, then between 0 and n-1.
:param n: the upper limit (minus 1) for the random integer
:type n: int
:return: the next random integer
:rtype: int
"""
if n is None:
return javabridge.call(self.jobject, "nextInt", "()I")
else:
return javabridge.call(self.jobject, "nextInt", "(I)I", n)
|
python
|
{
"resource": ""
}
|
q1643
|
OptionHandler.to_help
|
train
|
def to_help(self):
"""
Returns a string that contains the 'global_info' text and the options.
:return: the generated help string
:rtype: str
"""
result = []
result.append(self.classname)
result.append("=" * len(self.classname))
result.append("")
result.append("DESCRIPTION")
result.append("")
result.append(self.global_info())
result.append("")
result.append("OPTIONS")
result.append("")
options = javabridge.call(self.jobject, "listOptions", "()Ljava/util/Enumeration;")
enum = javabridge.get_enumeration_wrapper(options)
while enum.hasMoreElements():
opt = Option(enum.nextElement())
result.append(opt.synopsis)
result.append(opt.description)
result.append("")
return '\n'.join(result)
|
python
|
{
"resource": ""
}
|
q1644
|
Tags.find
|
train
|
def find(self, name):
"""
Returns the Tag that matches the name.
:param name: the string representation of the tag
:type name: str
:return: the tag, None if not found
:rtype: Tag
"""
result = None
for t in self.array:
if str(t) == name:
result = Tag(t.jobject)
break
return result
|
python
|
{
"resource": ""
}
|
q1645
|
Tags.get_object_tags
|
train
|
def get_object_tags(cls, javaobject, methodname):
"""
Instantiates the Tag array obtained from the object using the specified method name.
Example:
cls = Classifier(classname="weka.classifiers.meta.MultiSearch")
tags = Tags.get_object_tags(cls, "getMetricsTags")
:param javaobject: the javaobject to obtain the tags from
:type javaobject: JavaObject
:param methodname: the method name returning the Tag array
:type methodname: str
:return: the Tags objects
:rtype: Tags
"""
return Tags(jobject=javabridge.call(javaobject.jobject, methodname, "()[Lweka/core/Tag;"))
|
python
|
{
"resource": ""
}
|
q1646
|
SelectedTag.tags
|
train
|
def tags(self):
"""
Returns the associated tags.
:return: the list of Tag objects
:rtype: list
"""
result = []
a = javabridge.call(self.jobject, "getTags", "()Lweka/core/Tag;]")
length = javabridge.get_env().get_array_length(a)
wrapped = javabridge.get_env().get_object_array_elements(a)
for i in range(length):
result.append(Tag(javabridge.get_env().get_string(wrapped[i])))
return result
|
python
|
{
"resource": ""
}
|
q1647
|
SetupGenerator.base_object
|
train
|
def base_object(self):
"""
Returns the base object to apply the setups to.
:return: the base object
:rtype: JavaObject or OptionHandler
"""
jobj = javabridge.call(self.jobject, "getBaseObject", "()Ljava/io/Serializable;")
if OptionHandler.check_type(jobj, "weka.core.OptionHandler"):
return OptionHandler(jobj)
else:
return JavaObject(jobj)
|
python
|
{
"resource": ""
}
|
q1648
|
SetupGenerator.base_object
|
train
|
def base_object(self, obj):
"""
Sets the base object to apply the setups to.
:param obj: the object to use (must be serializable!)
:type obj: JavaObject
"""
if not obj.is_serializable:
raise Exception("Base object must be serializable: " + obj.classname)
javabridge.call(self.jobject, "setBaseObject", "(Ljava/io/Serializable;)V", obj.jobject)
|
python
|
{
"resource": ""
}
|
q1649
|
SetupGenerator.parameters
|
train
|
def parameters(self):
"""
Returns the list of currently set search parameters.
:return: the list of AbstractSearchParameter objects
:rtype: list
"""
array = JavaArray(javabridge.call(self.jobject, "getParameters", "()[Lweka/core/setupgenerator/AbstractParameter;"))
result = []
for item in array:
result.append(AbstractParameter(jobject=item.jobject))
return result
|
python
|
{
"resource": ""
}
|
q1650
|
SetupGenerator.parameters
|
train
|
def parameters(self, params):
"""
Sets the list of search parameters to use.
:param params: list of AbstractSearchParameter objects
:type params: list
"""
array = JavaArray(jobject=JavaArray.new_instance("weka.core.setupgenerator.AbstractParameter", len(params)))
for idx, obj in enumerate(params):
array[idx] = obj.jobject
javabridge.call(self.jobject, "setParameters", "([Lweka/core/setupgenerator/AbstractParameter;)V", array.jobject)
|
python
|
{
"resource": ""
}
|
q1651
|
SetupGenerator.setups
|
train
|
def setups(self):
"""
Generates and returns all the setups according to the parameter search space.
:return: the list of configured objects (of type JavaObject)
:rtype: list
"""
result = []
has_options = self.base_object.is_optionhandler
enm = javabridge.get_enumeration_wrapper(javabridge.call(self.jobject, "setups", "()Ljava/util/Enumeration;"))
while enm.hasMoreElements():
if has_options:
result.append(OptionHandler(enm.nextElement()))
else:
result.append(JavaObject(enm.nextElement()))
return result
|
python
|
{
"resource": ""
}
|
q1652
|
Actor.unique_name
|
train
|
def unique_name(self, name):
"""
Generates a unique name.
:param name: the name to check
:type name: str
:return: the unique name
:rtype: str
"""
result = name
if self.parent is not None:
index = self.index
bname = re.sub(r'-[0-9]+$', '', name)
names = []
for idx, actor in enumerate(self.parent.actors):
if idx != index:
names.append(actor.name)
result = bname
count = 0
while result in names:
count += 1
result = bname + "-" + str(count)
return result
|
python
|
{
"resource": ""
}
|
q1653
|
Actor.parent
|
train
|
def parent(self, parent):
"""
Sets the parent of the actor.
:param parent: the parent
:type parent: Actor
"""
self._name = self.unique_name(self._name)
self._full_name = None
self._logger = None
self._parent = parent
|
python
|
{
"resource": ""
}
|
q1654
|
Actor.full_name
|
train
|
def full_name(self):
"""
Obtains the full name of the actor.
:return: the full name
:rtype: str
"""
if self._full_name is None:
fn = self.name.replace(".", "\\.")
parent = self._parent
if parent is not None:
fn = parent.full_name + "." + fn
self._full_name = fn
return self._full_name
|
python
|
{
"resource": ""
}
|
q1655
|
Actor.storagehandler
|
train
|
def storagehandler(self):
"""
Returns the storage handler available to thise actor.
:return: the storage handler, None if not available
"""
if isinstance(self, StorageHandler):
return self
elif self.parent is not None:
return self.parent.storagehandler
else:
return None
|
python
|
{
"resource": ""
}
|
q1656
|
Actor.execute
|
train
|
def execute(self):
"""
Executes the actor.
:return: None if successful, otherwise error message
:rtype: str
"""
if self.skip:
return None
result = self.pre_execute()
if result is None:
try:
result = self.do_execute()
except Exception as e:
result = traceback.format_exc()
print(self.full_name + "\n" + result)
if result is None:
result = self.post_execute()
return result
|
python
|
{
"resource": ""
}
|
q1657
|
ActorHandler.actors
|
train
|
def actors(self, actors):
"""
Sets the sub-actors of the actor.
:param actors: the sub-actors
:type actors: list
"""
if actors is None:
actors = self.default_actors()
self.check_actors(actors)
self.config["actors"] = actors
|
python
|
{
"resource": ""
}
|
q1658
|
ActorHandler.active
|
train
|
def active(self):
"""
Returns the count of non-skipped actors.
:return: the count
:rtype: int
"""
result = 0
for actor in self.actors:
if not actor.skip:
result += 1
return result
|
python
|
{
"resource": ""
}
|
q1659
|
ActorHandler.first_active
|
train
|
def first_active(self):
"""
Returns the first non-skipped actor.
:return: the first active actor, None if not available
:rtype: Actor
"""
result = None
for actor in self.actors:
if not actor.skip:
result = actor
break
return result
|
python
|
{
"resource": ""
}
|
q1660
|
ActorHandler.last_active
|
train
|
def last_active(self):
"""
Returns the last non-skipped actor.
:return: the last active actor, None if not available
:rtype: Actor
"""
result = None
for actor in reversed(self.actors):
if not actor.skip:
result = actor
break
return result
|
python
|
{
"resource": ""
}
|
q1661
|
ActorHandler.index_of
|
train
|
def index_of(self, name):
"""
Returns the index of the actor with the given name.
:param name: the name of the Actor to find
:type name: str
:return: the index, -1 if not found
:rtype: int
"""
result = -1
for index, actor in enumerate(self.actors):
if actor.name == name:
result = index
break
return result
|
python
|
{
"resource": ""
}
|
q1662
|
ActorHandler.setup
|
train
|
def setup(self):
"""
Configures the actor before execution.
:return: None if successful, otherwise error message
:rtype: str
"""
result = super(ActorHandler, self).setup()
if result is None:
self.update_parent()
try:
self.check_actors(self.actors)
except Exception as e:
result = str(e)
if result is None:
for actor in self.actors:
name = actor.name
newname = actor.unique_name(actor.name)
if name != newname:
actor.name = newname
if result is None:
for actor in self.actors:
if actor.skip:
continue
result = actor.setup()
if result is not None:
break
if result is None:
result = self._director.setup()
return result
|
python
|
{
"resource": ""
}
|
q1663
|
ActorHandler.cleanup
|
train
|
def cleanup(self):
"""
Destructive finishing up after execution stopped.
"""
for actor in self.actors:
if actor.skip:
continue
actor.cleanup()
super(ActorHandler, self).cleanup()
|
python
|
{
"resource": ""
}
|
q1664
|
Flow.load
|
train
|
def load(cls, fname):
"""
Loads the flow from a JSON file.
:param fname: the file to load
:type fname: str
:return: the flow
:rtype: Flow
"""
with open(fname) as f:
content = f.readlines()
return Flow.from_json(''.join(content))
|
python
|
{
"resource": ""
}
|
q1665
|
Sequence.new_director
|
train
|
def new_director(self):
"""
Creates the director to use for handling the sub-actors.
:return: the director instance
:rtype: Director
"""
result = SequentialDirector(self)
result.record_output = False
result.allow_source = False
return result
|
python
|
{
"resource": ""
}
|
q1666
|
CommandlineToAny.check_input
|
train
|
def check_input(self, obj):
"""
Performs checks on the input object. Raises an exception if unsupported.
:param obj: the object to check
:type obj: object
"""
if isinstance(obj, str):
return
if isinstance(obj, unicode):
return
raise Exception("Unsupported class: " + self._input.__class__.__name__)
|
python
|
{
"resource": ""
}
|
q1667
|
CommandlineToAny.convert
|
train
|
def convert(self):
"""
Performs the actual conversion.
:return: None if successful, otherwise errors message
:rtype: str
"""
cname = str(self.config["wrapper"])
self._output = classes.from_commandline(self._input, classname=cname)
return None
|
python
|
{
"resource": ""
}
|
q1668
|
plot_experiment
|
train
|
def plot_experiment(mat, title="Experiment", axes_swapped=False, measure="Statistic", show_stdev=False,
key_loc="lower right", outfile=None, wait=True):
"""
Plots the results from an experiment.
:param mat: the result matrix to plot
:type mat: ResultMatrix
:param title: the title for the experiment
:type title: str
:param axes_swapped: whether the axes whether swapped ("sets x cls" or "cls x sets")
:type axes_swapped: bool
:param measure: the measure that is being displayed
:type measure: str
:param show_stdev: whether to show the standard deviation as error bar
:type show_stdev: bool
:param key_loc: the location string for the key
:type key_loc: str
:param outfile: the output file, ignored if None
:type outfile: str
:param wait: whether to wait for the user to close the plot
:type wait: bool
"""
if not plot.matplotlib_available:
logger.error("Matplotlib is not installed, plotting unavailable!")
return
if not isinstance(mat, ResultMatrix):
logger.error("Need to supply a result matrix!")
return
fig, ax = plt.subplots()
if axes_swapped:
ax.set_xlabel(measure)
ax.set_ylabel("Classifiers")
else:
ax.set_xlabel("Classifiers")
ax.set_ylabel(measure)
ax.set_title(title)
fig.canvas.set_window_title(title)
ax.grid(True)
ticksx = []
ticks = []
inc = 1.0 / float(mat.columns)
for i in range(mat.columns):
ticksx.append((i + 0.5) * inc)
ticks.append("[" + str(i+1) + "]")
plt.xticks(ticksx, ticks)
plt.xlim([0.0, 1.0])
for r in range(mat.rows):
x = []
means = []
stdevs = []
for c in range(mat.columns):
mean = mat.get_mean(c, r)
stdev = mat.get_stdev(c, r)
if not math.isnan(mean):
x.append((c + 0.5) * inc)
means.append(mean)
if not math.isnan(stdev):
stdevs.append(stdev)
plot_label = mat.get_row_name(r)
if show_stdev:
ax.errorbar(x, means, yerr=stdevs, fmt='-o', ls="-", label=plot_label)
else:
ax.plot(x, means, "o-", label=plot_label)
plt.draw()
plt.legend(loc=key_loc, shadow=True)
if outfile is not None:
plt.savefig(outfile)
if wait:
plt.show()
|
python
|
{
"resource": ""
}
|
q1669
|
predictions_to_instances
|
train
|
def predictions_to_instances(data, preds):
"""
Turns the predictions turned into an Instances object.
:param data: the original dataset format
:type data: Instances
:param preds: the predictions to convert
:type preds: list
:return: the predictions, None if no predictions present
:rtype: Instances
"""
if len(preds) == 0:
return None
is_numeric = isinstance(preds[0], NumericPrediction)
# create header
atts = []
if is_numeric:
atts.append(Attribute.create_numeric("index"))
atts.append(Attribute.create_numeric("weight"))
atts.append(Attribute.create_numeric("actual"))
atts.append(Attribute.create_numeric("predicted"))
atts.append(Attribute.create_numeric("error"))
else:
atts.append(Attribute.create_numeric("index"))
atts.append(Attribute.create_numeric("weight"))
atts.append(data.class_attribute.copy(name="actual"))
atts.append(data.class_attribute.copy(name="predicted"))
atts.append(Attribute.create_nominal("error", ["no", "yes"]))
atts.append(Attribute.create_numeric("classification"))
for i in range(data.class_attribute.num_values):
atts.append(Attribute.create_numeric("distribution-" + data.class_attribute.value(i)))
result = Instances.create_instances("Predictions", atts, len(preds))
count = 0
for pred in preds:
count += 1
if is_numeric:
values = array([count, pred.weight, pred.actual, pred.predicted, pred.error])
else:
if pred.actual == pred.predicted:
error = 0.0
else:
error = 1.0
l = [count, pred.weight, pred.actual, pred.predicted, error, max(pred.distribution)]
for i in range(data.class_attribute.num_values):
l.append(pred.distribution[i])
values = array(l)
inst = Instance.create_instance(values)
result.add_instance(inst)
return result
|
python
|
{
"resource": ""
}
|
q1670
|
Classifier.batch_size
|
train
|
def batch_size(self, size):
"""
Sets the batch size, in case this classifier is a batch predictor.
:param size: the size of the batch
:type size: str
"""
if self.is_batchpredictor:
javabridge.call(self.jobject, "setBatchSize", "(Ljava/lang/String;)V", size)
|
python
|
{
"resource": ""
}
|
q1671
|
Classifier.to_source
|
train
|
def to_source(self, classname):
"""
Returns the model as Java source code if the classifier implements weka.classifiers.Sourcable.
:param classname: the classname for the generated Java code
:type classname: str
:return: the model as source code string
:rtype: str
"""
if not self.check_type(self.jobject, "weka.classifiers.Sourcable"):
return None
return javabridge.call(self.jobject, "toSource", "(Ljava/lang/String;)Ljava/lang/String;", classname)
|
python
|
{
"resource": ""
}
|
q1672
|
GridSearch.evaluation
|
train
|
def evaluation(self, evl):
"""
Sets the statistic to use for evaluation.
:param evl: the statistic
:type evl: SelectedTag, Tag or str
"""
if isinstance(evl, str):
evl = self.tags_evaluation.find(evl)
if isinstance(evl, Tag):
evl = SelectedTag(tag_id=evl.ident, tags=self.tags_evaluation)
javabridge.call(self.jobject, "setEvaluation", "(Lweka/core/SelectedTag;)V", evl.jobject)
|
python
|
{
"resource": ""
}
|
q1673
|
MultipleClassifiersCombiner.classifiers
|
train
|
def classifiers(self):
"""
Returns the list of base classifiers.
:return: the classifier list
:rtype: list
"""
objects = javabridge.get_env().get_object_array_elements(
javabridge.call(self.jobject, "getClassifiers", "()[Lweka/classifiers/Classifier;"))
result = []
for obj in objects:
result.append(Classifier(jobject=obj))
return result
|
python
|
{
"resource": ""
}
|
q1674
|
MultipleClassifiersCombiner.classifiers
|
train
|
def classifiers(self, classifiers):
"""
Sets the base classifiers.
:param classifiers: the list of base classifiers to use
:type classifiers: list
"""
obj = []
for classifier in classifiers:
obj.append(classifier.jobject)
javabridge.call(self.jobject, "setClassifiers", "([Lweka/classifiers/Classifier;)V", obj)
|
python
|
{
"resource": ""
}
|
q1675
|
Kernel.eval
|
train
|
def eval(self, id1, id2, inst1):
"""
Computes the result of the kernel function for two instances. If id1 == -1, eval use inst1 instead of an
instance in the dataset.
:param id1: the index of the first instance in the dataset
:type id1: int
:param id2: the index of the second instance in the dataset
:type id2: int
:param inst1: the instance corresponding to id1 (used if id1 == -1)
:type inst1: Instance
"""
jinst1 = None
if inst1 is not None:
jinst1 = inst1.jobject
return javabridge.call(self.jobject, "eval", "(IILweka/core/Instance;)D", id1, id2, jinst1)
|
python
|
{
"resource": ""
}
|
q1676
|
KernelClassifier.kernel
|
train
|
def kernel(self):
"""
Returns the current kernel.
:return: the kernel or None if none found
:rtype: Kernel
"""
result = javabridge.static_call(
"weka/classifiers/KernelHelper", "getKernel",
"(Ljava/lang/Object;)Lweka/classifiers/functions/supportVector/Kernel;",
self.jobject)
if result is None:
return None
else:
return Kernel(jobject=result)
|
python
|
{
"resource": ""
}
|
q1677
|
KernelClassifier.kernel
|
train
|
def kernel(self, kernel):
"""
Sets the kernel.
:param kernel: the kernel to set
:type kernel: Kernel
"""
result = javabridge.static_call(
"weka/classifiers/KernelHelper", "setKernel",
"(Ljava/lang/Object;Lweka/classifiers/functions/supportVector/Kernel;)Z",
self.jobject, kernel.jobject)
if not result:
raise Exception("Failed to set kernel!")
|
python
|
{
"resource": ""
}
|
q1678
|
CostMatrix.apply_cost_matrix
|
train
|
def apply_cost_matrix(self, data, rnd):
"""
Applies the cost matrix to the data.
:param data: the data to apply to
:type data: Instances
:param rnd: the random number generator
:type rnd: Random
"""
return Instances(
javabridge.call(
self.jobject, "applyCostMatrix", "(Lweka/core/Instances;Ljava/util/Random;)Lweka/core/Instances;",
data.jobject, rnd.jobject))
|
python
|
{
"resource": ""
}
|
q1679
|
CostMatrix.expected_costs
|
train
|
def expected_costs(self, class_probs, inst=None):
"""
Calculates the expected misclassification cost for each possible class value, given class probability
estimates.
:param class_probs: the class probabilities
:type class_probs: ndarray
:return: the calculated costs
:rtype: ndarray
"""
if inst is None:
costs = javabridge.call(
self.jobject, "expectedCosts", "([D)[D", javabridge.get_env().make_double_array(class_probs))
return javabridge.get_env().get_double_array_elements(costs)
else:
costs = javabridge.call(
self.jobject, "expectedCosts", "([DLweka/core/Instance;)[D",
javabridge.get_env().make_double_array(class_probs), inst.jobject)
return javabridge.get_env().get_double_array_elements(costs)
|
python
|
{
"resource": ""
}
|
q1680
|
CostMatrix.get_cell
|
train
|
def get_cell(self, row, col):
"""
Returns the JB_Object at the specified location.
:param row: the 0-based index of the row
:type row: int
:param col: the 0-based index of the column
:type col: int
:return: the object in that cell
:rtype: JB_Object
"""
return javabridge.call(
self.jobject, "getCell", "(II)Ljava/lang/Object;", row, col)
|
python
|
{
"resource": ""
}
|
q1681
|
CostMatrix.set_cell
|
train
|
def set_cell(self, row, col, obj):
"""
Sets the JB_Object at the specified location. Automatically unwraps JavaObject.
:param row: the 0-based index of the row
:type row: int
:param col: the 0-based index of the column
:type col: int
:param obj: the object for that cell
:type obj: object
"""
if isinstance(obj, JavaObject):
obj = obj.jobject
javabridge.call(
self.jobject, "setCell", "(IILjava/lang/Object;)V", row, col, obj)
|
python
|
{
"resource": ""
}
|
q1682
|
CostMatrix.get_element
|
train
|
def get_element(self, row, col, inst=None):
"""
Returns the value at the specified location.
:param row: the 0-based index of the row
:type row: int
:param col: the 0-based index of the column
:type col: int
:param inst: the Instace
:type inst: Instance
:return: the value in that cell
:rtype: float
"""
if inst is None:
return javabridge.call(
self.jobject, "getElement", "(II)D", row, col)
else:
return javabridge.call(
self.jobject, "getElement", "(IILweka/core/Instance;)D", row, col, inst.jobject)
|
python
|
{
"resource": ""
}
|
q1683
|
CostMatrix.set_element
|
train
|
def set_element(self, row, col, value):
"""
Sets the float value at the specified location.
:param row: the 0-based index of the row
:type row: int
:param col: the 0-based index of the column
:type col: int
:param value: the float value for that cell
:type value: float
"""
javabridge.call(
self.jobject, "setElement", "(IID)V", row, col, value)
|
python
|
{
"resource": ""
}
|
q1684
|
CostMatrix.get_max_cost
|
train
|
def get_max_cost(self, class_value, inst=None):
"""
Gets the maximum cost for a particular class value.
:param class_value: the class value to get the maximum cost for
:type class_value: int
:param inst: the Instance
:type inst: Instance
:return: the cost
:rtype: float
"""
if inst is None:
return javabridge.call(
self.jobject, "getMaxCost", "(I)D", class_value)
else:
return javabridge.call(
self.jobject, "getElement", "(ILweka/core/Instance;)D", class_value, inst.jobject)
|
python
|
{
"resource": ""
}
|
q1685
|
Evaluation.crossvalidate_model
|
train
|
def crossvalidate_model(self, classifier, data, num_folds, rnd, output=None):
"""
Crossvalidates the model using the specified data, number of folds and random number generator wrapper.
:param classifier: the classifier to cross-validate
:type classifier: Classifier
:param data: the data to evaluate on
:type data: Instances
:param num_folds: the number of folds
:type num_folds: int
:param rnd: the random number generator to use
:type rnd: Random
:param output: the output generator to use
:type output: PredictionOutput
"""
if output is None:
generator = []
else:
generator = [output.jobject]
javabridge.call(
self.jobject, "crossValidateModel",
"(Lweka/classifiers/Classifier;Lweka/core/Instances;ILjava/util/Random;[Ljava/lang/Object;)V",
classifier.jobject, data.jobject, num_folds, rnd.jobject, generator)
|
python
|
{
"resource": ""
}
|
q1686
|
Evaluation.summary
|
train
|
def summary(self, title=None, complexity=False):
"""
Generates a summary.
:param title: optional title
:type title: str
:param complexity: whether to print the complexity information as well
:type complexity: bool
:return: the summary
:rtype: str
"""
if title is None:
return javabridge.call(
self.jobject, "toSummaryString", "()Ljava/lang/String;")
else:
return javabridge.call(
self.jobject, "toSummaryString", "(Ljava/lang/String;Z)Ljava/lang/String;", title, complexity)
|
python
|
{
"resource": ""
}
|
q1687
|
Evaluation.class_details
|
train
|
def class_details(self, title=None):
"""
Generates the class details.
:param title: optional title
:type title: str
:return: the details
:rtype: str
"""
if title is None:
return javabridge.call(
self.jobject, "toClassDetailsString", "()Ljava/lang/String;")
else:
return javabridge.call(
self.jobject, "toClassDetailsString", "(Ljava/lang/String;)Ljava/lang/String;", title)
|
python
|
{
"resource": ""
}
|
q1688
|
Evaluation.matrix
|
train
|
def matrix(self, title=None):
"""
Generates the confusion matrix.
:param title: optional title
:type title: str
:return: the matrix
:rtype: str
"""
if title is None:
return javabridge.call(self.jobject, "toMatrixString", "()Ljava/lang/String;")
else:
return javabridge.call(self.jobject, "toMatrixString", "(Ljava/lang/String;)Ljava/lang/String;", title)
|
python
|
{
"resource": ""
}
|
q1689
|
Evaluation.predictions
|
train
|
def predictions(self):
"""
Returns the predictions.
:return: the predictions. None if not available
:rtype: list
"""
preds = javabridge.get_collection_wrapper(
javabridge.call(self.jobject, "predictions", "()Ljava/util/ArrayList;"))
if self.discard_predictions:
result = None
else:
result = []
for pred in preds:
if is_instance_of(pred, "weka.classifiers.evaluation.NominalPrediction"):
result.append(NominalPrediction(pred))
elif is_instance_of(pred, "weka.classifiers.evaluation.NumericPrediction"):
result.append(NumericPrediction(pred))
else:
result.append(Prediction(pred))
return result
|
python
|
{
"resource": ""
}
|
q1690
|
PredictionOutput.print_all
|
train
|
def print_all(self, cls, data):
"""
Prints the header, classifications and footer to the buffer.
:param cls: the classifier
:type cls: Classifier
:param data: the test data
:type data: Instances
"""
javabridge.call(
self.jobject, "print", "(Lweka/classifiers/Classifier;Lweka/core/Instances;)V",
cls.jobject, data.jobject)
|
python
|
{
"resource": ""
}
|
q1691
|
PredictionOutput.print_classifications
|
train
|
def print_classifications(self, cls, data):
"""
Prints the classifications to the buffer.
:param cls: the classifier
:type cls: Classifier
:param data: the test data
:type data: Instances
"""
javabridge.call(
self.jobject, "printClassifications", "(Lweka/classifiers/Classifier;Lweka/core/Instances;)V",
cls.jobject, data.jobject)
|
python
|
{
"resource": ""
}
|
q1692
|
PredictionOutput.print_classification
|
train
|
def print_classification(self, cls, inst, index):
"""
Prints the classification to the buffer.
:param cls: the classifier
:type cls: Classifier
:param inst: the test instance
:type inst: Instance
:param index: the 0-based index of the test instance
:type index: int
"""
javabridge.call(
self.jobject, "printClassification", "(Lweka/classifiers/Classifier;Lweka/core/Instance;I)V",
cls.jobject, inst.jobject, index)
|
python
|
{
"resource": ""
}
|
q1693
|
Tokenizer.tokenize
|
train
|
def tokenize(self, s):
"""
Tokenizes the string.
:param s: the string to tokenize
:type s: str
:return: the iterator
:rtype: TokenIterator
"""
javabridge.call(self.jobject, "tokenize", "(Ljava/lang/String;)V", s)
return TokenIterator(self)
|
python
|
{
"resource": ""
}
|
q1694
|
DataGenerator.define_data_format
|
train
|
def define_data_format(self):
"""
Returns the data format.
:return: the data format
:rtype: Instances
"""
data = javabridge.call(self.jobject, "defineDataFormat", "()Lweka/core/Instances;")
if data is None:
return None
else:
return Instances(data)
|
python
|
{
"resource": ""
}
|
q1695
|
DataGenerator.dataset_format
|
train
|
def dataset_format(self):
"""
Returns the dataset format.
:return: the format
:rtype: Instances
"""
data = javabridge.call(self.jobject, "getDatasetFormat", "()Lweka/core/Instances;")
if data is None:
return None
else:
return Instances(data)
|
python
|
{
"resource": ""
}
|
q1696
|
DataGenerator.generate_example
|
train
|
def generate_example(self):
"""
Returns a single Instance.
:return: the next example
:rtype: Instance
"""
data = javabridge.call(self.jobject, "generateExample", "()Lweka/core/Instance;")
if data is None:
return None
else:
return Instance(data)
|
python
|
{
"resource": ""
}
|
q1697
|
DataGenerator.generate_examples
|
train
|
def generate_examples(self):
"""
Returns complete dataset.
:return: the generated dataset
:rtype: Instances
"""
data = javabridge.call(self.jobject, "generateExamples", "()Lweka/core/Instances;")
if data is None:
return None
else:
return Instances(data)
|
python
|
{
"resource": ""
}
|
q1698
|
DataGenerator.make_copy
|
train
|
def make_copy(cls, generator):
"""
Creates a copy of the generator.
:param generator: the generator to copy
:type generator: DataGenerator
:return: the copy of the generator
:rtype: DataGenerator
"""
return from_commandline(
to_commandline(generator), classname=classes.get_classname(DataGenerator()))
|
python
|
{
"resource": ""
}
|
q1699
|
DataGenerator.to_config
|
train
|
def to_config(self, k, v):
"""
Hook method that allows conversion of individual options.
:param k: the key of the option
:type k: str
:param v: the value
:type v: object
:return: the potentially processed value
:rtype: object
"""
if k == "setup":
return base.to_commandline(v)
return super(DataGenerator, self).to_config(k, v)
|
python
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.