Ejemplo n.º 1
0
import numpy as np
import pickle

"""
Used to generate trained GB models with different train-test splits.
"""

np.random.seed(100)

df = pickle.load(open('../../data/pairs_pdos.pkl'))

if True:
    X,y = train_prep_pdos(df,include_WF=True,dE=0.1)
    model_type = 'pdos'
else:
    X,y = train_prep(df,include_WF=True)
    model_type = 'moments'

if False:
    X_train, X_dev, X_test, y_train, y_dev, y_test = split_by_cols(df,X,y,['comp','ads_a','ads_b'])
    split_type = 'comp_rxn'
elif True:
    X_train, X_dev, X_test, y_train, y_dev, y_test = split_by_cols(df,X,y,['comp'])
    split_type = 'comp'
elif False:
    X_train, X_dev, X_test, y_train, y_dev, y_test = split_by_cols(df,X,y,['ads_a','ads_b'])
    split_type = 'rxn'
else:
    X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3)
    X_dev, X_test, y_dev, y_test = train_test_split(X_test,y_test,test_size=0.5)
    split_type = 'random'
Ejemplo n.º 2
0
    errors = abs(predictions - test_labels)
    mae = np.mean(errors)
    print('Model Performance')
    print('Average Error: {:0.4f} eV.'.format(mae))
    return mae


if __name__ == '__main__':
    df = pickle.load(open('data/pairs_pdos.pkl'))

    features = 'moments'  # #pdos,'moments'
    bayes = True

    #Feature Selection
    if features == 'moments':
        X, y = train_prep(df)
    elif features == 'pdos':
        X, y = train_prep_pdos(df, stack=False, include_WF=False, dE=0.1)

    X_train, X_dev, X_test, y_train, y_dev, y_test, groups = split_by_cols(
        df, X, y, ['comp', 'ads_a', 'ads_b'], ret_groups=True)

    rf = ensemble.RandomForestRegressor(n_estimators=100)

    group_kfold = GroupKFold(n_splits=3)

    #print(X_train.shape[1]),np.sqrt(X_train.shape[1])
    if bayes:
        random_grid = {  #'n_estimators': (5,100),
            'max_features': (int(np.sqrt(X_train.shape[1])), X_train.shape[1]),
            'max_depth': (5, 50),
Ejemplo n.º 3
0
import pickle
import matplotlib.pyplot as plt
from ML_prep import load_data, split_by_cols, train_prep_pdos, train_prep
import numpy as np

df = pickle.load(open('data/pairs_pdos.pkl'))
X,y = train_prep_pdos(df,include_WF=True,dE=0.1)
X1,y1 = train_prep(df,include_WF=True)

i = 1094
#i = 889

n = 2
figsize = (8,8)

if n == 2:
    fig1 = plt.figure(facecolor=(0.75,)*3,figsize=figsize)
    fig2 = plt.figure(facecolor=(0.75,)*3,figsize=figsize)
    axs = [fig1.add_subplot(111),fig2.add_subplot(111)]
else:
    fig = plt.figure(figsize=figsize)
    axs = [fig.add_subplot(111)]

while True:
    print i
    Xi = X[i]

    axs[0].fill_between(range(200),[0]*200,Xi[:200],facecolor='deepskyblue',edgecolor='none')
    axs[0].fill_between(range(199,352),[0]*(352-199),Xi[199:352],facecolor='deepskyblue',edgecolor='none',alpha=0.3)

    if n == 2: