예제 #1
0
def run(dataset_train, dataset_test, pop_size, gens, cross_rate, fb, max_time=1200):

    Xtrain, ytrain = dataset_train[:, :-1], dataset_train[:, -1]
    Xtest,  ytest  = dataset_test[:, :-1],  dataset_test[:, -1]
    
    est_gp = Feat(obj="fitness,complexity",
               pop_size=pop_size,
               gens=gens,
               max_time=max_time,
               max_stall=50,
               batch_size=10000,
               ml = "LinearRidgeRegression",
               sel='lexicase',
               surv='nsga2',
               max_depth=10,
               max_dim=min([Xtrain.shape[1]*2,50]),
               #random_state=random_seed,
               functions="+,-,*,/,sqrt,sin,cos,tanh,exp,log,^,x,kd",
               otype="f",
               backprop=True,
               iters=10,
               n_threads=1,
               verbosity=1,
               # tuned parameters
               cross_rate= cross_rate,
               fb = fb,
               root_xo_rate = 0.75,
               softmax_norm = False
               )
    
    est_gp.fit(Xtrain, ytrain)
    
    return RMSE(est_gp.predict(Xtrain), ytrain), RMSE(est_gp.predict(Xtest), ytest), est_gp.get_model()
예제 #2
0
파일: wrappertest.py 프로젝트: hsarv/feat
    def test_saving_loading(self):
        self.debug("Pickle Feat object")
    
        reg = clone(self.reg) 
        reg.fit(self.X, self.yr)
        initial_pred = reg.predict(self.X)
        reg.save('Feat_tmp.json')

        loaded_reg = Feat().load('Feat_tmp.json')
        # print('loaded_reg:',type(loaded_reg).__name__)
        loaded_pred = loaded_reg.predict(self.X)
        # print('initial pred:',initial_pred)
        # print('loaded pred:',loaded_pred)
        diff = np.abs(initial_pred-loaded_pred)
        for i,d in enumerate(diff):
            if d > 0.0001:
                print('pred:',initial_pred[i],'loaded:',loaded_pred[i],
                      'diff:',d)
            assert(d < 0.0001)
        # assert(all([ip==lp for ip,lp in zip(initial_pred, loaded_pred)]))

        assert(reg.get_representation() == loaded_reg.get_representation())
        assert(reg.get_model() == loaded_reg.get_model())
        assert((reg.get_coefs() == loaded_reg.get_coefs()).all())
        loaded_params = loaded_reg.get_params()
        # print('\n',10*'=','\n')
        # print('loaded_params:')
        # for k,v in loaded_params.items():
        #     print(k,':',v)

        for k,v in reg.get_params().items():
            if k not in loaded_params.keys():
                print(k,'not in ',loaded_params.keys())
                assert(k in loaded_params.keys())
            if isinstance(v,float):
                if np.abs(loaded_params[k] - v) > 0.0001:
                    print('loaded_params[',k,'] =',
                      loaded_params[k], '\nwhich is different from:', v)
                assert(np.abs(loaded_params[k] - v) < 0.0001)
            elif loaded_params[k] != v:
                print('loaded_params[',k,'] =',
                      loaded_params[k], '\nwhich is different from:', v)
                assert(loaded_params[k] == v)

        loaded_reg.fit(self.X, self.yr)
예제 #3
0
for train_idx, test_idx in kf.split(X, y):
    # print('train_idx:',train_idx)
    clf.fit(X[train_idx], y[train_idx], zfile, train_idx)
    scores.append(clf.score(X[test_idx], y[test_idx], zfile, test_idx))

print('scores:', scores)

###################################################################################################
# fit to all data
###################################################################################################

print('fitting longer to all data...')
clf.gens = 20
clf.verbosity = 2
clf.fit(X, y, zfile, np.arange(len(X)))
print('model:', clf.get_model())

##################################################################################################
# Plot t-SNE transformation
###################################################################################################

print('transform:')
Phi = clf.transform(X, zfile, np.arange(len(X)))
# use t-SNE to visualize transformation
import sklearn
from sklearn.manifold import TSNE
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.patheffects as PathEffects

proj = TSNE(random_state=42).fit_transform(Phi)