Пример #1
0
// CreateState creates a new state for AROW classifier.
func (c *AROWStateCreator) CreateState(ctx *core.Context, params data.Map) (core.SharedState, error) {
	label, err := pluginutil.ExtractParamAsStringWithDefault(params, "label_field", "label")
	if err != nil {
		return nil, err
	}
	fv, err := pluginutil.ExtractParamAsStringWithDefault(params, "feature_vector_field", "feature_vector")
	if err != nil {
		return nil, err
	}
	rw, err := pluginutil.ExtractParamAndConvertToFloat(params, "regularization_weight")
	if err != nil {
		return nil, err
	}
	if rw <= 0 {
		return nil, errors.New("regularization_weight parameter must be greater than zero")
	}

	a, err := NewAROW(float32(rw))
	if err != nil {
		return nil, fmt.Errorf("failed to initialize AROW: %v", err)
	}

	return &AROWState{
		arow:               a,
		labelField:         label,
		featureVectorField: fv,
	}, nil
}
Пример #2
0
func (c *PassiveAggressiveStateCreator) CreateState(ctx *core.Context, params data.Map) (core.SharedState, error) {
	value, err := pluginutil.ExtractParamAsStringWithDefault(params, "value_field", "value")
	if err != nil {
		return nil, err
	}
	fv, err := pluginutil.ExtractParamAsStringWithDefault(params, "feature_vector_field", "feature_vector")
	if err != nil {
		return nil, err
	}

	rw, err := pluginutil.ExtractParamAndConvertToFloat(params, "regularization_weight")
	if err != nil {
		return nil, err
	}
	if rw <= 0 {
		return nil, errors.New("regularization_weight parameter must be greater than zero")
	}

	sen, err := pluginutil.ExtractParamAndConvertToFloat(params, "sensitivity")
	if err != nil {
		return nil, err
	}
	if sen < 0 {
		return nil, errors.New("sensitivity parameter must be not less than zero")
	}

	pa, err := NewPassiveAggressive(float32(rw), float32(sen))
	if err != nil {
		return nil, err
	}

	return &PassiveAggressiveState{
		pa:                 pa,
		valueField:         value,
		featureVectorField: fv,
	}, nil
}