def testEvaluateTwoFormulas(self):
     if IGNORE_TEST:
         return
     self.column_a.setFormula(
         SECOND_VALID_FORMULA)  # Make A a formula column
     evaluator = TableEvaluator(self.table)
     error = evaluator.evaluate(user_directory=TEST_DIR)
     self.assertIsNone(error)
Exemple #2
0
 def export(self, **kwargs):
   """
   Exports the table to a python program
   :return: error - string from the file export
   """
   table_evaluator = TableEvaluator(self)
   error = table_evaluator.export(**kwargs)
   return error
 def testEvaluateError(self):
     if IGNORE_TEST:
         return
     column_invalid_formula = cl.Column(COLUMN_INVALID_FORMULA)
     column_invalid_formula.setFormula(INVALID_FORMULA)
     self.table.addColumn(column_invalid_formula)
     evaluator = TableEvaluator(self.table)
     error = evaluator.evaluate(user_directory=TEST_DIR)
     self.assertIsNotNone(error)
Exemple #4
0
 def evaluate(self, user_directory=None):
   """
   Evaluates formulas in the table
   :param user_directory: full directory path where user modules
                           are placed
   :return: error from table evaluation or None
   """
   evaluator = TableEvaluator(self)
   error = evaluator.evaluate(user_directory=user_directory)
   return error
def main():
    cat_cols_test = ['firstname', 'lastname', 'address']

    real, fake = load_data('data/test-data-real.csv',
                           'data/test-data-fake.csv')
    table_evaluator_test = TableEvaluator(real, fake, cat_cols=cat_cols_test)

    for category in cat_cols_test:
        print(category + " Statistics")
        table_evaluator_test.evaluate(target_col=category)
        print("-------------------------------")
    def testRunningSheetWithExport(self):
        if IGNORE_TEST:
            return
        """
    Imports two sheets. The first is the Michaelis-Menten sheet. The second
    is a sheet with S, V, V_MAX, K_M. This test:
     1. Exports the first sheet
     2. Changes the V_MAX formula in the second sheet to use the export
     3. Evaluates the second sheet
    """
        def isEqualColumns(table1, table2, colnm):
            """
      Checks that the tables have the same value for the column name
      :param Table table1:
      :param Table table2:
      :param str colnm:
      """
            value1 = table1.columnFromName(colnm).getCells()[0]
            value2 = table2.columnFromName(colnm).getCells()[0]
            self.assertEqual(value1, value2)

        function_name = "MM"
        # Read the tables
        table1 = api_util.readObjectFromFile(join(TEST_DIR, FILE1))
        table2 = api_util.readObjectFromFile(join(TEST_DIR, FILE1))
        # Set V_MAX in the second table to a dummy value
        column_v_max_second = table2.columnFromName("V_MAX")
        column_v_max_second.setFormula("range(10)")
        evaluator = TableEvaluator(table2)
        evaluator.evaluate(user_directory=TEST_DIR)
        # Use the exported first table for the values of V_MAX, K_M
        table1.export(function_name=function_name,
                      inputs=["S", "V"],
                      outputs=["V_MAX", "K_M"],
                      user_directory=TEST_DIR)
        formula = "V_MAX, K_M = %s(S, V)" % function_name
        column_v_max_second.setFormula(formula)
        evaluator = TableEvaluator(table2)
        evaluator.evaluate(user_directory=TEST_DIR)
        isEqualColumns(table1, table2, "V_MAX")
        isEqualColumns(table1, table2, "K_M")
 def setUp(self):
     """
 Creates the following structure:
 DUMMY_TABLE
   row:
     DUMMY1:
     A:
     B:
     C:
     VALID_FORMULA:
 """
     self.table = createTable(TABLE_NAME)
     self._addColumn(COLUMN1, cells=COLUMN1_CELLS)
     self.column_a = self._addColumn(COLUMN2, cells=COLUMN2_CELLS)
     self.column_b = self._addColumn(COLUMNB, cells=COLUMNB_CELLS)
     self.column_c = self._addColumn(COLUMNC, cells=COLUMNC_CELLS)
     self.column_valid_formula = self._addColumn(COLUMN_VALID_FORMULA,
                                                 formula=VALID_FORMULA)
     api_util.writeObjectToFile(self.table)
     self.evaluator = TableEvaluator(self.table)
Exemple #8
0
                ax.set_zlim(data['Test'][z].min() - 10,
                            data['Test'][z].max() + 10)

                if i == 4:
                    ax.set_xlabel(x)
                    ax.set_ylabel(y)
                    ax.set_zlabel(z)

                ax.set_title(dataset, fontsize=14)
            plt.tight_layout()

            plt.show()

        dataset = 'MIAMI'
        cols = ['age', 'workclass', 'marital.status']
        table_evaluator = TableEvaluator(data['Test'][cols],
                                         data[dataset][cols])

        table_evaluator.plot_distributions()

        #==========================================
        # Correlation matrices
        #==========================================

        w_ratios = [1] * len(plot_datasets) + [0.08]
        fig, axs = plt.subplots(1, len(plot_datasets) + 1, \
                                gridspec_kw={'width_ratios':w_ratios}, figsize = (15,10))

        axs[0].get_shared_y_axes().join(*axs[1:-1])
        #fig.suptitle(design + ' ' + ' (preds' + str(idx) + ')',\
        #fontsize=16)
        for idx, mod in enumerate(ord_modalities):
            train_new['education'] = np.where(
                train_new['education'] == str(float(idx)), mod,
                train_new['education'])

        # Keep only the women that have more than 60 years in the test
        if design in ['Absent', 'Unb']:
            test = test[(test['age'] >= 60) & (test['sex'] == 'Female')]

        # Store the predictions
        train_new.to_csv('pseudo_adult/' + design + '/' + 'preds' + str(filenum) + '.csv',\
                         index = False)

acceptance_rate = pd.DataFrame(acceptance_rate)
acceptance_rate.to_csv('pseudo_adult/acceptance_rate.csv')

acceptance_rate[['Unbalanced', 'Absent']].astype(float).boxplot()
plt.title('Acceptance rate of MIAMI in the Absent and Unbalanced designs')
plt.ylabel('Acceptance rate')
plt.xlabel('Design')

# Visualise the predictions
# Use table_evaluator
plt.plot([0])
plt.title('Design:' + design)
plt.show()
cat_features = (~(pd.Series(var_distrib) != 'continuous')).to_list()
table_evaluator = TableEvaluator(test, train_new)
table_evaluator.visual_evaluation()
 def testConstructor(self):
     if IGNORE_TEST:
         return
     evaluator = TableEvaluator(self.table)
     self.assertEqual(evaluator._table.getName(is_global_name=False),
                      TABLE_NAME)