IQ#

Visualizing the intelligence quotient (IQ) of 100 applicants using histogram and box plots.

Importing libraries and packages#

1# Warnings
2import warnings
3
4# Plotting
5import matplotlib.pyplot as plt
6
7warnings.filterwarnings("ignore")
8%matplotlib inline

Set paths#

1# Path to datasets directory
2data_path = "./datasets"
3# Path to assets directory (for saving results to)
4assets_path = "./assets"

Loading dataset#

  1# IQ samples
  2iq_scores = [
  3    126,
  4    89,
  5    90,
  6    101,
  7    102,
  8    74,
  9    93,
 10    101,
 11    66,
 12    120,
 13    108,
 14    97,
 15    98,
 16    105,
 17    119,
 18    92,
 19    113,
 20    81,
 21    104,
 22    108,
 23    83,
 24    102,
 25    105,
 26    111,
 27    102,
 28    107,
 29    103,
 30    89,
 31    89,
 32    110,
 33    71,
 34    110,
 35    120,
 36    85,
 37    111,
 38    83,
 39    122,
 40    120,
 41    102,
 42    84,
 43    118,
 44    100,
 45    100,
 46    114,
 47    81,
 48    109,
 49    69,
 50    97,
 51    95,
 52    106,
 53    116,
 54    109,
 55    114,
 56    98,
 57    90,
 58    92,
 59    98,
 60    91,
 61    81,
 62    85,
 63    86,
 64    102,
 65    93,
 66    112,
 67    76,
 68    89,
 69    110,
 70    75,
 71    100,
 72    90,
 73    96,
 74    94,
 75    107,
 76    108,
 77    95,
 78    96,
 79    96,
 80    114,
 81    93,
 82    95,
 83    117,
 84    141,
 85    115,
 86    95,
 87    86,
 88    100,
 89    121,
 90    103,
 91    66,
 92    99,
 93    96,
 94    111,
 95    110,
 96    105,
 97    110,
 98    91,
 99    112,
100    102,
101    112,
102    75,
103]
104
105group_a = [
106    118,
107    103,
108    125,
109    107,
110    111,
111    96,
112    104,
113    97,
114    96,
115    114,
116    96,
117    75,
118    114,
119    107,
120    87,
121    117,
122    117,
123    114,
124    117,
125    112,
126    107,
127    133,
128    94,
129    91,
130    118,
131    110,
132    117,
133    86,
134    143,
135    83,
136    106,
137    86,
138    98,
139    126,
140    109,
141    91,
142    112,
143    120,
144    108,
145    111,
146    107,
147    98,
148    89,
149    113,
150    117,
151    81,
152    113,
153    112,
154    84,
155    115,
156    96,
157    93,
158    128,
159    115,
160    138,
161    121,
162    87,
163    112,
164    110,
165    79,
166    100,
167    84,
168    115,
169    93,
170    108,
171    130,
172    107,
173    106,
174    106,
175    101,
176    117,
177    93,
178    94,
179    103,
180    112,
181    98,
182    103,
183    70,
184    139,
185    94,
186    110,
187    105,
188    122,
189    94,
190    94,
191    105,
192    129,
193    110,
194    112,
195    97,
196    109,
197    121,
198    106,
199    118,
200    131,
201    88,
202    122,
203    125,
204    93,
205    78,
206]
207
208group_b = [
209    126,
210    89,
211    90,
212    101,
213    102,
214    74,
215    93,
216    101,
217    66,
218    120,
219    108,
220    97,
221    98,
222    105,
223    119,
224    92,
225    113,
226    81,
227    104,
228    108,
229    83,
230    102,
231    105,
232    111,
233    102,
234    107,
235    103,
236    89,
237    89,
238    110,
239    71,
240    110,
241    120,
242    85,
243    111,
244    83,
245    122,
246    120,
247    102,
248    84,
249    118,
250    100,
251    100,
252    114,
253    81,
254    109,
255    69,
256    97,
257    95,
258    106,
259    116,
260    109,
261    114,
262    98,
263    90,
264    92,
265    98,
266    91,
267    81,
268    85,
269    86,
270    102,
271    93,
272    112,
273    76,
274    89,
275    110,
276    75,
277    100,
278    90,
279    96,
280    94,
281    107,
282    108,
283    95,
284    96,
285    96,
286    114,
287    93,
288    95,
289    117,
290    141,
291    115,
292    95,
293    86,
294    100,
295    121,
296    103,
297    66,
298    99,
299    96,
300    111,
301    110,
302    105,
303    110,
304    91,
305    112,
306    102,
307    112,
308    75,
309]
310
311group_c = [
312    108,
313    89,
314    114,
315    116,
316    126,
317    104,
318    113,
319    96,
320    69,
321    121,
322    109,
323    102,
324    107,
325    122,
326    104,
327    107,
328    108,
329    137,
330    107,
331    116,
332    98,
333    132,
334    108,
335    114,
336    82,
337    93,
338    89,
339    90,
340    86,
341    91,
342    99,
343    98,
344    83,
345    93,
346    114,
347    96,
348    95,
349    113,
350    103,
351    81,
352    107,
353    85,
354    116,
355    85,
356    107,
357    125,
358    126,
359    123,
360    122,
361    124,
362    115,
363    114,
364    93,
365    93,
366    114,
367    107,
368    107,
369    84,
370    131,
371    91,
372    108,
373    127,
374    112,
375    106,
376    115,
377    82,
378    90,
379    117,
380    108,
381    115,
382    113,
383    108,
384    104,
385    103,
386    90,
387    110,
388    114,
389    92,
390    101,
391    72,
392    109,
393    94,
394    122,
395    90,
396    102,
397    86,
398    119,
399    103,
400    110,
401    96,
402    90,
403    110,
404    96,
405    69,
406    85,
407    102,
408    69,
409    96,
410    101,
411    90,
412]
413
414group_d = [
415    93,
416    99,
417    91,
418    110,
419    80,
420    113,
421    111,
422    115,
423    98,
424    74,
425    96,
426    80,
427    83,
428    102,
429    60,
430    91,
431    82,
432    90,
433    97,
434    101,
435    89,
436    89,
437    117,
438    91,
439    104,
440    104,
441    102,
442    128,
443    106,
444    111,
445    79,
446    92,
447    97,
448    101,
449    106,
450    110,
451    93,
452    93,
453    106,
454    108,
455    85,
456    83,
457    108,
458    94,
459    79,
460    87,
461    113,
462    112,
463    111,
464    111,
465    79,
466    116,
467    104,
468    84,
469    116,
470    111,
471    103,
472    103,
473    112,
474    68,
475    54,
476    80,
477    86,
478    119,
479    81,
480    84,
481    91,
482    96,
483    116,
484    125,
485    99,
486    58,
487    102,
488    77,
489    98,
490    100,
491    90,
492    106,
493    109,
494    114,
495    102,
496    102,
497    112,
498    103,
499    98,
500    96,
501    85,
502    97,
503    110,
504    131,
505    92,
506    79,
507    115,
508    122,
509    95,
510    105,
511    74,
512    85,
513    85,
514    95,
515]

