Exemplo n.º 1
0
    def run_single_patient(self):
        predictor_result = []

        for iteration in range(self.cross_validation):

            if iteration % 10 is 0:
                print(str(iteration) + " ...")

            train_data, pos_test_data, neg_test_data, train_labels = process_data.generate_training_data(
                self.data, break_amount=1, split_percentage=0)

            clf = MLPClassifier(solver='lbfgs',
                                alpha=1e-3,
                                hidden_layer_sizes=(15, 5),
                                random_state=1)
            clf.fit(train_data, train_labels)

            pred_test_probabilities = clf.predict_proba(self.patient_list)

            iteration_result = []
            for row in pred_test_probabilities:
                if row[0] > row[1]:
                    iteration_result.append(["NEG", row[0]])
                else:
                    iteration_result.append(["POS", row[1]])

            predictor_result.append(iteration_result)

        return predictor_result
Exemplo n.º 2
0
    def run_cross_validation(self):
        pos_predictor_result = []
        neg_predictor_result = []
        for iteration in range(self.cross_validation):

            if iteration % 10 is 0:
                print(str(iteration) + " ...")

            train_data, pos_test_data, neg_test_data, train_labels = process_data.generate_training_data(
                self.data, break_amount=1.2, split_percentage=20)

            clf = MLPClassifier(solver='lbfgs',
                                alpha=1e-3,
                                hidden_layer_sizes=(len(self.data.ab_names),
                                                    2),
                                random_state=1)
            clf.fit(train_data, train_labels)

            pos_pred_test = clf.predict(pos_test_data)
            neg_pred_test = clf.predict(neg_test_data)

            pos_predictor_result.append(
                len([1 for x in pos_pred_test if x == "POS"]) /
                float(len(pos_pred_test)))
            neg_predictor_result.append(
                len([1 for x in neg_pred_test if x == "NEG"]) /
                float(len(neg_pred_test)))

        return pos_predictor_result, neg_predictor_result
Exemplo n.º 3
0
    def run_single_patient(self):
        predictor_result = []

        for iteration in range(self.cross_validation):

            if iteration%20 is 0:
                print(str(iteration) + " ...")

            # Create training set (split percentage is 0)
            train_data, pos_test_data, neg_test_data, train_labels = process_data.generate_training_data(self.pos_training_data,
                                                                                                         self.neg_training_data,
                                                                                                         break_amount=1,
                                                                                                         split_percentage=0)

            # Train a perceptron classifier
            clf = MLPClassifier(solver='lbfgs', alpha=1e-3, hidden_layer_sizes=(self.layers[0], self.layers[1]), random_state=0)
            clf.fit(train_data, train_labels)

            # Output prediction probabilities
            pred_test_probabilities = clf.predict_proba(self.patient_list)

            # Append labels
            iteration_result = []
            for row in pred_test_probabilities:
                if row[0] > row[1]:
                    iteration_result.append(["NEG", row[0]])
                else:
                    iteration_result.append(["POS", row[1]])

            predictor_result.append(iteration_result)

        # Process results, sums over all suscebtible and certainty values per patient
        patient_pos_probability = []
        patient_certainty = []
        for patient_index in range(len(self.patient_list)):
            pos_count = 0
            certainty_sum = 0
            for iteration_result in predictor_result:
                if iteration_result[patient_index][0] == "POS":
                    pos_count+=1
                    certainty_sum+=iteration_result[patient_index][1]
            patient_pos_probability.append(pos_count/float(len(predictor_result)))
            patient_certainty.append(certainty_sum/float(len(predictor_result)))
        
        return patient_pos_probability, patient_certainty
