Exemplo n.º 1
0
lbl = "Base model SVM(kernel=rbf):"
print (lbl)
basemodel = sklearn.svm.SVC(kernel=kernel, probability=True)
basemodel.fit(Xsupervised, ysupervised)
evaluate(basemodel, X, ys, ytrue, lbl)

# basemodel = SGDClassifier(loss='hinge', penalty='l1', tol=1e-3, max_iter=1000) # scikit logistic regression
# basemodel.fit(X[random_labeled_points, :], ys[random_labeled_points])
# print ("supervised log.reg. score", basemodel.score(X, ytrue))
#
# fast (but naive, unsafe) self learning framework
ssmodel = SelfLearningModel(basemodel)
ssmodel.fit(X, ys)
print ("self-learning log.reg. score", ssmodel.score(X, ytrue))

kernel = "rbf"

Xsupervised = X[ys!=-1, :]
ysupervised = ys[ys!=-1]

lbl = "Purely supervised SVM:"
print (lbl)
model = sklearn.svm.SVC(kernel=kernel, probability=True)
model.fit(Xsupervised, ysupervised)
evaluate(model, X, ys, ytrue, lbl)

lbl =  "S3VM (Gieseke et al. 2012):"
print (lbl)
model = scikitTSVM.SKTSVM(kernel=kernel)
model.fit(X, ys)
evaluate(model, X, ys, ytrue, lbl)
Exemplo n.º 2
0
    X = pd.read_csv('../data/five_imps/train_mice_hot_%d.csv' % i)
    y = np.ravel(X[['y']])
    X.drop('y', axis=1, inplace=True)
    # Transform to numpy
    X = X.values

    if use_scaling:
        scaler = StandardScaler()
        #scaler = RobustScaler()
        #scaler = MinMaxScaler()
        X = scaler.fit_transform(X)

    if use_transductive:
        #cfr = CPLELearningModel(cfr, verbose=2)
        cfr = scikitTSVM.SKTSVM(kernel="rbf")
        #cfr = SelfLearningModel(cfr)

    if do_cross_validation:

        #iterate through the training and test cross validation segments and
        #run the classifier on each one, aggregating the results into a list
        results = []
        X_cv_train = X

        for j in range(1, 6):
            X_cv_test = pd.read_csv('../data/five_imps/train_mice_hot_%d.csv' %
                                    j)
            X_cv_test.drop('y', axis=1, inplace=True)
            # Transform to numpy
            X_cv_test = X_cv_test.values