Visualisation#

 1# Histogram with ten bins for the given IQ scores.
 2plt.figure(figsize=(6, 4), dpi=150)
 3# Create histogram
 4plt.hist(iq_scores, bins=10)
 5plt.axvline(x=100, color="r")
 6plt.axvline(x=115, color="r", linestyle="--")
 7plt.axvline(x=85, color="r", linestyle="--")
 8# Add labels and title
 9plt.xlabel("IQ score")
10plt.ylabel("Frequency")
11plt.title("IQ scores for a test group of a hundred adults")
12# Show plot
13plt.show()
../../_images/341d26e502ee0f2564dab512f0b78a639a327e91895a7e2cc2cdece5e7016fbd.png
 1# Box plot
 2plt.figure(figsize=(6, 4), dpi=150)
 3# Create histogram
 4plt.boxplot(iq_scores)
 5# Add labels and title
 6ax = plt.gca()
 7ax.set_xticklabels(["Test group"])
 8plt.ylabel("IQ score")
 9plt.title("IQ scores for a test group of a hundred adults")
10# Show plot
11plt.show()
../../_images/877ccc39fc4441cdf15b598a5c9129414eb7f1913fe7adfbff236ef3a16f7db8.png
 1# Box plot for each of the IQ scores of the different test groups
 2# a, b, c and d.
 3plt.figure(figsize=(6, 4), dpi=150)
 4# Create histogram
 5plt.boxplot([group_a, group_b, group_c, group_d])
 6# Add labels and title
 7ax = plt.gca()
 8ax.set_xticklabels(["Group A", "Group B", "Group C", "Group D"])
 9plt.ylabel("IQ score")
10plt.title("IQ scores for different test groups")
11# Show plot
12plt.show()
../../_images/5e51a112eddd1222568d92dbee25477da4cfa42125759fe52147a5dc0376cbc2.png