def predictIntegratedConfidence(measure): """ generates a plot of predicted confidence by integrating two individual target group confidences, with weightings based off of inverse standard deviation squared. Measure takes either value "warmth" or "competence" """ global normalized intWarmthMap, intCompMap = parser.extractInformation(parser.getMappings(normalized)[0], parser.getMappings(normalized)[1]) print(intWarmthMap) predictedList = [] observedList = [] labels = [] if measure == "warmth": mapping = intWarmthMap if measure == "competence": mapping = intCompMap for key in mapping.keys(): if "_" in key: g1 = key.split("_")[0] g2 = key.split("_")[1] confidence1 = mapping[g1][2] sig1 = mapping[g1][3] confidence2 = mapping[g2][2] sig2 = mapping[g2][3] sigNew = (math.pow(sig1,2) * math.pow(sig2, 2)) \ / float((math.pow(sig1,2) + math.pow(sig2, 2))) inv1 = 1 / float((math.pow(sig1, 2))) inv2 = 1 / float((math.pow(sig2, 2))) sumInverses = inv1 + inv2 ##inverse standard deviations squared w1 = inv1 / float(sumInverses) w2 = inv2 / float(sumInverses) predValue = confidence1 * w1 + confidence2 * w2 predictedList.append(predValue) observedList.append(mapping[key][2]) labels.append(key) fig = plt.figure(1) ax = fig.add_subplot(111) plt.axis([50, 100, 50, 100]) if normalized == True: plt.axis([0, 100, 0, 100]) plt.scatter(observedList, predictedList) plt.plot([0,100], [0,100]) slope, intercept, r_value, p_value, std_err = stats.linregress(observedList, predictedList) text = ax.text(70, 60, "R^2 value: " + str(r_value**2) , \ fontsize = 12, color = 'black') plt.title("Observed vs Predicted " + measure.title() + " Confidence") plt.xlabel("Observed") plt.ylabel("Predicted") plt.savefig("Confidence/predicted" + measure + 'Integrated.png') plt.show()
def visualizeTargets(): """ generates graph of individual target ratings, based off of Ming's csv file for averaged warmth and competence values """ global normalized intWarmthMap, intCompMap = parser.extractInformation(parser.getMappings(normalized)[0], parser.getMappings(normalized)[1]) targetMap = targetParser.getMappings() allCategories = set() compAxis = [] warmthAxis = [] fig, ax = plt.subplots() for key in intWarmthMap.keys(): integrated = key g1 = integrated.split("_")[0] g2 = integrated.split("_")[1] if g1 != "": allCategories.add(g1) if g2 != "": allCategories.add(g2) #adjusts label positions for annotation catLabelMap = dict() for category in allCategories: if category == "jewish": catLabelMap[category] = (-30, -30) elif category == "farmer": catLabelMap[category] = (0, 20) elif category == "greek" or category == "nurse": catLabelMap[category] = (20, -20) elif category == "british": catLabelMap[category] = (-30, -30) else: catLabelMap[category] = (-20, 20) catLabelMap["japanese"] =(-40, 20) for category in allCategories: x = targetMap[category][1] y = targetMap[category][0] compAxis.append(x) warmthAxis.append(y) ax.annotate(category, (x,y), xytext = catLabelMap[category], textcoords = 'offset points', bbox = dict(boxstyle = 'round,pad=0.2', fc = 'yellow', alpha = 0.5), arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0')) plt.xlabel("warmth") plt.ylabel("competence") plt.title("Individual Ratings") ax.scatter(compAxis, warmthAxis) plt.show()
def getPlotData(integrated): """ integrated = g1 + "_" + g2 returns two lists, warmthAxis and compAxis, for which axis[0] = g1 value, axis[1] = g2 value, axis[2] = observed integrated value, axis[3] = predicted integrated value """ global normalized g1 = integrated.split("_")[0] g2 = integrated.split("_")[1] compAxis = [] warmthAxis = [] getMappingsWarmth = parser.getMappings(normalized)[0] getMappingsComp = parser.getMappings(normalized)[1] intWarmthMap, intCompMap = parser.extractInformation(getMappingsWarmth, getMappingsComp) #using mean and standard deviation computed from 18aug16 data: compAxis.append(intCompMap[g1][0]) #group 1 compAxis.append(intCompMap[g2][0]) #group 2 compAxis.append(intCompMap[integrated][0]) #combined observed #using mean and standard deviation computed from 18aug16 data: compPrediction = getCombination(float(intCompMap[g1][0]), float(intCompMap[g2][0]), float(intCompMap[g1][1]), float(intCompMap[g2][1]), float(intCompMap[g1][2]), float(intCompMap[g2][2])) compAxis.append(compPrediction[0]) #combined predicted #using mean and standard deviation computed from 18aug16 data: warmthAxis.append(intWarmthMap[g1][0]) warmthAxis.append(intWarmthMap[g2][0]) warmthAxis.append(intWarmthMap[integrated][0]) #using mean and standard deviation computed from 18aug16 data: warmthPrediction = getCombination(float(intWarmthMap[g1][0]), float(intWarmthMap[g2][0]), float(intWarmthMap[g1][1]), float(intWarmthMap[g2][1]), float(intWarmthMap[g1][2]), float(intWarmthMap[g2][2])) warmthAxis.append(warmthPrediction[0]) return warmthAxis, compAxis