示例#1
0
    def statistics_olr(self, m):
        if m is None:
            return None

        columns = [
            variable.String("Variable"),
            variable.Continuous("Coeff Est"),
            variable.Continuous("Std Error"),
            variable.Continuous("t-value"),
            variable.Continuous("p")
        ]

        domain = Orange.data.Domain(columns, None)
        vars = ["Intercept"] if m.intercept else []
        vars.extend([a.name for a in m.domain.attributes])
        stats = []
        geti = lambda list, i: list[i] if list is not None else "?"

        for i, var in enumerate(vars):
            coef = m.coefficients[i]
            std_err = geti(m.std_error, i)
            t_val = geti(m.t_scores, i)
            p = geti(m.p_vals, i)
            stats.append([var, coef, std_err, t_val, p])

        return Orange.data.Table(domain, stats)
def prepare_dataset(components=((),), n=150):
    components = components if isinstance(components, np.ndarray) else np.array(components)

    ncomponents, m = components.shape
    coefficients = np.random.normal(0., 1., (n, ncomponents))

    d = np.dot(coefficients, components)

    domain = data.Domain([feature.Continuous("A%d" % i) for i in range(m)], False)
    return domain, d
示例#3
0
def matrix_to_table(matrix, items=None):
    if items is None:
        items = getattr(matrix, "items", None)
    if items is None:
        items = range(matrix.dim)

    items = map(str, items)

    attrs = [variable.Continuous(name) for name in items]
    domain = Orange.data.Domain(attrs, None)
    row_name = variable.String("Row name")
    domain.addmeta(Orange.feature.Descriptor.new_meta_id(), row_name)

    table = Orange.data.Table(domain, [list(r) for r in matrix])
    for item, row in zip(items, table):
        row[row_name] = item

    return table
示例#4
0
    def commit(self):
        from Orange import feature as variable
        name_mapper = {"Mahalanobis absolute": "Mahalanobis"}
        all_predictions = []
        all_estimates = []
        score_vars = []
        features = []
        table = None
        if self.learner and self.train_data is not None \
                and self._test_data() is not None:
            self.run()

            scores = []
            if self.include_class and not self.include_input_features:
                original_class = self._test_data().domain.class_var
                features.append(original_class)

            if self.include_class:
                prediction_var = variable.Continuous("Prediction")
                features.append(prediction_var)

            if self.include_error:
                error_var = variable.Continuous("Error")
                abs_error_var = variable.Continuous("Abs. Error")
                features.append(error_var)
                features.append(abs_error_var)

            for estimates, (selected, method, _,
                            _) in zip(self.results, self.estimators):
                if estimates is not None and getattr(self, selected):
                    for estimate in estimates:
                        name = estimate[0].method_name
                        name = name_mapper.get(name, name)
                        var = variable.Continuous(name)
                        features.append(var)
                        score_vars.append(var)
                        all_estimates.append(estimate)

            if self.include_input_features:
                dom = self._test_data().domain
                attributes = list(dom.attributes) + features
                domain = Orange.data.Domain(attributes, dom.class_var)
                domain.add_metas(dom.get_metas())

                data = Orange.data.Table(domain, self._test_data())
            else:
                domain = Orange.data.Domain(features, None)
                data = Orange.data.Table(domain, [[None] * len(features)
                                                  for _ in self._test_data()])

            if self.include_class:
                for d, inst, pred in zip(data, self._test_data(),
                                         self.predictions):
                    if not self.include_input_features:
                        d[features[0]] = float(inst.get_class())
                    d[prediction_var] = float(pred)

            if self.include_error:
                for d, inst, pred in zip(data, self._test_data(),
                                         self.predictions):
                    error = float(pred) - float(inst.get_class())
                    d[error_var] = error
                    d[abs_error_var] = abs(error)

            for estimations, var in zip(all_estimates, score_vars):
                for d, e in zip(data, estimations):
                    d[var] = e.estimate

            table = data

        self.send("Reliability Scores", table)
        self.output_changed = False