How to use the mindsdb.libs.helpers.general_helpers.get_label_index_for_value function in MindsDB

To help you get started, we’ve selected a few MindsDB examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mindsdb / mindsdb / mindsdb / libs / workers / train.py View on Github external
'real_x_predicted_dist': [[0 for i in reduced_buckets] for j in reduced_buckets],
                        'real_x_predicted': [[0 for i in reduced_buckets] for j in reduced_buckets]
                    }
                }
            else:
                #TODO: Smarter way to deal with reduced buckets for other data types
                reduced_buckets = confusion_matrices[col]['labels']
                reduced_confusion_matrices = copy.copy(confusion_matrices)

        # calculate confusion matrices real vs predicted
        for col in predicted_targets:
            totals = [0] * len(self.persistent_model_metadata.column_stats[col]['histogram']['x'])
            reduced_totals = [0] * len(reduced_buckets)
            for i, predicted_value in enumerate(predicted_targets[col]):
                predicted_index = get_label_index_for_value(predicted_value, confusion_matrices[col]['labels'])
                real_index = get_label_index_for_value(real_targets[col][i], confusion_matrices[col]['labels'])
                confusion_matrices[col]['real_x_predicted_dist'][real_index][predicted_index] += 1
                totals[predicted_index] += 1

                reduced_predicted_index = get_label_index_for_value(predicted_value,
                                                                    reduced_confusion_matrices[col]['labels'])
                reduced_real_index = get_label_index_for_value(real_targets[col][i],
                                                               reduced_confusion_matrices[col]['labels'])
                reduced_confusion_matrices[col]['real_x_predicted_dist'][reduced_real_index][
                    reduced_predicted_index] += 1
                reduced_totals[reduced_predicted_index] += 1

            # calculate probability of predicted being correct P(predicted=real|predicted)
            for pred_j, label in enumerate(confusion_matrices[col]['labels']):
                for real_j, label in enumerate(confusion_matrices[col]['labels']):
                    if totals[pred_j] == 0:
                        confusion_matrices[col]['real_x_predicted'][real_j][pred_j] = 0
github mindsdb / mindsdb / mindsdb / libs / workers / train.py View on Github external
'labels': reduced_buckets,
                        'real_x_predicted_dist': [[0 for i in reduced_buckets] for j in reduced_buckets],
                        'real_x_predicted': [[0 for i in reduced_buckets] for j in reduced_buckets]
                    }
                }
            else:
                #TODO: Smarter way to deal with reduced buckets for other data types
                reduced_buckets = confusion_matrices[col]['labels']
                reduced_confusion_matrices = copy.copy(confusion_matrices)

        # calculate confusion matrices real vs predicted
        for col in predicted_targets:
            totals = [0] * len(self.persistent_model_metadata.column_stats[col]['histogram']['x'])
            reduced_totals = [0] * len(reduced_buckets)
            for i, predicted_value in enumerate(predicted_targets[col]):
                predicted_index = get_label_index_for_value(predicted_value, confusion_matrices[col]['labels'])
                real_index = get_label_index_for_value(real_targets[col][i], confusion_matrices[col]['labels'])
                confusion_matrices[col]['real_x_predicted_dist'][real_index][predicted_index] += 1
                totals[predicted_index] += 1

                reduced_predicted_index = get_label_index_for_value(predicted_value,
                                                                    reduced_confusion_matrices[col]['labels'])
                reduced_real_index = get_label_index_for_value(real_targets[col][i],
                                                               reduced_confusion_matrices[col]['labels'])
                reduced_confusion_matrices[col]['real_x_predicted_dist'][reduced_real_index][
                    reduced_predicted_index] += 1
                reduced_totals[reduced_predicted_index] += 1

            # calculate probability of predicted being correct P(predicted=real|predicted)
            for pred_j, label in enumerate(confusion_matrices[col]['labels']):
                for real_j, label in enumerate(confusion_matrices[col]['labels']):
                    if totals[pred_j] == 0:
