Advertisement
makispaiktis

Colors Personality Traits

Sep 2nd, 2024
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.73 KB | None | 0 0
  1. # 1. Basics
  2. import pandas as pd
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5.  
  6.  
  7. # 1a. Define the traits and their types
  8. red = ['Επιθετικός', 'Φιλόδοξος', 'Με ισχυρή θέληση', 'Προσανατολισμένος στον στόχο', 'Πιεστικός', 'Καλός στην επίλυση των προβλημάτων', 'Πρωτοπόρος', 'Αποφασιστικός', 'Καινοτόμος', 'Ανυπόμονος', 'Ελεγκτικός', 'Πειστικός', 'Προσανατολισμένος στην απόδοση', 'Δυνατός', 'Προσανατολισμένος στα αποτελέσματα', 'Πρωτεργάτης', 'Ταχύς', 'Συνεπής', 'Έντονος', 'Ισχυρογνώμων', 'Ευθύς', 'Ανεξάρτητος']
  9. red_types = ['Α', 'Θ', 'Θ', 'Θ', 'Α', 'Θ', 'Θ', 'Θ', 'Θ', 'Α', 'Α', 'Θ', 'Θ', 'Θ', 'Θ', 'Θ', 'Θ', 'Θ', 'Ο', 'Α', 'Θ', 'Θ']
  10. yellow = ['Ομιλητικός', 'Ενθουσιώδης', 'Πειστικός ', 'Δημιουργικός', 'Αισιόδοξος', 'Κοινωνικός', 'Αυθόρμητος', 'Εκφραστικός', 'Γοητευτικός', 'Γεμάτος ζωτικότητα', 'Εγωκεντρικός', 'Ευαίσθητος', 'Ευπροσάρμοστος', 'Εμπνευσμένος', 'Επιζητά την προσοχή', 'Ενθαρρυντικός', 'Επικοινωνιακός', 'Ευέλικτος', 'Ανοιχτός', 'Φιλικός', 'Ευφάνταστος', 'Καλόβολος']
  11. yellow_types = ['Ο', 'Θ', 'Θ', 'Θ', 'Θ', 'Θ', 'Θ', 'Θ', 'Θ', 'Θ', 'Α', 'Θ', 'Θ', 'Θ', 'Α', 'Θ', 'Θ', 'Θ', 'Θ', 'Θ', 'Θ', 'Θ']
  12. green = ['Υπομονετικός', 'Χαλαρός', 'Με αυτοέλεγχο', 'Αξιόπιστος', 'Συγκροτημένος', 'Πιστός', 'Σεμνός', 'Με κατανόηση', 'Αργόσυρτος', 'Σταθερός', 'Εγκρατής', 'Διακριτικός', 'Υποστηρικτικός', 'Καλός ακροατής', 'Βοηθητικός', 'Παραγωγός', 'Επίμονος', 'Απρόθυμος', 'Σκεπτικός', 'Κρύβει συναισθήματα', 'Σκέφτεται τους άλλους', 'Στοργικός']
  13. green_types = ['Θ', 'Θ', 'Θ', 'Θ', 'Θ', 'Θ', 'Θ', 'Θ', 'Α', 'Θ', 'Θ', 'Θ', 'Θ', 'Θ', 'Θ', 'Θ', 'Α', 'Α', 'Ο', 'Α', 'Θ', 'Θ']
  14. blue = ['Ευσυνείδητος', 'Συστηματικός', 'Απόμακρος', 'Σωστός', 'Συμβατικός', 'Μοιάζει ανασφαλής', 'Αντικειμενικός', 'Συγκροτημένος', 'Αναλυτικός', 'Τελειομανής', 'Χρειάζεται χρόνο', 'Σκεπτικός ', 'Μεθοδικός', 'Αναζητά γεγονότα', 'Προσανατολισμένος στην ποιότητα', 'Ελέγχει εξονυχιστικά', 'Ακολουθεί κανόνες', 'Λογικός', 'Αμφισβητίας', 'Ενδελεχής', 'Στοχαστικός', 'Επιφυλακτικός']
  15. blue_types = ['Θ', 'Θ', 'Α', 'Θ', 'Ο', 'Α', 'Θ', 'Θ', 'Θ', 'Ο', 'Ο', 'Θ', 'Θ', 'Θ', 'Θ', 'Ο', 'Θ', 'Θ', 'Ο', 'Θ', 'Θ', 'Ο']
  16.  
  17.  
  18. LEN1 = len(red)
  19. LEN2 = len(yellow)
  20. LEN3 = len(green)
  21. LEN4 = len(blue)
  22. LEN5 = len(red_types)
  23. LEN6 = len(yellow_types)
  24. LEN7 = len(green_types)
  25. LEN8 = len(blue_types)
  26. LEN = LEN1 + LEN2 + LEN3 + LEN4
  27.  
  28. print(80 * "-")
  29. if LEN1 == LEN5 and LEN2 == LEN6 and LEN3 == LEN7 and LEN4 == LEN8:
  30.     print("Personality traits:\n")
  31.     print(f"{LEN1} red\n{LEN2} yellow\n{LEN3} green\n{LEN4} blue")
  32.     print(f"{LEN} total")
  33. print(80 * "-", '\n\n')
  34.  
  35. # 1b. Concatenate the lists
  36. traits = red + yellow + green + blue
  37. colors = ["Κόκκινο" for __ in range(LEN1)] + ["Κίτρινο" for __ in range(LEN1)] + ["Πράσινο" for __ in range(LEN1)] + ["Μπλε" for __ in range(LEN1)]
  38. types = red_types + yellow_types + green_types + blue_types
  39. type_dict = {'Α':'Αρνητικό', 'Θ':'Θετικό', 'Ο':'Ουδέτερο'}
  40. types = [type_dict[type] for type in types]
  41.  
  42.  
  43. # 1c. Create an initial dataframe with 'ΟΧΙ' in the 4th column
  44. print(80 * "-")
  45. print(f"\nInitial Dataframe")
  46. my_dict = {'Trait': traits, 'Color': colors, 'Type': types}
  47. df = pd.DataFrame(my_dict)
  48. print(df)
  49. print(80 * "-")
  50.  
  51.  
  52.  
  53. # 2. Random input
  54. from random import randrange
  55.  
  56. name = "Random User"
  57. ratings = [randrange(11) for _ in range(LEN)]
  58. df = pd.DataFrame(my_dict)
  59. df['Rating (?/10)'] = ratings
  60. print(df)
  61.  
  62.  
  63.  
  64. # 3. Input from the user (88 ratings in personality traits)
  65. ratings = []
  66.  
  67. name = input("Enter your name here: ")
  68. for trait in traits:
  69.     rating = float(input(f"{trait} (?/10) ----> "))
  70.     while rating < 0 or rating > 10:
  71.         print("Invalid input")
  72.         rating = float(input(f"{trait} (?/10) ----> "))
  73.     ratings.append(rating)
  74.  
  75. df = pd.DataFrame(my_dict)
  76. df['Rating (?/10)'] = ratings
  77. print(df)
  78.  
  79.  
  80.  
  81. # 4. Pretty Print
  82. def pretty_print(my_dict, print_LENS=False, print_decimals=False, is_perc=False, print_rating=False):
  83.     for key, value in my_dict.items():
  84.  
  85.         if is_perc:
  86.             value = 100 * value
  87.  
  88.         if key == 'Μπλε':
  89.             print(f"{key}    --->  ", end='')
  90.             if print_decimals:
  91.                 print(f"{value:.2f}", end='')
  92.             else:
  93.                 print(f"{value}", end='')
  94.             if is_perc:
  95.                 print(f" %", end='')
  96.             if print_LENS:
  97.                 print(f" / 22", end='')
  98.             if print_rating:
  99.                 print(f" / 10.00", end='')
  100.  
  101.         else:
  102.             print(f"{key} --->  ", end='')
  103.             if print_decimals:
  104.                 print(f"{value:.2f}", end='')
  105.             else:
  106.                 print(f"{value}", end='')
  107.             if is_perc:
  108.                 print(f" %", end='')
  109.             if print_LENS:
  110.                 print(f" / 22", end='')
  111.             if print_rating:
  112.                 print(f" / 10.00", end='')
  113.  
  114.         print()
  115.  
  116.  
  117.  
  118. # 5. Create the 3 basic dictionaries
  119. LENS = [LEN1, LEN2, LEN3, LEN4]
  120. num_colors = df['Color'].nunique()
  121. colors = list(df['Color'].unique())
  122.  
  123. # First dictionary:  Add +1 in each color "counter", when a trait rating is above 5
  124. # example = {red:20, yellow:15, green:12, blue:14}
  125. colors_dict = {color:0 for color in colors}
  126. # Second dictionary: Find the mean rating of every trait in a color
  127. # example = {red:9.5, yellow:7.5, green:6.2, blue:7.0}
  128. colors_avg_dict = {color:5 for color in colors}
  129.  
  130. for color in colors:
  131.     df2 = df[df['Color'] == color]
  132.     for i, rating in enumerate(df2['Rating (?/10)']):
  133.         if rating >= 5:
  134.             colors_dict[color] = colors_dict[color] + 1
  135.     avg = df2['Rating (?/10)'].mean()
  136.     colors_avg_dict[color] = avg
  137.  
  138. colors_perc_dict = {color:colors_dict[color]/LENS[i] for i, color in enumerate(colors)}
  139.  
  140.  
  141.  
  142. # 6. Some easy statistics
  143. import numpy as np
  144.  
  145. df_good_total = df[df['Type'] == 'Θετικό']
  146. df_bad_total = df[df['Type'] == 'Αρνητικό']
  147. df_neutral_total = df[df['Type'] == 'Ουδέτερο']
  148. num_good_total = len(df_good_total)
  149. num_bad_total = len(df_bad_total)
  150. num_neutral_total = len(df_neutral_total)
  151. # print(f"Number of good traits: {num_good_total}")
  152. # print(f"Number of bad traits: {num_bad_total}")
  153. # print(f"Number of neutral traits: {num_neutral_total}")
  154.  
  155.  
  156. df_good_user = df[(df['Type'] == 'Θετικό') & (df['Rating (?/10)'] >= 5)]
  157. df_bad_user = df[(df['Type'] == 'Αρνητικό') & (df['Rating (?/10)'] >= 5)]
  158. df_neutral_user = df[(df['Type'] == 'Ουδέτερο') & (df['Rating (?/10)'] >= 5)]
  159. num_good_user = len(df_good_user)
  160. num_bad_user = len(df_bad_user)
  161. num_neutral_user = len(df_neutral_user)
  162. # print(f"Number of good traits (user): {num_good_user}")
  163. # print(f"Number of bad traits (user): {num_bad_user}")
  164. # print(f"Number of neutral traits (user): {num_neutral_user}")
  165.  
  166.  
  167. print(f"For user '{name}':\n")
  168. print(80 * "-")
  169. print(f"Positive traits: {num_good_user:2d} / {num_good_total:2d} = {100*num_good_user/num_good_total:.2f}%")
  170. print(f"Negative traits: {num_bad_user:2d} / {num_bad_total:2d} = {100*num_bad_user/num_bad_total:.2f}%")
  171. print(f"Neutral traits:  {num_neutral_user:2d} / {num_neutral_total:2d} = {100*num_neutral_user/num_neutral_total:.2f}%")
  172. print(80 * "-", '\n')
  173.  
  174. print(80 * "-")
  175. print("Interpretation 1 - Which traits do I have?")
  176. pretty_print(colors_dict, True, False, False, False)
  177. print("\nInterpretation 1 - Which traits do I have (percentage)?")
  178. pretty_print(colors_perc_dict, False, True, True, False)
  179. print(80 * "-")
  180. print('\n')
  181. print(80 * "-")
  182. print("Interpretation 2 - Mean rating of color traits")
  183. pretty_print(colors_avg_dict, False, True, False, True)
  184. print(80 * "-")
  185.  
  186.  
  187.  
  188. # 7. Normalization - Create 2 auxiliary dictionaries
  189. # Normalization processes
  190. SUM1 = 0
  191. for value in colors_perc_dict.values():
  192.     SUM1 = SUM1 + value
  193. normalized1 = {color:value/SUM1 for color, value in colors_perc_dict.items()}
  194.  
  195.  
  196. SUM2 = 0
  197. for value in colors_avg_dict.values():
  198.     SUM2 = SUM2 + value
  199. normalized2 = {color:value/SUM2 for color, value in colors_avg_dict.items()}
  200.  
  201.  
  202. # Displays
  203. print(80 * "-")
  204. print("Normalization - Interpretation 1 - Which traits do I have?")
  205. pretty_print(normalized1, False, True, True, False)
  206. print(80 * "-", '\n\n')
  207. print(80 * "-")
  208. print("Normalization - Interpretation 2 - Mean rating of color traits")
  209. pretty_print(normalized2, False, True, True, False)
  210. print(80 * "-", '\n\n')
  211.  
  212.  
  213.  
  214. # 8. Bar diagrammes and pie charts
  215. import seaborn as sns
  216. import matplotlib.pyplot as plt
  217. colors_for_plot = ['#FF0000', '#FFFF00','#00FF00', '#0000FF']
  218.  
  219.  
  220. # Interpretation 1
  221. print(colors_perc_dict, '\n', normalized1, '\n')
  222. fig, ax = plt.subplots()
  223. mylabels1 = [f"{100*elem:.2f}%" for elem in list(colors_perc_dict.values())]
  224. plt.bar(colors_perc_dict.keys(), colors_perc_dict.values(), color=colors_for_plot, label=mylabels1)
  225. plt.ylabel('Ποσοστό')
  226. plt.title(f"Interpretation 1 for {name}")
  227. plt.legend(mylabels1)
  228. ax.plot([-0.5, 4.5], [1, 1], "k--")
  229. plt.show()
  230. print('\n')
  231.  
  232. y1 = np.array(list(normalized1.values()))
  233. mylabels1 = [f"{100*elem:.2f}%" for elem in y1]
  234. plt.pie(y1, colors=colors_for_plot)
  235. plt.legend(mylabels1)
  236. plt.title(f"Interpretation 1 for {name}")
  237. plt.show()
  238.  
  239.  
  240.  
  241. # Interpretation 2
  242. print(colors_avg_dict, '\n', normalized2, '\n')
  243. fig, ax = plt.subplots()
  244. mylabels2 = [f"{elem:.2f}" for elem in list(colors_avg_dict.values())]
  245. plt.bar(colors_avg_dict.keys(), colors_avg_dict.values(), color=colors_for_plot, label=mylabels2)
  246. plt.ylabel('Ποσοστό')
  247. plt.title(f"Interpretation 2 for {name}")
  248. plt.legend(mylabels2)
  249. ax.plot([-0.5, 4.5], [10, 10], "k--")
  250. plt.show()
  251. print('\n')
  252.  
  253. y2 = np.array(list(normalized2.values()))
  254. mylabels2 = [f"{100*elem:.2f}%" for elem in y2]
  255. plt.pie(y2, colors=colors_for_plot)
  256. plt.legend(mylabels2)
  257. plt.title(f"Interpretation 2 for {name}")
  258. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement