예제 #1
0
파일: svc.py 프로젝트: ozgurgul/lale
class SVCImpl():
    def __init__(self,
                 C=1.0,
                 kernel='rbf',
                 degree=3,
                 gamma='auto_deprecated',
                 coef0=0.0,
                 shrinking=True,
                 probability=False,
                 tol=0.001,
                 cache_size=200,
                 class_weight='balanced',
                 verbose=False,
                 max_iter=(-1),
                 decision_function_shape='ovr',
                 random_state=None):
        self._hyperparams = {
            'C': C,
            'kernel': kernel,
            'degree': degree,
            'gamma': gamma,
            'coef0': coef0,
            'shrinking': shrinking,
            'probability': probability,
            'tol': tol,
            'cache_size': cache_size,
            'class_weight': class_weight,
            'verbose': verbose,
            'max_iter': max_iter,
            'decision_function_shape': decision_function_shape,
            'random_state': random_state
        }
        self._wrapped_model = Op(**self._hyperparams)

    def fit(self, X, y=None):
        if (y is not None):
            self._wrapped_model.fit(X, y)
        else:
            self._wrapped_model.fit(X)
        return self

    def predict(self, X):
        return self._wrapped_model.predict(X)

    def predict_proba(self, X):
        return self._wrapped_model.predict_proba(X)

    def decision_function(self, X):
        return self._wrapped_model.decision_function(X)
예제 #2
0
파일: train_DF.py 프로젝트: qlv1/11775-hw3
                i += 1

    clf = SVC(kernel=laplacian_kernel)

    features = ['.cnn.', '.mfcc.', '.asr.', '.cnn+mfcc.', '.cnn+mfcc+asr.']
    X_score = np.zeros((len(X_all), len(features)))

    j = 0
    for j, feature in enumerate(features):
        if j <= 2:
            X = X_all[:, dimension_i[j]:dimension_i[j] + dimension_i[j + 1]]
        elif j == 3:
            X = X_all[:, 0:150]
        elif j == 4:
            X = X_all
        clf.fit(X, Y_all)
        print('saving scores...')
        X_score[:, j] = clf.decision_function(X)
        # print (X_score[:, j])
        np.save(event_name + feature + 'score', X_score[:, j])
        cPickle.dump(clf, open(output_file + feature + 'score', "wb"))

    clf = SVC(kernel='linear')
    clf.fit(X_score[:, [0, 1, 2, 4]], Y_all)

    fread.close()

    cPickle.dump(clf, open(output_file, "wb"))

    print 'SVM trained successfully for event %s!' % (event_name)