Esempio n. 1
0
from sklearn.pipeline import Pipeline
from sklearn.decomposition import PCA
from sklearn.model_selection import train_test_split

from fastsr.estimators.symbolic_regression import SymbolicRegression
from fastsr.containers.learning_data import LearningData

estimators = [('reduce_dim', PCA()), ('symbolic_regression', SymbolicRegression())]
pipe = Pipeline(estimators)

training_data = LearningData()
training_data.from_file('data/hour_simple_lagged.hdf5')
X_train, X_test, y_train, y_test = train_test_split(training_data.predictors, training_data.response, test_size=0.1,
                                                    shuffle=False)

pipe.fit(X_train, y_train)
print(pipe.score(X_train, y_train))

model = SymbolicRegression()
model.fit(X_train, y_train)
print(model.score(X_train, y_train))
Esempio n. 2
0
                    required=True)
parser.add_argument('-s', '--seed', help='Random seed.', type=int)
args = parser.parse_args()

if args.experiment == 'TruncationElite':
    experiment_class, experiment_name = utils.get_experiment_class_and_name(
        TruncationElite)
elif args.experiment == 'TruncationEliteRT':
    experiment_class, experiment_name = utils.get_experiment_class_and_name(
        TruncationEliteRT)
elif args.experiment == 'TruncationEliteRTNOMUT':
    experiment_class, experiment_name = utils.get_experiment_class_and_name(
        TruncationEliteRTNOMUT)

training_data = LearningData()
training_data.from_file(args.data)
X_train, X_test, y_train, y_test = train_test_split(training_data.predictors,
                                                    training_data.response,
                                                    test_size=0.2,
                                                    shuffle=False)
print('Training examples: ' + str(X_train.shape[0]))
print('Testing examples: ' + str(X_test.shape[0]))
model = SymbolicRegression(
    experiment_class=experiment_class,
    variable_type_indices=training_data.variable_type_indices,
    variable_names=training_data.variable_names,
    variable_dict=training_data.variable_dict,
    num_features=training_data.num_variables,
    pop_size=100,
    ngen=1000,
    crossover_probability=.5,
Esempio n. 3
0
experiment = 'rt'
dataset = 'energy_lagged'
path = '/'.join([dataset, experiment])
models_dir = '/home/cfusting/efsresults/' + path + '/saved_models/'
results_dir = '/home/cfusting/efsscores/' + path


def get_seed(file):
    pattern = re.compile('\d+')
    match = pattern.search(file)
    return match.group(0)


training_data = LearningData()
training_data.from_file(
    '/home/cfusting/bunny/range-terminal/data/energy_lagged.hdf5')
X_train, X_test, y_train, y_test = train_test_split(training_data.predictors,
                                                    training_data.response,
                                                    test_size=0.2,
                                                    shuffle=False)
files = [f for f in listdir(models_dir) if isfile(join(models_dir, f))]
scores = {}
all_features = {}
print('Processing seeds for ' + experiment)
for fl in files:
    with open(models_dir + '/' + fl, 'rb') as f:
        data = pickle.load(f)
    seed = get_seed(fl)
    print('Processing seed: ' + str(seed))
    statistics = data[0]
    best_models = data[1]