def exp_titanic_id_static(print, pprint): dataset = DatasetPackLoader().load_dataset("titanic") dataset = dataset.set['train'] ret_dict = {} n = 100 for i in range(n): clf_pack = ClassifierPack() dataset.shuffle() train_set, valid_set = dataset.split((7, 3)) train_Xs, train_Ys = train_set.full_batch(['Xs', 'Ys']) clf_pack.fit(train_Xs, train_Ys) dataset.sort() full_Xs, full_Ys = dataset.full_batch(['Xs', 'Ys']) predict = clf_pack.predict(full_Xs) for key in predict: if key in ret_dict: ret_dict[key] += predict[key] / float(n) else: ret_dict[key] = predict[key] / float(n) import pandas as pd df = pd.DataFrame() for key in ret_dict: df[key] = ret_dict[key] for key in dataset.BATCH_KEYS: if key in ['Xs', 'Ys']: continue print(key, type(key)) df[key] = dataset.full_batch([key]) df.to_csv('./exp_titianic_id_result.csv', )
def test_titanic(self): class_ = self.class_ dataset = DatasetPackLoader().load_dataset("titanic") dataset = dataset.train_set Xs, Ys = dataset.full_batch(['Xs', 'Ys']) sample_X = Xs[:2] sample_Y = Ys[:2] model = class_(dataset.input_shapes) model.build() model.train(Xs, Ys, epoch=1) code = model.code(sample_X) print("code {code}".format(code=code)) recon = model.recon(sample_X, sample_Y) print("recon {recon}".format(recon=recon)) loss = model.metric(sample_X, sample_Y) print("loss {:}".format(loss)) # generate(self, zs, Ys) proba = model.proba(sample_X) print("proba {}".format(proba)) predict = model.predict(sample_X) print("predict {}".format(predict)) score = model.score(sample_X, sample_Y) print("score {}".format(score)) path = model.save() model = class_() model.load(path) print('model reloaded') code = model.code(sample_X) print("code {code}".format(code=code)) recon = model.recon(sample_X, sample_Y) print("recon {recon}".format(recon=recon)) loss = model.metric(sample_X, sample_Y) print("loss {:}".format(loss)) # generate(self, zs, Ys) proba = model.proba(sample_X) print("proba {}".format(proba)) predict = model.predict(sample_X) print("predict {}".format(predict)) score = model.score(sample_X, sample_Y) print("score {}".format(score))
def test_titanic(self): class_ = DAE dataset = DatasetPackLoader().load_dataset("titanic") dataset = dataset.train_set model = class_(dataset.input_shapes) model.build() Xs = dataset.full_batch(['Xs']) model.train(Xs, epoch=1) sample_X = Xs[:2] code = model.code(sample_X) print("code {code}".format(code=code)) recon = model.recon(sample_X) print("recon {recon}".format(recon=recon)) loss = model.metric(Xs) loss = np.mean(loss) print("loss {:.4}".format(loss)) path = model.save() model = class_() model.load(path) print('model reloaded') sample_X = Xs[:2] code = model.code(sample_X) print("code {code}".format(code=code)) recon = model.recon(sample_X) print("recon {recon}".format(recon=recon)) loss = model.metric(Xs) loss = np.mean(loss) print("loss {:.4}".format(loss))
def test_mnist(self): class_ = self.class_ dataset = DatasetPackLoader().load_dataset("MNIST") dataset = dataset.train_set Xs, Ys = dataset.full_batch(['Xs', 'Ys']) sample_X = Xs[:2] sample_Y = Ys[:2] model = class_(dataset.input_shapes) model.build() model.train(Xs, Ys, epoch=1) code = model.code(sample_X, sample_Y) print("code {code}".format(code=code)) recon = model.recon(sample_X, sample_Y) print("recon {recon}".format(recon=recon)) loss = model.metric(sample_X, sample_Y) loss = np.mean(loss) print("loss {:.4}".format(loss)) path = model.save() model = class_() model.load(path) print('model reloaded') code = model.code(sample_X, sample_Y) print("code {code}".format(code=code)) recon = model.recon(sample_X, sample_Y) print("recon {recon}".format(recon=recon)) loss = model.metric(sample_X, sample_Y) loss = np.mean(loss) print("loss {:.4}".format(loss))