Beispiel #1
0
def _spearman_r(X, Y):
    """
    Calculates a Spearman rank-order correlation coefficient
    and the p-value to test for non-correlation.
    """
    rho, p_value = spearman(X, Y)
    return rho
Beispiel #2
0
def _spearman_r(X, Y):
    """
    Calculates a Spearman rank-order correlation coefficient
    and the p-value to test for non-correlation.
    """
    rho, p_value = spearman(X, Y)
    return rho
Beispiel #3
0
    def __get_speaker_accommodation(self, speaker: str):
        accommodationPath = self.cfg.paths[
            'accommPath'] + speaker + self.fileSuffix

        for task in self.__get_tasks(speaker):
            with open(accommodationPath, 'r') as f:
                reader = csv.reader(f)

                times, distances = self.__extract_task_ratios(reader, task)
                correlation = stats.spearman(times, distances)
                spearCoefficient = correlation[0]
                pValue = correlation[1]
                taskLength = max(
                    times
                )  # Approximate the task end by the start of the last word.

                row = [
                    speaker + " " + task, spearCoefficient,
                    abs(spearCoefficient), pValue, taskLength
                ]
                print(",".join(row))
pos2 = np.stack(([values_LesothoN,values_SAN]),axis = 0)
print(np.cov(pos1))
print(np.cov(pos2))
rv = mvn([mean_Lesotho,mean_SA],np.cov(pos1))
rv1 = mvn([mean_LesothoN,mean_SAN],np.cov(pos2))

x1,y1 = np.mgrid[300:450:0.5, 300:400:0.5]
posnew = np.dstack((x1,y1))


levels = [0.01,0.05, 0.10, 0.50, 0.90,0.95,0.99]
levels1 = [0.88,0.90,0.91,0.92,0.93, 0.94,0.95, 0.96,0.965,0.97, 0.975,0.976,0.977,0.978,0.979,0.98,0.981,0.982,0.983,0.985,0.987, 0.99,0.991, 0.992, 0.993, 0.994,0.995, 0.996, 0.997, 0.998, 0.999]


kendal = kdtau(values_Lesotho,values_SA)
spearman = spearman(values_Lesotho,values_SA)
print(kendal)
print(spearman[0])

####
data_normalized = pd.DataFrame({'val-L':values_Lesotho-np.mean(values_Lesotho),'val-SA': values_SA-np.mean(values_SA)})
data_normalized_N = pd.DataFrame({'val-L':values_LesothoN-np.mean(values_LesothoN),'val-SA': values_SAN-np.mean(values_SAN)})

data_small = data_normalized[data_normalized['val-L']<0 & (data_normalized['val-SA'] < 0)]
data_small1 = data_normalized_N[data_normalized_N['val-L']<0 & (data_normalized_N['val-SA'] < 0)]
print(np.corrcoef(data_small['val-L'],data_small['val-SA']))
print(np.corrcoef(data_small1['val-L'],data_small1['val-SA']))

fig, ax = plt.subplots()
ax.plot(values_Lesotho,values_SA,'ro',markersize='2.0')
ax.plot(values_LesothoN,values_SAN,'bo', markersize='2.0')
    plt.title('Receiver Operating Characteristic')
    plt.plot(fpr, tpr, 'b', label = 'AUC = %0.2f' % roc_auc)
    plt.legend(loc = 'lower right')
    plt.plot([0, 1], [0, 1],'r--')
    plt.xlim([0, 1])
    plt.ylim([0, 1])
    plt.ylabel('True Positive Rate')
    plt.xlabel('False Positive Rate')
    plt.show()

plot_roc_curve()


### SCC and PCC

scc = stats.spearman(pred, targets)
def plot_scc():
    plt.title('Spearmans Correlation Coefficient')
    plt.scatter(y_test.flatten().detach().numpy(), pred.flatten().detach().numpy(), label = 'SCC = %0.2f' % scc)
    plt.legend(loc = 'lower right')
    plt.ylabel('Predicted')
    plt.xlabel('Validation targets')
    plt.show()


pcc = stats.pearsonr(pred, targets)
def plot_scc():
    plt.title('Pearsons Correlation Coefficient')
    plt.scatter(y_test.flatten().detach().numpy(), pred.flatten().detach().numpy(), label = 'PCC = %0.2f' % pcc)
    plt.legend(loc = 'lower right')
    plt.ylabel('Predicted')