Exemplo n.º 4
0
    def run_single_patient(self):
        predictor_result = []

        for iteration in range(self.cross_validation):

            if iteration%2000 is 0:
                print(str(iteration) + " ...")

            train_data, pos_test_data, neg_test_data, train_labels = process_data.generate_training_data(self.pos_training_data,
                                                                                                         self.neg_training_data,
                                                                                                         break_amount=1,
                                                                                                         split_percentage=0)

            clf = tree.DecisionTreeClassifier()
            clf.fit(train_data, train_labels)

            pred_test_probabilities = clf.predict_proba(self.patient_list)

            iteration_result = []
            for row in pred_test_probabilities:
                if row[0] > row[1]:
                    iteration_result.append(["NEG", row[0]])
                else:
                    iteration_result.append(["POS", row[1]])

            predictor_result.append(iteration_result)

        # Process results
        patient_pos_probability = []
        patient_certainty = []
        for patient_index in range(len(self.patient_list)):
            pos_count = 0
            certainty_sum = 0
            for iteration_result in predictor_result:
                if iteration_result[patient_index][0] == "POS":
                    pos_count+=1
                    certainty_sum+=iteration_result[patient_index][1]
            patient_pos_probability.append(pos_count/float(len(predictor_result)))
            patient_certainty.append(certainty_sum/float(len(predictor_result)))

        return patient_pos_probability, patient_certainty
Exemplo n.º 5
0
    def run_cross_validation(self):
        pos_predictor_result = []
        neg_predictor_result = []

        importance = np.zeros(len(self.data.relevant_ab_names))

        for iteration in range(self.cross_validation):

            if iteration%2000 is 0:
                print(str(iteration) + " ...")

            train_data, pos_test_data, neg_test_data, train_labels = process_data.generate_training_data(self.pos_training_data,
                                                                                                         self.neg_training_data,
                                                                                                         break_amount=1,
                                                                                                         split_percentage=10)

            clf = tree.DecisionTreeClassifier()
            clf.fit(train_data, train_labels)

            importance+=clf.feature_importances_

            pos_pred_test = clf.predict(pos_test_data)
            neg_pred_test = clf.predict(neg_test_data)

            pos_predictor_result.append(len([1 for x in pos_pred_test if x == "POS"])/float(len(pos_pred_test)))
            neg_predictor_result.append(len([1 for x in neg_pred_test if x == "NEG"])/float(len(neg_pred_test)))

        print("")
        results = []
        for i in range(len(self.data.relevant_ab_names)):
            results.append([importance[i]/self.cross_validation, self.data.relevant_ab_names[i]])
        results.sort(reverse=True)

        print(self.data.relevant_ab_names)
        for i in range(len(self.data.relevant_ab_names)):
            print("{}: {}".format(results[i][1], results[i][0]))
        print("")

        return pos_predictor_result, neg_predictor_result
Exemplo n.º 6
0
    def run_cross_validation(self):
        pos_predictor_result = []
        neg_predictor_result = []

        self.iteration_timer_estimate = 0

        importance = np.zeros(len(self.data.relevant_ab_names))
        
        for iteration in range(self.cross_validation):

            # Start of timer
            iteration_start = time()

            if iteration%50 is 0:
                print(str(iteration) + " ...")
                print("Time left: {}".format((self.iteration_timer_estimate/(iteration+1))*(self.cross_validation-iteration)))

            # Split dataset into train and test
            train_data, pos_test_data, neg_test_data, train_labels = process_data.generate_training_data(self.pos_training_data,
                                                                                                         self.neg_training_data,
                                                                                                         break_amount=1,
                                                                                                         split_percentage=10)

            # Train percpetron on training set
            clf = MLPClassifier(solver='lbfgs', alpha=1e-3, hidden_layer_sizes=(self.layers[0], self.layers[1]), random_state=0)
            clf.fit(train_data, train_labels)

            # Test the classification on a test and control set
            pos_pred_test = clf.predict(pos_test_data)
            neg_pred_test = clf.predict(neg_test_data)

            # Calculate accuracy and store it
            pos_predictor_result.append(len([1 for x in pos_pred_test if x == "POS"])/float(len(pos_pred_test)))
            neg_predictor_result.append(len([1 for x in neg_pred_test if x == "NEG"])/float(len(neg_pred_test)))

            self.iteration_timer_estimate+=(time()-iteration_start)

        return pos_predictor_result, neg_predictor_result