Package cascading.pattern.model

Examples of cascading.pattern.model.ModelSchema


  public RandomForestFunction( RandomForestSpec randomForestSpec )
    {
    super( randomForestSpec );

    ModelSchema modelSchema = randomForestSpec.getModelSchema();

    String predictedFieldName = modelSchema.getPredictedFieldNames().get( 0 );

    List<String> predictedCategories = modelSchema.getPredictedCategories( predictedFieldName );

    if( modelSchema.isIncludePredictedCategories() && predictedCategories.isEmpty() )
      throw new IllegalArgumentException( "no predicted categories were set, but include predicted is true" );

    List<String> nodeCategories = randomForestSpec.getModelCategories();
    Sets.SetView<String> difference = Sets.difference( newHashSet( predictedCategories ), newHashSet( nodeCategories ) );
View Full Code Here


    return tail;
    }

  private Pipe handleTreeModel( Pipe tail, TreeModel model )
    {
    ModelSchema modelSchema = createModelSchema( model );

    Tree tree = createTree( model, modelSchema );

    TreeSpec treeSpec = new TreeSpec( modelSchema, tree );
View Full Code Here

    return create( tail, modelSchema, new TreeFunction( treeSpec ) );
    }

  private Pipe handleGeneralRegressionModel( Pipe tail, GeneralRegressionModel model )
    {
    ModelSchema modelSchema = createModelSchema( model );

    Set<String> parameterList = GeneralRegressionUtil.createParameters( model );
    Set<String> covariateList = GeneralRegressionUtil.createCovariates( model );
    Set<String> factorsList = GeneralRegressionUtil.createFactors( model );
View Full Code Here

    throw new UnsupportedOperationException( "unsupported mining type, got: " + model.getFunctionName() );
    }

  private Pipe handleCategoricalRegressionModel( Pipe tail, RegressionModel model )
    {
    ModelSchema modelSchema = createModelSchema( model );

    List<String> predictedCategories = new ArrayList<String>( modelSchema.getPredictedCategories( modelSchema.getPredictedFieldNames().get( 0 ) ) );

    if( predictedCategories.isEmpty() )
      throw new PatternException( "no categories specified" );

    GeneralRegressionSpec regressionSpec = new GeneralRegressionSpec( modelSchema );
View Full Code Here

  private Pipe handlePredictionRegressionModel( Pipe tail, RegressionModel model )
    {
    if( model.getRegressionTables().size() != 1 )
      throw new UnsupportedOperationException( "regression model only supports a single regression table, got: " + model.getRegressionTables().size() );

    ModelSchema modelSchema = createModelSchema( model );

    org.dmg.pmml.RegressionTable regressionTable = model.getRegressionTables().get( 0 );

    GeneralRegressionSpec regressionSpec = new GeneralRegressionSpec( modelSchema );
View Full Code Here

    return create( tail, modelSchema, new PredictionRegressionFunction( regressionSpec ) );
    }

  private Pipe handleClusteringModel( Pipe tail, ClusteringModel model )
    {
    ModelSchema modelSchema = createModelSchema( model );

    if( model.getModelClass() != ClusteringModel.ModelClass.CENTER_BASED )
      throw new UnsupportedOperationException( "unsupported model class, got: " + model.getModelClass() );

    ComparisonMeasure comparisonMeasure = model.getComparisonMeasure();
View Full Code Here

    return create( tail, modelSchema, new ClusteringFunction( clusteringSpec ) );
    }

  private Pipe handleMiningModel( Pipe tail, MiningModel model )
    {
    ModelSchema modelSchema = createModelSchema( model );
    List<TreeSpec> models = new LinkedList<TreeSpec>();

    for( Segment segment : model.getSegmentation().getSegments() )
      {
      if( !segment.getPredicate().getClass().equals( True.class ) )
        throw new PatternException( "segment predicates currently not supported, got: " + segment.getPredicate() );

      Model segmentModel = segment.getModel();

      if( segmentModel instanceof TreeModel )
        models.add( new TreeSpec( modelSchema, createTree( (TreeModel) segmentModel, modelSchema ) ) );
      else
        throw new PatternException( "ensemble model currently not supported, got: " + segmentModel );
      }

    EnsembleSpec<TreeSpec> miningSpec = new EnsembleSpec<TreeSpec>( modelSchema, models );

    LOG.debug( "creating: {}, input: {}, output: {}", new Object[]{miningSpec, modelSchema.getInputFields(),
                                                                   modelSchema.getDeclaredFields()} );

    SelectionStrategy strategy = PMMLUtil.getSelectionStrategy( model );

    miningSpec.setSelectionStrategy( strategy );
View Full Code Here

    return new Each( tail, inputFields, function, Fields.ALL );
    }

  private ModelSchema createModelSchema( Model model )
    {
    ModelSchema modelSchema = new ModelSchema();

    for( MiningField miningField : model.getMiningSchema().getMiningFields() )
      {
      DataField dataField = getPMMLModel().getDataField( miningField.getName() );

      if( miningField.getUsageType() == FieldUsageType.ACTIVE )
        modelSchema.addExpectedField( createDataFields( dataField ) );
      else if( miningField.getUsageType() == FieldUsageType.PREDICTED )
        modelSchema.setPredictedFields( createDataFields( dataField ) );
      }

    if( modelSchema.getPredictedFieldNames().isEmpty() && defaultPredictedField == null )
      throw new PatternException( "no predicted field name provided in PMML model, use setDefaultPredictedField() method" );

    if( modelSchema.getPredictedFieldNames().isEmpty() )
      modelSchema.setPredictedFields( new ContinuousDataField( defaultPredictedField ) );

    return modelSchema;
    }
View Full Code Here

      throw new IllegalArgumentException( "given selection strategy must support parallel models, got: " + ensembleSpec.getSelectionStrategy() );

    if( ensembleSpec.getModelSpecs().size() < 2 )
      throw new IllegalArgumentException( "ensembles must have more than 1 model" );

    ModelSchema modelSchema = ensembleSpec.getModelSchema();

    Fields predictedFields = modelSchema.getPredictedFields();
    Fields keyFields = modelSchema.getKeyFields();

    if( keyFields.isNone() )
      {
      keyFields = new Fields( "ensemble-primary-key", String.class );
      pipe = new InsertGUID( pipe, keyFields );
      }

    boolean isCategorical = ensembleSpec.isPredictedCategorical();

    // the parallel bits
    List<Pipe> pipes = new ArrayList<Pipe>();

    for( int i = 0; i < ensembleSpec.getModelSpecs().size(); i++ )
      {
      Spec spec = (Spec) ensembleSpec.getModelSpecs().get( i );

      if( spec instanceof TreeSpec )
        pipes.add( createScoringPipe( i, pipe, modelSchema, new TreeFunction( (TreeSpec) spec, isCategorical, false ) ) );
      }

    pipe = new GroupBy( "vote", pipes.toArray( new Pipe[ pipes.size() ] ), keyFields );

    SelectionBuffer buffer;

    if( isCategorical )
      buffer = new CategoricalSelectionBuffer( ensembleSpec );
    else
      buffer = new PredictionSelectionBuffer( ensembleSpec );

    pipe = new Every( pipe, predictedFields, buffer, Fields.SWAP );

    if( modelSchema.getKeyFields().isNone() )
      pipe = new Discard( pipe, keyFields );

    setTails( pipe );
    }
View Full Code Here

    super( regressionSpec );

    if( regressionSpec.getNormalization() == null )
      throw new IllegalArgumentException( "normalization may not be null" );

    ModelSchema modelSchema = regressionSpec.getModelSchema();

    DataField predictedField = modelSchema.getPredictedField( modelSchema.getPredictedFieldNames().get( 0 ) );

    if( !( predictedField instanceof CategoricalDataField ) )
      throw new IllegalArgumentException( "predicted field must be categorical" );

    if( ( (CategoricalDataField) predictedField ).getCategories().size() != regressionSpec.getRegressionTables().size() )
View Full Code Here

TOP

Related Classes of cascading.pattern.model.ModelSchema

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.