def running(dx, withData=True, compare=True, proj="M", filename="fullData.txt"): """ dx gives the resolution, dx=1 for 1x1 grid withData is a boolean, withData=True plots the data points on top the map projection has the same options as gmt, Mercator projection is the default filename is the name of the file that stores the data """ """ Reading data """ theta0 = [600000] for theta in theta0: xpoints = np.arange(-180, 180, dx) ypoints = np.arange(-90 + dx, 90, dx) if filename.endswith("txt"): rawData = readData.readTxt(filename) elif filename.endswith("xlsx"): rawData = readData.readCols(filename) else: print "I don't think I can handle this format" return """ Classifier being trained """ rfc = mapping.training(rawData) """ Map being made with the classifier """ data = [(rawData["lon"][i], rawData["lat"][i]) for i in range(len(rawData["lon"]))] labels = [mapping.downLabels(i) for i in rawData["classif"]] data, labels = mapping.cleanDoubles(data, labels) scores = cross_val_score(rfc, data, labels, cv=5) print ("Accuracy: %0.2f (+/- %0.2f)" % (scores.mean(), scores.std() * 2)) prediction = mapping.mapping(xpoints, ypoints, rfc) """ Map being written to a file """ writeResults.writePredictions( xpoints, ypoints, prediction, header="> Predictions made with training.py", newFilename="seabed_lithology_regular_grid.txt", ) """ GMT file written """ writeResults.makeMap(dx, withData, proj) """ Postscript called to call gmt """ writeResults.gmtMap() print len(rawData["lon"]), len(rawData["classif"]) """ Statisctics being compared """ if compare: compareStats(rawData, theta)
def blocks(dx, filename, theta, withData=False, proj="M", xBlockRange=[-180, 180], yBlockRange=[-90, 90]): xpoints = np.arange(-180, 180, dx) ypoints = np.arange(-90 + dx, 90, dx) rawData = readData.readCols(filename) rfc = blockTraining(rawData, theta, xBlockRange, yBlockRange) prediction = blockPredict(rfc, xpoints, ypoints, xBlockRange, yBlockRange) writeResults.writePredictions( xpoints, ypoints, prediction, header="> Predictions made with training.py", newFilename="seabed_lithology_blocks_regular_grid.txt", ) writeResults.makeMap(dx, withData, proj) writeResults.gmtMap()
# print('y_pred = ' + str(y_pred[:50])) y_length = y_pred.shape[0] precision = correctNum / y_length for labelID in range(labelNum): print(' stageLabel = ' + stageLabels[labelID] + ', sensitivity = ' + "{0:.3f}".format(sensitivity[labelID]) + ', specificity = ' + "{0:.3f}".format(specificity[labelID]) + ', accuracy = ' + "{0:.3f}".format(accuracy[labelID])) sensitivityMat[markovOrder, labelID] = sensitivity[labelID] specificityMat[markovOrder, labelID] = specificity[labelID] accuracyMat[markovOrder, labelID] = accuracy[labelID] print(' precision = ' + "{0:.5f}".format(precision) + ' (= ' + str(correctNum) + '/' + str(y_length) + ')') precisions[markovOrder] = precision print('') resultFileDescription = 'markov.' + str(markovOrder) writePredictions(fileID, params, y_test, y_pred, resultFileDescription) saveData = (sensitivityMat, specificityMat, accuracyMat, precisions) outpath = open(pickledDir + '/res.testMarkovOrders.pkl', 'wb') pickle.dump(saveData, outpath) print('in the final summary:') print('classifier type = ' + str(classifierType)) print('useEMG = ' + str(params.useEMG)) print('emgTimeFrameNum = ' + str(params.emgTimeFrameNum)) print('binWidth4freqHisto = ' + str(params.binWidth4freqHisto)) print('precisions by different orders:') for markovOrder in range(orderMin, orderMax + 1): print(str(markovOrder) + ', ' + "{0:.5f}".format(precisions[markovOrder]))