Exemplo n.º 1
0
    #EncodedBond(n_jobs = -1, max_depth = 1)]
    feat1 = Connectivity(n_jobs=1)
    featLC = EncodedBond(n_jobs=-1, smoothing='expit', max_depth=1)
    featNP = EncodedBond(n_jobs=-1, smoothing='norm', max_depth=2)
    #feat1b = (Connectivity(n_jobs = 1, use_coordination = True))

    #loop to  test each fold
    for x in range(5):
        # Fit and transform test and train set
        Xin_train, Xin_test, y_train, y_test = load_qm7(x)
        #for feat in featNP:
        #X_train = feat1.fit_transform(Xin_train)
        #X_test = feat1.transform(Xin_test)
        #for feat2 in feats2:
        X_train1 = feat1.fit_transform(Xin_train)
        X_test1 = feat1.transform(Xin_test)
        #X_train2b = feat2b.fit_transform(Xin_train)
        #X_test2b = feat2b.transform(Xin_test)
        #for feat in featsNP:
        X_trainLC = featLC.fit_transform(Xin_train)
        X_testLC = featLC.transform(Xin_test)
        X_train = np.concatenate((X_train1, X_trainLC), axis=1)
        X_test = np.concatenate((X_test1, X_testLC), axis=1)
        # Use Ridge linear regression
        clf = Ridge(alpha=0.01)
        clf.fit(X_trainLC, y_train)
        # Calculate train and test MAE
        train_error_temp[x] = MAE(clf.predict(X_trainLC), y_train)
        test_error_temp[x] = MAE(clf.predict(X_testLC), y_test)

    print(
Exemplo n.º 2
0
alpha = 0.1
gamma = 1

for fold in range(4):
    train_folds = [x for x in range(4) if x != fold]
    train_idxs = np.ravel(train_validation[train_folds])
    test_idxs = np.ravel(train_validation[fold])

    Xin_train = list(zip(train_anum[train_idxs], train_coor[train_idxs]))
    Xin_test = list(zip(train_anum[test_idxs], train_coor[test_idxs]))
    y_train = train_energy[train_idxs]
    y_test = train_energy[test_idxs]

    #for feat in feats:
    X_train = feat.fit_transform(Xin_train)
    X_test = feat.transform(Xin_test)

    clf = KernelRidge(alpha=alpha, gamma=gamma, kernel="rbf")
    clf.fit(X_train, y_train)
    train_error_temp[fold] = MAE(clf.predict(X_train), y_train)
    test_error_temp[fold] = MAE(clf.predict(X_test), y_test)

with open('ANI1_KRR.txt', 'a') as f:
    print('\n', feat)
    print("alpha: %.4f    gamma: %6f" % (alpha, gamma))
    print(
        "Avg Train MAE: %.6f Avg Test MAE: %.6f" %
        (statistics.mean(train_error_temp), statistics.mean(test_error_temp)))
    print()
    #caluate standard deviation
    print("Train Standard Deviation: %.4f, Test Standard Deviation: %.4f" %