示例#1
0
def test_gamma_C(x_arr, y_arr, itraining, K_chk, y_chk,
                 get_ml, get_kernel=None):
    shp = (len(y_arr), len(x_arr))
    pnl = pd.Panel(data=[np.zeros(shp), np.zeros(shp)],
                   items=['error', 'accuracy'],
                   major_axis=y_arr, minor_axis=x_arr)
    for g in x_arr:
        for c in y_arr:
            print "computing g=%r, c=%r" % (g, c)
            ml = get_ml(g, c, get_kernel)
            y_all = cls(ml, itraining, K_chk, y_chk)
            pnl['error'][g][c] = mlpy.error(y_chk, y_all[y_chk.index])
            pnl['accuracy'][g][c] = mlpy.accuracy(y_chk, y_all[y_chk.index])
    return pnl
示例#2
0
#ACCURACY measure CLASSIFICATION
import mlpy
t = [3,2,3,3,3,1,1,1]
p = [3,2,1,3,3,2,1,1]
mlpy.error(t, p)
mlpy.accuracy(t, p)


#Sensitivity, Specitivity, AUC
import mlpy
t = [1, 1, 1,-1, 1,-1,-1,-1]
p = [1,-1, 1, 1, 1,-1, 1,-1]
mlpy.error_p(t, p)
mlpy.error_n(t, p)
mlpy.sensitivity(t, p)
mlpy.specificity(t, p)
mlpy.ppv(t, p)
mlpy.npv(t, p)
mlpy.mcc(t, p)
p = [2.3,-0.4, 1.6, 0.6, 3.2,-4.9, 1.3,-0.3]
mlpy.auc_wmw(t, p)
p = [2.3,0.4, 1.6, -0.6, 3.2,-4.9, -1.3,-0.3]
mlpy.auc_wmw(t, p)


#Mean Squared Error REGRESSION
import mlpy
t = [2.4,0.4,1.2,-0.2,3.3,-4.9,-1.1,-0.1]
p = [2.3,0.4,1.6,-0.6,3.2,-4.9,-1.3,-0.3]
mlpy.mse(t, p)
示例#3
0
        test_y = train_y[:split_index]
        train_X = train_X[split_index:]
        train_y = train_y[split_index:]
        print strftime("%Y-%m-%d %H:%M:%S", gmtime()), ": Parsing complete!\n"
    else:
        print strftime("%Y-%m-%d %H:%M:%S", gmtime()), ": Parsing test data..."
        # Parsing test input data
        data_reader = csv.reader(open(input_test_file, 'rb'), delimiter = ",")
        data_reader.next() # Skip the first line, since it contains the labels
        test_X = []
        for row in data_reader:
            line_x = [1]
            for i in range(len(row)):
                line_x.append(float(row[i]))
            test_X.append(line_x)
        print strftime("%Y-%m-%d %H:%M:%S", gmtime()), ": Finished parsing test data!"
    
    predicted_labels = Predict_svm(train_X, train_y, test_X)
    print strftime("%Y-%m-%d %H:%M:%S", gmtime()), ": Finished predicting!"

    if crossval == True:
        # Only useful for cross-validation, otherwise test_y is unknown and we get error=1/accuracy=0
        print "Error: ", mlpy.error(test_y, predicted_labels)
        print "Accuracy: ", mlpy.accuracy(test_y, predicted_labels)
    else:
        print strftime("%Y-%m-%d %H:%M:%S", gmtime()), ": Writing predicted labels to file..."    
        prediction_filename = "test_" + strftime("%Y-%m-%d_%H-%M-%S", gmtime()) + ".csv"
        prediction_writer = csv.writer(open(prediction_filename, 'wb'))
        for row in predicted_labels:
            list_row = [row]
            prediction_writer.writerow(list_row)