github mindsdb / mindsdb / mindsdb / libs / workers / train.py View on Github external
reduced_buckets = confusion_matrices[col]['labels']
                reduced_confusion_matrices = copy.copy(confusion_matrices)

        # calculate confusion matrices real vs predicted
        for col in predicted_targets:
            totals = [0] * len(self.persistent_model_metadata.column_stats[col]['histogram']['x'])
            reduced_totals = [0] * len(reduced_buckets)
            for i, predicted_value in enumerate(predicted_targets[col]):
                predicted_index = get_label_index_for_value(predicted_value, confusion_matrices[col]['labels'])
                real_index = get_label_index_for_value(real_targets[col][i], confusion_matrices[col]['labels'])
                confusion_matrices[col]['real_x_predicted_dist'][real_index][predicted_index] += 1
                totals[predicted_index] += 1

                reduced_predicted_index = get_label_index_for_value(predicted_value,
                                                                    reduced_confusion_matrices[col]['labels'])
                reduced_real_index = get_label_index_for_value(real_targets[col][i],
                                                               reduced_confusion_matrices[col]['labels'])
                reduced_confusion_matrices[col]['real_x_predicted_dist'][reduced_real_index][
                    reduced_predicted_index] += 1
                reduced_totals[reduced_predicted_index] += 1

            # calculate probability of predicted being correct P(predicted=real|predicted)
            for pred_j, label in enumerate(confusion_matrices[col]['labels']):
                for real_j, label in enumerate(confusion_matrices[col]['labels']):
                    if totals[pred_j] == 0:
                        confusion_matrices[col]['real_x_predicted'][real_j][pred_j] = 0
                    else:
                        confusion_matrices[col]['real_x_predicted'][real_j][pred_j] = \
                        confusion_matrices[col]['real_x_predicted_dist'][real_j][pred_j] / totals[pred_j]

            for pred_j, label in enumerate(reduced_confusion_matrices[col]['labels']):
                for real_j, label in enumerate(reduced_confusion_matrices[col]['labels']):
github mindsdb / mindsdb / mindsdb / libs / workers / train.py View on Github external
else:
                #TODO: Smarter way to deal with reduced buckets for other data types
                reduced_buckets = confusion_matrices[col]['labels']
                reduced_confusion_matrices = copy.copy(confusion_matrices)

        # calculate confusion matrices real vs predicted
        for col in predicted_targets:
            totals = [0] * len(self.persistent_model_metadata.column_stats[col]['histogram']['x'])
            reduced_totals = [0] * len(reduced_buckets)
            for i, predicted_value in enumerate(predicted_targets[col]):
                predicted_index = get_label_index_for_value(predicted_value, confusion_matrices[col]['labels'])
                real_index = get_label_index_for_value(real_targets[col][i], confusion_matrices[col]['labels'])
                confusion_matrices[col]['real_x_predicted_dist'][real_index][predicted_index] += 1
                totals[predicted_index] += 1

                reduced_predicted_index = get_label_index_for_value(predicted_value,
                                                                    reduced_confusion_matrices[col]['labels'])
                reduced_real_index = get_label_index_for_value(real_targets[col][i],
                                                               reduced_confusion_matrices[col]['labels'])
                reduced_confusion_matrices[col]['real_x_predicted_dist'][reduced_real_index][
                    reduced_predicted_index] += 1
                reduced_totals[reduced_predicted_index] += 1

            # calculate probability of predicted being correct P(predicted=real|predicted)
            for pred_j, label in enumerate(confusion_matrices[col]['labels']):
                for real_j, label in enumerate(confusion_matrices[col]['labels']):
                    if totals[pred_j] == 0:
                        confusion_matrices[col]['real_x_predicted'][real_j][pred_j] = 0
                    else:
                        confusion_matrices[col]['real_x_predicted'][real_j][pred_j] = \
                        confusion_matrices[col]['real_x_predicted_dist'][real_j][pred_j] / totals[pred_j]