Ejemplo n.º 1
0
def training(features, target, cycle):
    try:
        if cycle != 1:
            model = repository.get(PassiveAggressiveClassifier.__name__,
                                   DIR_PATH)
            scaler = repository.get(StandardScaler.__name__, DIR_PATH)
        else:
            model = PassiveAggressiveClassifier(loss='squared_hinge')
            scaler = StandardScaler()

        # add the new data to the existing scaler model, because the scaling depends on the data
        scaler.partial_fit(features)

        # scale the new features
        features = scaler.transform(features)

        # Perform online learning with the new features
        model.partial_fit(features, target, classes=np.array([0, 1]))

        # Store the model and scaler to respective files for later use
        repository.create(model, PassiveAggressiveClassifier.__name__,
                          DIR_PATH)
        repository.create(scaler, StandardScaler.__name__, DIR_PATH)

        return {'message': 'training successful'}

    except Exception as e:
        traceback.print_tb(e.__traceback__)
        return {'message': 'training failed '}
Ejemplo n.º 2
0
def training(features, target):
    try:
        model = repository.get(SGDClassifier(loss='hinge', penalty='l1'),
                               SGDClassifier.__name__, DIR_PATH)
        scaler = repository.get(MinMaxScaler(), MinMaxScaler.__name__,
                                DIR_PATH)
        scaler.partial_fit(features)
        features = scaler.transform(features)
        model.partial_fit(features, target, classes=np.array([0, 1]))
        repository.create(model, SGDClassifier.__name__, DIR_PATH)
        repository.create(scaler, MinMaxScaler.__name__, DIR_PATH)
        return {'message': 'training successful'}
    except Exception as e:
        traceback.print_tb(e.__traceback__)
        return {'message': 'training failed '}
Ejemplo n.º 3
0
def training(features, target):
    try:
        model = repository.get(
            SGDRegressor(loss='epsilon_insensitive', penalty='l2'),
            SGDRegressor.__name__, DIR_PATH)
        scaler = repository.get(MaxAbsScaler(), MaxAbsScaler.__name__,
                                DIR_PATH)
        scaler.partial_fit(features)
        features = scaler.transform(features)
        model.partial_fit(features, target)
        repository.create(model, SGDRegressor.__name__, DIR_PATH)
        repository.create(scaler, MaxAbsScaler.__name__, DIR_PATH)
        return {'message': 'training successful '}
    except Exception as e:
        traceback.print_tb(e.__traceback__)
        return {'message': 'training failed '}
Ejemplo n.º 4
0
def training(features, target, cycle):
    try:
        if cycle != 1:
            model = repository.get(SGDClassifier.__name__, DIR_PATH)
            scaler = repository.get(MinMaxScaler.__name__, DIR_PATH)
        else:
            model = SGDClassifier(loss='hinge', penalty='l1')
            scaler = MinMaxScaler()

        scaler.partial_fit(features)
        features = scaler.transform(features)

        # online learn the adaptation options (features) and their targets (goal satisfactions)
        model.partial_fit(features, target, classes=np.array([0, 1, 2, 3]))

        # Save the scaler and classifier model
        repository.create(model, SGDClassifier.__name__, DIR_PATH)
        repository.create(scaler, MinMaxScaler.__name__, DIR_PATH)

        return {'message': 'training successful'}

    except Exception as e:
        traceback.print_tb(e.__traceback__)
        return {'message': 'training failed '}