本文整理汇总了Java中com.rapidminer.example.Tools.onlyNonMissingValues方法的典型用法代码示例。如果您正苦于以下问题:Java Tools.onlyNonMissingValues方法的具体用法?Java Tools.onlyNonMissingValues怎么用?Java Tools.onlyNonMissingValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.rapidminer.example.Tools
的用法示例。
在下文中一共展示了Tools.onlyNonMissingValues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: learn
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public Model learn(ExampleSet exampleSet) throws OperatorException {
Tools.onlyNonMissingValues(exampleSet, getOperatorClassName(), this, new String[0]);
ImprovedNeuralNetModel model = new ImprovedNeuralNetModel(exampleSet);
List<String[]> hiddenLayers = getParameterList(PARAMETER_HIDDEN_LAYERS);
int maxCycles = getParameterAsInt(PARAMETER_TRAINING_CYCLES);
double maxError = getParameterAsDouble(PARAMETER_ERROR_EPSILON);
double learningRate = getParameterAsDouble(PARAMETER_LEARNING_RATE);
double momentum = getParameterAsDouble(PARAMETER_MOMENTUM);
boolean decay = getParameterAsBoolean(PARAMETER_DECAY);
boolean shuffle = getParameterAsBoolean(PARAMETER_SHUFFLE);
boolean normalize = getParameterAsBoolean(PARAMETER_NORMALIZE);
RandomGenerator randomGenerator = RandomGenerator.getRandomGenerator(this);
model.train(exampleSet, hiddenLayers, maxCycles, maxError, learningRate, momentum, decay, shuffle, normalize,
randomGenerator, this);
return model;
}
示例2: generateInternalClusterModel
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
protected ClusterModel generateInternalClusterModel(ExampleSet exampleSet) throws OperatorException {
// get parameters
int k = getParameterAsInt(PARAMETER_K);
// perform checks
Tools.isNonEmpty(exampleSet);
Tools.onlyNonMissingValues(exampleSet, getOperatorClassName(), this, new String[0]);
Tools.checkAndCreateIds(exampleSet);
if (exampleSet.size() < k) {
logWarning("number of clusters (k) = " + k + " > number of objects =" + exampleSet.size());
throw new UserError(this, 142, k);
}
ClusterModel model = createClusterModel(exampleSet);
return model;
}
示例3: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
int maxLeafSize = getParameterAsInt(PARAMETER_MAX_LEAF_SIZE);
// additional checks
Tools.checkAndCreateIds(exampleSet);
Tools.onlyNonMissingValues(exampleSet, getOperatorClassName(), this, new String[0]);
// recursively descend until leaf_size smaller than max_leaf_size
HierarchicalClusterNode root = new HierarchicalClusterNode("root");
HierarchicalClusterModel model = new HierarchicalClusterModel(root);
int createdLeafs = descend(exampleSet, root, 0, maxLeafSize, getParameterAsInt(PARAMETER_MAX_DEPTH) - 1);
if (getParameterAsBoolean(PARAMETER_CREATE_CLUSTER_LABEL) && exampleSetOutput.isConnected()) {
try {
FlattenClusterModel flattener = OperatorService.createOperator(FlattenClusterModel.class);
flattener.setParameter(FlattenClusterModel.PARAMETER_NUMBER_OF_CLUSTER, createdLeafs + "");
ClusterModel flatModel = flattener.flatten(model, exampleSet);
ClusterModel2ExampleSet applier = OperatorService.createOperator(ClusterModel2ExampleSet.class);
ExampleSet labelledExampleSet = applier.addClusterAttribute(exampleSet, flatModel);
exampleSetOutput.deliver(labelledExampleSet);
modelOutput.deliver(model);
} catch (OperatorCreationException e) {
throw new OperatorException("Could not create FlattenClusterModel Operator: " + e, e);
}
} else {
Attribute clusterAttribute = exampleSet.getAttributes().getCluster();
if (clusterAttribute != null) {
exampleSet.getAttributes().remove(clusterAttribute);
}
exampleSetOutput.deliver(exampleSet);
modelOutput.deliver(model);
}
}
示例4: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
int maxLeafSize = getParameterAsInt(PARAMETER_MAX_LEAF_SIZE);
// additional checks
Tools.checkAndCreateIds(exampleSet);
Tools.onlyNonMissingValues(exampleSet, getOperatorClassName(), this, new String[0]);
// recursively descend until leaf_size smaller than max_leaf_size
HierarchicalClusterNode root = new HierarchicalClusterNode("root");
HierarchicalClusterModel model = new HierarchicalClusterModel(root);
int createdLeafs = descend(exampleSet, root, 0, maxLeafSize, getParameterAsInt(PARAMETER_MAX_DEPTH) - 1,
getProgress());
if (getParameterAsBoolean(PARAMETER_CREATE_CLUSTER_LABEL) && exampleSetOutput.isConnected()) {
try {
FlattenClusterModel flattener = OperatorService.createOperator(FlattenClusterModel.class);
flattener.setParameter(FlattenClusterModel.PARAMETER_NUMBER_OF_CLUSTER, createdLeafs + "");
ClusterModel flatModel = flattener.flatten(model, exampleSet);
ClusterModel2ExampleSet applier = OperatorService.createOperator(ClusterModel2ExampleSet.class);
ExampleSet labelledExampleSet = applier.addClusterAttribute(exampleSet, flatModel);
exampleSetOutput.deliver(labelledExampleSet);
modelOutput.deliver(model);
} catch (OperatorCreationException e) {
throw new OperatorException("Could not create FlattenClusterModel Operator: " + e, e);
}
} else {
Attribute clusterAttribute = exampleSet.getAttributes().getCluster();
if (clusterAttribute != null) {
exampleSet.getAttributes().remove(clusterAttribute);
}
exampleSetOutput.deliver(exampleSet);
modelOutput.deliver(model);
}
}
示例5: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
int maxLeafSize = getParameterAsInt(PARAMETER_MAX_LEAF_SIZE);
// additional checks
Tools.checkAndCreateIds(exampleSet);
Tools.onlyNonMissingValues(exampleSet, "AgglomerativeClustering");
// recursively descend until leaf_size smaller than max_leaf_size
HierarchicalClusterNode root = new HierarchicalClusterNode("root");
HierarchicalClusterModel model = new HierarchicalClusterModel(root);
int createdLeafs = descend(exampleSet, root, 0, maxLeafSize, getParameterAsInt(PARAMETER_MAX_DEPTH) - 1);
if (getParameterAsBoolean(PARAMETER_CREATE_CLUSTER_LABEL) && exampleSetOutput.isConnected()) {
try {
FlattenClusterModel flattener = OperatorService.createOperator(FlattenClusterModel.class);
flattener.setParameter(FlattenClusterModel.PARAMETER_NUMBER_OF_CLUSTER, createdLeafs + "");
ClusterModel flatModel = flattener.flatten(model, exampleSet);
ClusterModel2ExampleSet applier = OperatorService.createOperator(ClusterModel2ExampleSet.class);
ExampleSet labelledExampleSet = applier.addClusterAttribute(exampleSet, flatModel);
exampleSetOutput.deliver(labelledExampleSet);
modelOutput.deliver(model);
} catch (OperatorCreationException e) {
throw new OperatorException("Could not create FlattenClusterModel Operator: "+e, e);
}
} else {
Attribute clusterAttribute = exampleSet.getAttributes().getCluster();
if (clusterAttribute != null) {
exampleSet.getAttributes().remove(clusterAttribute);
}
exampleSetOutput.deliver(exampleSet);
modelOutput.deliver(model);
}
}
示例6: apply
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public ExampleSet apply(ExampleSet exampleSet) throws OperatorException {
Tools.onlyNonMissingValues(exampleSet, "Fourier Transform");
// create new example table
int numberOfNewExamples = FastFourierTransform.getGreatestPowerOf2LessThan(exampleSet.size()) / 2;
ExampleTable exampleTable = new MemoryExampleTable(new LinkedList<Attribute>(), new DataRowFactory(DataRowFactory.TYPE_DOUBLE_ARRAY, '.'), numberOfNewExamples);
// create frequency attribute (for frequency)
Attribute frequencyAttribute = AttributeFactory.createAttribute("frequency", Ontology.REAL);
exampleTable.addAttribute(frequencyAttribute);
DataRowReader drr = exampleTable.getDataRowReader();
int k = 0;
while (drr.hasNext()) {
DataRow dataRow = drr.next();
dataRow.set(frequencyAttribute, FastFourierTransform.convertFrequency(k++, numberOfNewExamples, exampleSet.size()));
}
// create FFT values
Attribute label = exampleSet.getAttributes().getLabel();
// add FFT values
FastFourierTransform fft = new FastFourierTransform(WindowFunction.BLACKMAN_HARRIS);
SpectrumFilter filter = new SpectrumFilter(SpectrumFilter.NONE);
for (Attribute current : exampleSet.getAttributes()) {
if (current.isNumerical()) {
Complex[] result = fft.getFourierTransform(exampleSet, label, current);
Peak[] spectrum = filter.filter(result, exampleSet.size());
// create new attribute and fill table with values
Attribute newAttribute = AttributeFactory.createAttribute("fft(" + current.getName() + ")", Ontology.REAL);
exampleTable.addAttribute(newAttribute);
fillTable(exampleTable, newAttribute, spectrum);
}
}
ExampleSet resultSet = new SimpleExampleSet(exampleTable);
return resultSet;
}
示例7: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
DistanceMeasure measure = measureHelper.getInitializedMeasure(exampleSet);
// additional checks
Tools.onlyNonMissingValues(exampleSet, getOperatorClassName(), this, new String[0]);
Tools.checkAndCreateIds(exampleSet);
Attribute idAttribute = exampleSet.getAttributes().getId();
boolean idAttributeIsNominal = idAttribute.isNominal();
DistanceMatrix matrix = new DistanceMatrix(exampleSet.size());
Map<Integer, HierarchicalClusterNode> clusterMap = new HashMap<Integer, HierarchicalClusterNode>(exampleSet.size());
int[] clusterIds = new int[exampleSet.size()];
// filling the distance matrix
int nextClusterId = 0;
for (Example example1 : exampleSet) {
checkForStop();
clusterIds[nextClusterId] = nextClusterId;
int y = 0;
for (Example example2 : exampleSet) {
if (y > nextClusterId) {
matrix.set(nextClusterId, y, measure.calculateDistance(example1, example2));
}
y++;
}
if (idAttributeIsNominal) {
clusterMap.put(nextClusterId,
new HierarchicalClusterLeafNode(nextClusterId, example1.getValueAsString(idAttribute)));
} else {
clusterMap
.put(nextClusterId, new HierarchicalClusterLeafNode(nextClusterId, example1.getValue(idAttribute)));
}
nextClusterId++;
}
// creating linkage method
AbstractLinkageMethod linkage = new SingleLinkageMethod(matrix, clusterIds);
if (getParameterAsString(PARAMETER_MODE).equals(modes[1])) {
linkage = new CompleteLinkageMethod(matrix, clusterIds);
} else if (getParameterAsString(PARAMETER_MODE).equals(modes[2])) {
linkage = new AverageLinkageMethod(matrix, clusterIds);
}
// now building agglomerative tree bottom up
while (clusterMap.size() > 1) {
Agglomeration agglomeration = linkage.getNextAgglomeration(nextClusterId, clusterMap);
HierarchicalClusterNode newNode = new HierarchicalClusterNode(nextClusterId, agglomeration.getDistance());
newNode.addSubNode(clusterMap.get(agglomeration.getClusterId1()));
newNode.addSubNode(clusterMap.get(agglomeration.getClusterId2()));
clusterMap.remove(agglomeration.getClusterId1());
clusterMap.remove(agglomeration.getClusterId2());
clusterMap.put(nextClusterId, newNode);
nextClusterId++;
}
// creating model
HierarchicalClusterModel model = new DendogramHierarchicalClusterModel(clusterMap.entrySet().iterator().next()
.getValue());
// registering visualizer
ObjectVisualizerService.addObjectVisualizer(model, new ExampleVisualizer((ExampleSet) exampleSet.clone()));
modelOutput.deliver(model);
exampleSetOutput.deliver(exampleSet);
}
示例8: apply
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public ExampleSet apply(ExampleSet exampleSet) throws OperatorException {
Tools.onlyNonMissingValues(exampleSet, getOperatorClassName(), this);
// create new example table
int numberOfNewExamples = FastFourierTransform.getGreatestPowerOf2LessThan(exampleSet.size()) / 2;
ExampleTable exampleTable = new MemoryExampleTable(new LinkedList<Attribute>(), new DataRowFactory(
DataRowFactory.TYPE_DOUBLE_ARRAY, '.'), numberOfNewExamples);
// create frequency attribute (for frequency)
Attribute frequencyAttribute = AttributeFactory.createAttribute("frequency", Ontology.REAL);
exampleTable.addAttribute(frequencyAttribute);
DataRowReader drr = exampleTable.getDataRowReader();
int k = 0;
while (drr.hasNext()) {
DataRow dataRow = drr.next();
dataRow.set(frequencyAttribute,
FastFourierTransform.convertFrequency(k++, numberOfNewExamples, exampleSet.size()));
}
// create FFT values
Attribute label = exampleSet.getAttributes().getLabel();
// add FFT values
FastFourierTransform fft = new FastFourierTransform(WindowFunction.BLACKMAN_HARRIS);
SpectrumFilter filter = new SpectrumFilter(SpectrumFilter.NONE);
for (Attribute current : exampleSet.getAttributes()) {
if (current.isNumerical()) {
Complex[] result = fft.getFourierTransform(exampleSet, label, current);
Peak[] spectrum = filter.filter(result, exampleSet.size());
// create new attribute and fill table with values
Attribute newAttribute = AttributeFactory.createAttribute("fft(" + current.getName() + ")", Ontology.REAL);
exampleTable.addAttribute(newAttribute);
fillTable(exampleTable, newAttribute, spectrum);
}
}
ExampleSet resultSet = new SimpleExampleSet(exampleTable);
return resultSet;
}
示例9: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
// only use numeric attributes
Tools.onlyNumericalAttributes(exampleSet, "KernelPCA");
Tools.onlyNonMissingValues(exampleSet, getOperatorClassName(), this);
Attributes attributes = exampleSet.getAttributes();
int numberOfExamples = exampleSet.size();
// calculating means for later zero centering
exampleSet.recalculateAllAttributeStatistics();
double[] means = new double[exampleSet.getAttributes().size()];
int i = 0;
for (Attribute attribute : exampleSet.getAttributes()) {
means[i] = exampleSet.getStatistics(attribute, Statistics.AVERAGE);
i++;
}
// kernel
Kernel kernel = Kernel.createKernel(this);
// copying zero centered exampleValues
ArrayList<double[]> exampleValues = new ArrayList<double[]>(numberOfExamples);
i = 0;
for (Example columnExample : exampleSet) {
double[] columnValues = getAttributeValues(columnExample, attributes, means);
exampleValues.add(columnValues);
i++;
}
// filling kernel matrix
Matrix kernelMatrix = new Matrix(numberOfExamples, numberOfExamples);
for (i = 0; i < numberOfExamples; i++) {
for (int j = 0; j < numberOfExamples; j++) {
kernelMatrix.set(i, j, kernel.calculateDistance(exampleValues.get(i), exampleValues.get(j)));
}
}
// calculating eigenVectors
EigenvalueDecomposition eig = kernelMatrix.eig();
Model model = new KernelPCAModel(exampleSet, means, eig.getV(), exampleValues, kernel);
if (exampleSetOutput.isConnected()) {
exampleSetOutput.deliver(model.apply(exampleSet));
}
originalOutput.deliver(exampleSet);
modelOutput.deliver(model);
}
示例10: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
// check whether all attributes are numerical
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
Tools.onlyNonMissingValues(exampleSet, getOperatorClassName(), this, new String[0]);
Tools.onlyNumericalAttributes(exampleSet, "PCA");
Iterator<Attribute> iterate = exampleSet.getAttributes().allAttributes();
while (iterate.hasNext()) {
Attribute curattribute = iterate.next();
if (curattribute.getName().startsWith("pc_")) {
throw new UserError(this, "pca_attribute_names", curattribute.getName());
}
}
// create covariance matrix
log("Creating the covariance matrix...");
Matrix covarianceMatrix = CovarianceMatrix.getCovarianceMatrix(exampleSet, this);
// EigenVector and EigenValues of the covariance matrix
log("Performing the eigenvalue decomposition...");
EigenvalueDecomposition eigenvalueDecomposition = covarianceMatrix.eig();
checkForStop();
// create and deliver results
double[] eigenvalues = eigenvalueDecomposition.getRealEigenvalues();
Matrix eigenvectorMatrix = eigenvalueDecomposition.getV();
double[][] eigenvectors = eigenvectorMatrix.getArray();
PCAModel model = new PCAModel(exampleSet, eigenvalues, eigenvectors);
int reductionType = getParameterAsInt(PARAMETER_REDUCTION_TYPE);
switch (reductionType) {
case REDUCTION_NONE:
model.setNumberOfComponents(exampleSet.getAttributes().size());
break;
case REDUCTION_VARIANCE:
model.setVarianceThreshold(getParameterAsDouble(PARAMETER_VARIANCE_THRESHOLD));
break;
case REDUCTION_FIXED:
model.setNumberOfComponents(Math.min(exampleSet.getAttributes().size(),
getParameterAsInt(PARAMETER_NUMBER_OF_COMPONENTS)));
break;
}
modelOutput.deliver(model);
originalOutput.deliver(exampleSet);
if (exampleSetOutput.isConnected()) {
exampleSetOutput.deliver(model.apply(exampleSet));
}
}
示例11: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
// check whether all attributes are numerical
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
Tools.onlyNonMissingValues(exampleSet, getOperatorClassName(), this);
Tools.onlyNumericalAttributes(exampleSet, "SVD");
// create data matrix
Matrix dataMatrix = MatrixTools.getDataAsMatrix(exampleSet);
// Singular Value Decomposition
SingularValueDecomposition singularValueDecomposition = dataMatrix.svd();
// create and deliver results
double[] singularvalues = singularValueDecomposition.getSingularValues();
Matrix vMatrix = singularValueDecomposition.getV();
SVDModel model = new SVDModel(exampleSet, singularvalues, vMatrix);
if (getCompatibilityLevel().isAtMost(OPERATOR_VERSION_CHANGED_ATTRIBUTE_NAME)) {
model.enableLegacyMode();
}
int reductionType = getParameterAsInt(PARAMETER_REDUCTION_TYPE);
switch (reductionType) {
case REDUCTION_NONE:
model.setNumberOfComponents(exampleSet.getAttributes().size());
break;
case REDUCTION_PERCENTAGE:
model.setVarianceThreshold(getParameterAsDouble(PARAMETER_PERCENTAGE_THRESHOLD));
break;
case REDUCTION_FIXED:
model.setNumberOfComponents(getParameterAsInt(PARAMETER_NUMBER_OF_COMPONENTS));
break;
}
modelOutput.deliver(model);
originalOutput.deliver(exampleSet);
if (exampleSetOutput.isConnected()) {
exampleSetOutput.deliver(model.apply(exampleSet));
}
}
示例12: learn
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public Model learn(ExampleSet exampleSet) throws OperatorException {
Attribute label = exampleSet.getAttributes().getLabel();
if (label.isNominal() && label.getMapping().size() != 2) {
throw new UserError(this, 114, getName(), label.getName());
}
// check if example set contains missing values, if so fail because
// this operator produces garbage with them
Tools.onlyNonMissingValues(exampleSet, getOperatorClassName(), this, Attributes.LABEL_NAME);
this.svmExamples = new com.rapidminer.operator.learner.functions.kernel.jmysvm.examples.SVMExamples(exampleSet,
label, getParameterAsBoolean(PARAMETER_SCALE));
// kernel
int cacheSize = getParameterAsInt(PARAMETER_KERNEL_CACHE);
int kernelType = getParameterAsInt(PARAMETER_KERNEL_TYPE);
kernel = createKernel(kernelType);
if (kernelType == KERNEL_RADIAL) {
((KernelRadial) kernel).setGamma(getParameterAsDouble(PARAMETER_KERNEL_GAMMA));
} else if (kernelType == KERNEL_POLYNOMIAL) {
((KernelPolynomial) kernel).setDegree(getParameterAsDouble(PARAMETER_KERNEL_DEGREE));
} else if (kernelType == KERNEL_NEURAL) {
((KernelNeural) kernel).setParameters(getParameterAsDouble(PARAMETER_KERNEL_A),
getParameterAsDouble(PARAMETER_KERNEL_B));
} else if (kernelType == KERNEL_ANOVA) {
((KernelAnova) kernel).setParameters(getParameterAsDouble(PARAMETER_KERNEL_GAMMA),
getParameterAsDouble(PARAMETER_KERNEL_DEGREE));
} else if (kernelType == KERNEL_EPANECHNIKOV) {
((KernelEpanechnikov) kernel).setParameters(getParameterAsDouble(PARAMETER_KERNEL_SIGMA1),
getParameterAsDouble(PARAMETER_KERNEL_DEGREE));
} else if (kernelType == KERNEL_GAUSSIAN_COMBINATION) {
((KernelGaussianCombination) kernel).setParameters(getParameterAsDouble(PARAMETER_KERNEL_SIGMA1),
getParameterAsDouble(PARAMETER_KERNEL_SIGMA2), getParameterAsDouble(PARAMETER_KERNEL_SIGMA3));
} else if (kernelType == KERNEL_MULTIQUADRIC) {
((KernelMultiquadric) kernel).setParameters(getParameterAsDouble(PARAMETER_KERNEL_SIGMA1),
getParameterAsDouble(PARAMETER_KERNEL_SHIFT));
}
kernel.init(svmExamples, cacheSize);
// SVM
svm = createSVM(label, kernel, svmExamples, exampleSet);
svm.init(kernel, svmExamples);
svm.train();
return createSVMModel(exampleSet, svmExamples, kernel, kernelType);
}
示例13: learn
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
/** Learns a new SVM model with the LibSVM package. */
@Override
public Model learn(ExampleSet exampleSet) throws OperatorException {
svm_parameter params = getParameters(exampleSet);
if (exampleSet.size() < 2) {
throw new UserError(this, 110, 2);
}
// check if example set contains missing values, if so fail because
// this operator produces garbage with them
Tools.onlyNonMissingValues(exampleSet, getOperatorClassName(), this);
// check if svm type fits problem type
Attribute label = exampleSet.getAttributes().getLabel();
if (label.isNominal()) {
if ((params.svm_type != SVM_TYPE_C_SVC) && (params.svm_type != SVM_TYPE_NU_SVC)
&& (params.svm_type != SVM_TYPE_ONE_CLASS)) {
throw new UserError(this, 102, SVM_TYPES[params.svm_type], label.getName());
}
// check for one class svm: Only works with mapping of label attribute of size 1
if ((params.svm_type == SVM_TYPE_ONE_CLASS) && label.getMapping().size() > 1) {
throw new UserError(this, 118, label.getName(), label.getMapping().size() + "", 1 + " for one-class svm");
}
} else {
if ((params.svm_type != SVM_TYPE_EPS_SVR) && (params.svm_type != SVM_TYPE_NU_SVR)) {
throw new UserError(this, 101, SVM_TYPES[params.svm_type], label.getName());
}
}
svm_problem problem = getProblem(exampleSet);
this.checkForStop();
String errorMsg = Svm.svm_check_parameter(problem, params);
if (errorMsg != null) {
throw new UserError(this, 905, new Object[] { "libsvm", errorMsg });
}
log("Training LibSVM.");
svm_model model = Svm.svm_train(problem, params, this);
return new LibSVMModel(exampleSet, model, exampleSet.getAttributes().size(),
getParameterAsBoolean(PARAMETER_CONFIDENCE_FOR_MULTICLASS));
}
示例14: generateInternalClusterModel
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
protected ClusterModel generateInternalClusterModel(ExampleSet exampleSet) throws OperatorException {
DistanceMeasure measure = getInitializedMeasure(exampleSet);
double epsilon = getParameterAsDouble(PARAMETER_EPSILON);
int minPoints = getParameterAsInt(PARAMETER_MIN_POINTS);
// init operator progress
getProgress().setTotal(exampleSet.size());
// checking and creating ids if necessary
Tools.checkAndCreateIds(exampleSet);
// additional checks
Tools.onlyNonMissingValues(exampleSet, getOperatorClassName(), this, new String[0]);
// extracting attribute names
Attributes attributes = exampleSet.getAttributes();
ArrayList<String> attributeNames = new ArrayList<String>(attributes.size());
for (Attribute attribute : attributes) {
attributeNames.add(attribute.getName());
}
boolean[] visited = new boolean[exampleSet.size()];
boolean[] noised = new boolean[exampleSet.size()];
int[] clusterAssignments = new int[exampleSet.size()];
int i = 0;
int clusterIndex = 1;
for (Example example : exampleSet) {
if (!visited[i]) {
Queue<Integer> centerNeighbourhood = getNeighbourhood(example, exampleSet, measure, epsilon);
if (centerNeighbourhood.size() < minPoints) {
noised[i] = true;
} else {
// then its center point of a cluster. Assign example to new cluster
clusterAssignments[i] = clusterIndex;
// expanding cluster within density borders
while (centerNeighbourhood.size() > 0) {
int currentIndex = centerNeighbourhood.poll().intValue();
Example currentExample = exampleSet.getExample(currentIndex);
// assigning example to current cluster
clusterAssignments[currentIndex] = clusterIndex;
visited[currentIndex] = true;
// appending own neighbourhood to queue
Queue<Integer> neighbourhood = getNeighbourhood(currentExample, exampleSet, measure, epsilon);
if (neighbourhood.size() >= minPoints) {
// then this neighbor of center is also a center of the cluster
while (neighbourhood.size() > 0) {
int neighbourIndex = neighbourhood.poll().intValue();
if (!visited[neighbourIndex]) {
if (!noised[neighbourIndex]) {
// if its not noised, then it might be center of cluster! So
// append to queue
centerNeighbourhood.add(neighbourIndex);
}
clusterAssignments[neighbourIndex] = clusterIndex;
visited[neighbourIndex] = true;
}
}
}
}
// step to next cluster
clusterIndex++;
}
}
i++;
getProgress().step();
}
ClusterModel model = new ClusterModel(exampleSet, Math.max(clusterIndex, 1), addsLabelAttribute(),
getParameterAsBoolean(RMAbstractClusterer.PARAMETER_REMOVE_UNLABELED));
model.setClusterAssignments(clusterAssignments, exampleSet);
if (addsClusterAttribute()) {
addClusterAssignments(exampleSet, clusterAssignments);
}
getProgress().complete();
return model;
}
示例15: doWork
import com.rapidminer.example.Tools; //导入方法依赖的package包/类
@Override
public void doWork() throws OperatorException {
ExampleSet exampleSet = exampleSetInput.getData(ExampleSet.class);
DistanceMeasure measure = measureHelper.getInitializedMeasure(exampleSet);
// additional checks
Tools.onlyNonMissingValues(exampleSet, "AgglomerativeClustering");
Tools.checkAndCreateIds(exampleSet);
Attribute idAttribute = exampleSet.getAttributes().getId();
boolean idAttributeIsNominal = idAttribute.isNominal();
DistanceMatrix matrix = new DistanceMatrix(exampleSet.size());
Map<Integer, HierarchicalClusterNode> clusterMap = new HashMap<Integer, HierarchicalClusterNode>(exampleSet.size());
int[] clusterIds = new int[exampleSet.size()];
// filling the distance matrix
int nextClusterId = 0;
for (Example example1: exampleSet) {
checkForStop();
clusterIds[nextClusterId] = nextClusterId;
int y = 0;
for (Example example2: exampleSet) {
if (y > nextClusterId)
matrix.set(nextClusterId, y, measure.calculateDistance(example1, example2));
y++;
}
if (idAttributeIsNominal) {
clusterMap.put(nextClusterId, new HierarchicalClusterLeafNode(nextClusterId, example1.getValueAsString(idAttribute)));
} else {
clusterMap.put(nextClusterId, new HierarchicalClusterLeafNode(nextClusterId, example1.getValue(idAttribute)));
}
nextClusterId++;
}
// creating linkage method
AbstractLinkageMethod linkage = new SingleLinkageMethod(matrix, clusterIds);
if (getParameterAsString(PARAMETER_MODE).equals(modes[1]))
linkage = new CompleteLinkageMethod(matrix, clusterIds);
else if (getParameterAsString(PARAMETER_MODE).equals(modes[2]))
linkage = new AverageLinkageMethod(matrix, clusterIds);
// now building agglomerative tree bottom up
while (clusterMap.size() > 1) {
Agglomeration agglomeration = linkage.getNextAgglomeration(nextClusterId, clusterMap);
HierarchicalClusterNode newNode = new HierarchicalClusterNode(nextClusterId, agglomeration.getDistance());
newNode.addSubNode(clusterMap.get(agglomeration.getClusterId1()));
newNode.addSubNode(clusterMap.get(agglomeration.getClusterId2()));
clusterMap.remove(agglomeration.getClusterId1());
clusterMap.remove(agglomeration.getClusterId2());
clusterMap.put(nextClusterId, newNode);
nextClusterId++;
}
// creating model
HierarchicalClusterModel model = new DendogramHierarchicalClusterModel(clusterMap.entrySet().iterator().next().getValue());
// registering visualizer
ObjectVisualizerService.addObjectVisualizer(model, new ExampleVisualizer((ExampleSet) exampleSet.clone()));
modelOutput.deliver(model);
exampleSetOutput.deliver(exampleSet);
}