Categories
Bangla Data Science

āĻ•ā§‹-āĻ°āĻŋāĻ˛ā§‡āĻļāĻ¨ (Correlation), āĻ•āĻœā§‡āĻļāĻ¨ (Causation) āĻ“ āĻĢā§‡āĻ‡āĻ¸āĻŦā§āĻ•ā§‡āĻ° āĻ—āĻ˛ā§āĻĒ

āĻ¸ā§āĻŸā§āĻ¯āĻžāĻŸāĻŋāĻ¸ā§āĻŸāĻŋāĻ•ā§āĻ¸ – ā§§ā§Ļā§§ āĻ•āĻŋāĻ‚āĻŦāĻž āĻŦāĻŋāĻœāĻ¨ā§‡āĻ¸ āĻ°āĻŋāĻ¸āĻžāĻ°ā§āĻš – ā§§ā§Ļā§§ āĻ•ā§‹āĻ°ā§āĻ¸ āĻ—ā§āĻ˛ā§‹āĻ¤ā§‡ āĻāĻ•āĻŸāĻž āĻĒā§āĻ°āĻļā§āĻ¨ āĻ–ā§āĻŦāĻ‡ āĻ•āĻŽāĻ¨ – “āĻ•ā§‹-āĻ°āĻŋāĻ˛ā§‡āĻļāĻ¨āĻ‡ āĻ•āĻŋ āĻ•āĻœā§‡āĻļāĻ¨? āĻ‰āĻĻāĻžāĻšāĻ°āĻ¨ āĻ¸āĻš āĻŦā§āĻ¯āĻ–ā§āĻ¯āĻž āĻ•āĻ°ā§‹” āĨ¤ āĻ•ā§‹-āĻ°āĻŋāĻ˛ā§‡āĻļāĻ¨ āĻĨā§‡āĻ•ā§‡ āĻ†āĻŽāĻ°āĻž āĻœāĻžāĻ¨āĻ¤ā§‡ āĻĒāĻžāĻ°āĻŋ āĻĻā§āĻŸā§‹ āĻ­ā§āĻ¯āĻžāĻ°āĻŋā§Ÿā§‡āĻŦāĻ˛ āĻāĻ° āĻŽāĻ§ā§āĻ¯ā§‡ āĻ•ā§‹āĻ¨ “āĻ•ā§‹-āĻ°āĻŋāĻ˛ā§‡āĻļāĻ¨āĻļāĻŋāĻĒ” āĻ†āĻ›ā§‡ āĻ•āĻŋāĻ¨āĻž āĨ¤

āĻŽāĻ¨ā§‡ āĻ•āĻ°āĻŋ num_friends āĻšāĻšā§āĻ›ā§‡ āĻāĻ•āĻœāĻ¨ āĻŦā§āĻ¯āĻ•ā§āĻ¤āĻŋāĻ° āĻĢā§‡āĻ‡āĻ¸āĻŦā§āĻ• āĻĢā§āĻ°ā§‡āĻ¨ā§āĻĄā§‡āĻ° āĻ¸āĻ‚āĻ–ā§āĻ¯āĻž āĻ†āĻ° time_spent āĻšāĻšā§āĻ›ā§‡ āĻ¸ā§‡āĻ‡ āĻŦā§āĻ¯āĻ•ā§āĻ¤āĻŋ āĻĻāĻŋāĻ¨ā§‡ āĻ•āĻ¤āĻŸā§āĻ•ā§ āĻ¸āĻŽā§Ÿ āĻĢā§‡āĻ‡āĻ¸āĻŦā§āĻ•ā§‡ āĻŦā§āĻ¯ā§Ÿ āĻ•āĻ°ā§‡ āĨ¤ āĻāĻ•āĻĻāĻŋāĻ¨ āĻ¸āĻŽā§Ÿ āĻ•āĻ°ā§‡ āĻ†āĻŽāĻŋ āĻŦāĻŋāĻœāĻ¨ā§‡āĻ¸ āĻā§āĻ¯āĻžāĻĄāĻŽāĻŋāĻ¨āĻŋāĻ¸ā§āĻŸā§āĻ°ā§‡āĻļāĻ¨ āĻĄāĻŋāĻ¸āĻŋāĻĒā§āĻ˛āĻŋāĻ¨ā§‡āĻ° āĻļāĻŋāĻ•ā§āĻˇāĻžāĻ°ā§āĻĨā§€āĻĻā§‡āĻ° āĻ‰āĻĒāĻ° āĻœāĻ°āĻŋāĻĒ āĻ•āĻ°ā§‡ āĻāĻ‡ āĻĄāĻžāĻŸāĻž āĻ•āĻžāĻ˛ā§‡āĻ•ā§āĻŸ āĻ•āĻ°āĻŋ āĻāĻŦāĻ‚ āĻ•ā§‹-āĻ°āĻŋāĻ˛ā§‡āĻļāĻ¨ āĻ¨āĻŋāĻ°ā§āĻ¨ā§Ÿ āĻ•āĻ°āĻŋ āĨ¤ āĻĻā§‡āĻ–āĻž āĻ—ā§‡āĻ˛ā§‹ āĻāĻ‡ āĻ­ā§āĻ¯āĻžāĻ°āĻŋā§Ÿā§‡āĻŦāĻ˛ āĻĻā§āĻŸāĻŋ āĻĒāĻœāĻŋāĻŸāĻŋāĻ­āĻ˛āĻŋ āĻ•ā§‹-āĻ°āĻŋāĻ˛ā§‡āĻŸā§‡āĻĄ āĨ¤ āĻ¤āĻžāĻ° āĻŽāĻžāĻ¨ā§‡ āĻ¯āĻžāĻĻā§‡āĻ° āĻĢā§‡āĻ‡āĻ¸āĻŦā§āĻ•ā§‡ āĻĢā§āĻ°ā§‡āĻ¨ā§āĻĄ āĻ¸āĻ‚āĻ–ā§āĻ¯āĻž āĻŦā§‡āĻļā§€, āĻ¤āĻžāĻ°āĻž āĻĢā§‡āĻ‡āĻ¸āĻŦā§āĻ•ā§‡ āĻŦā§‡āĻļā§€ āĻ¸āĻŽā§Ÿ āĻ•āĻžāĻŸāĻžā§Ÿ āĨ¤

āĻ¸āĻŽāĻ¸ā§āĻ¯āĻž āĻšāĻ˛ā§‹, āĻāĻ‡ āĻ˜āĻŸāĻ¨āĻžāĻ° āĻĒāĻŋāĻ›āĻ¨ā§‡ ā§Š āĻ§āĻ°āĻ¨ā§‡āĻ° āĻ•āĻžāĻ°āĻ¨ āĻĨāĻžāĻ•āĻ¤ā§‡ āĻĒāĻžāĻ°ā§‡:

(ā§§) āĻ¯āĻžāĻĻā§‡āĻ° āĻĢā§āĻ°ā§‡āĻ¨ā§āĻĄ āĻ¸āĻ‚āĻ–ā§āĻ¯āĻž āĻŦā§‡āĻļā§€, āĻ¤āĻžāĻ°āĻž āĻĢā§āĻ°ā§‡āĻ¨ā§āĻĄāĻĻā§‡āĻ° āĻĒā§‹āĻ¸ā§āĻŸ, āĻ›āĻŦāĻŋ, āĻ•āĻŽā§‡āĻ¨ā§āĻŸ āĻĒā§œāĻžāĻ° āĻœāĻ¨ā§āĻ¯ āĻĢā§‡āĻ‡āĻ¸āĻŦā§āĻ•ā§‡ āĻŦā§‡āĻļā§€ āĻ¸āĻŽā§Ÿ āĻŦā§āĻ¯ā§Ÿ āĻ•āĻ°ā§‡ (“num_friends” causes “time_spent”)

(ā§¨) āĻ¯āĻžāĻ°āĻž āĻĢā§‡āĻ‡āĻ¸āĻŦā§āĻ•ā§‡ āĻŦā§‡āĻļā§€ āĻ¸āĻŽā§Ÿ āĻ•āĻžāĻŸāĻžā§Ÿ āĻ¤āĻžāĻ°āĻž āĻĢāĻŸā§‹āĻ—ā§āĻ°āĻžāĻĢāĻŋ āĻ—ā§āĻ°ā§āĻĒ, āĻĢā§āĻĄāĻŋāĻœ āĻ—ā§āĻ°ā§āĻĒ, āĻ¨āĻŋāĻœā§‡āĻ° āĻ•ā§āĻ˛āĻžāĻ¸ā§‡āĻ° āĻ—ā§āĻ°ā§āĻĒ, āĻĄāĻŋāĻ¸āĻŋāĻĒā§āĻ˛āĻŋāĻ¨ā§‡āĻ° āĻ—ā§āĻ°ā§āĻĒ – āĻ¨āĻžāĻ¨āĻž āĻ—ā§āĻ°ā§āĻĒā§‡ āĻŽāĻ¤āĻžāĻŽāĻ¤ āĻļā§‡ā§ŸāĻžāĻ° āĻ•āĻ°ā§‡ āĨ¤ āĻāĻ°āĻĢāĻ˛ā§‡ āĻ¸āĻŽāĻŽāĻ¨āĻž āĻ…āĻ¨ā§‡āĻ• āĻŽāĻžāĻ¨ā§āĻˇā§‡āĻ° āĻ¸āĻžāĻĨā§‡ āĻŦāĻ¨ā§āĻ§ā§āĻ¤ā§āĻŦ āĻšā§Ÿ āĨ¤ (“time_spent” causes “num_friends”)

(ā§Š) āĻāĻ°āĻž āĻĢā§‡āĻ‡āĻ¸āĻŦā§āĻ•ā§‡ āĻŦā§‡āĻļā§€ āĻ¸āĻŽā§Ÿ āĻ•āĻžāĻŸāĻžāĻ¨ āĻŦā§ŸāĻĢā§āĻ°ā§‡āĻ¨ā§āĻĄ āĻŦāĻž āĻ—āĻžāĻ°ā§āĻ˛āĻĢā§āĻ°ā§‡āĻ¨ā§āĻĄā§‡āĻ° āĻ¸āĻžāĻĨā§‡ āĻšā§āĻ¯āĻžāĻŸ āĻ•āĻ°ā§‡ āĻ†āĻ° āĻĢā§āĻ°ā§‡āĻ¨ā§āĻĄ āĻā§āĻ¯āĻžāĻĄ āĻ•āĻ°ā§‡āĻ¨ āĻĄāĻŋāĻ¸āĻŋāĻĒā§āĻ˛āĻŋāĻ¨ā§‡āĻ° āĻ¸āĻŋāĻ¨āĻŋā§ŸāĻ° āĻœā§āĻ¨āĻŋā§ŸāĻ° āĻ¸āĻŦāĻžāĻ‡āĻ•ā§‡ āĨ¤ (none causes the other)

āĻāĻ–āĻ¨ āĻ¯ā§‡āĻšā§‡āĻ¤ā§ āĻ†āĻŽāĻ°āĻž āĻ¨āĻŋāĻļā§āĻšāĻŋāĻ¤ āĻ¨āĻž āĻāĻ‡ ā§ŠāĻŸāĻŋ āĻ˜āĻŸāĻ¨āĻžāĻ° āĻ•ā§‹āĻ¨āĻŸāĻŋ āĻ˜āĻŸāĻ›ā§‡ āĨ¤ āĻ¤āĻžāĻ‡ āĻ•ā§‹āĻ°āĻŋāĻ˛ā§‡āĻļāĻ¨ āĻŽāĻžāĻ¨ā§‡āĻ‡ āĻ¯ā§‡ āĻ•āĻœā§‡āĻļāĻ¨ – āĻāĻ‡ āĻ§āĻžāĻ°āĻ¨āĻž āĻ†āĻŽāĻžāĻĻā§‡āĻ° āĻ¨āĻžāĻ•āĻš āĻ•āĻ°ā§‡ āĻĻāĻŋāĻ¤ā§‡ āĻšā§Ÿ āĨ¤ āĻāĻŦāĻ‚ āĻāĻŸāĻž āĻ†āĻŽāĻ°āĻž āĻ¸ā§āĻ¨ā§āĻĻāĻ° āĻ•āĻ°ā§‡ āĻĒāĻ°ā§€āĻ•ā§āĻˇāĻžāĻ° āĻ–āĻžāĻ¤āĻžā§Ÿ āĻŦā§āĻ¯āĻ–ā§āĻ¯āĻž āĻ•āĻ°ā§‡ āĻ¨āĻžāĻŽā§āĻŦāĻžāĻ° āĻĒāĻžāĻ‡ āĨ¤ āĻ¤āĻžāĻ‡ āĻāĻ° āĻŦā§‡āĻļā§€ āĻ†āĻŽāĻžāĻĻā§‡āĻ° āĻšāĻŋāĻ¨ā§āĻ¤āĻž āĻ•āĻ°āĻž āĻšā§Ÿā§‡ āĻ‰āĻ ā§‡ āĻ¨āĻž āĨ¤

āĻ…āĻ¨ā§āĻ¯āĻĻāĻŋāĻ•ā§‡ āĻĢā§‡āĻ‡āĻ¸āĻŦā§āĻ•ā§‡āĻ° āĻŦā§‡āĻ¤āĻ¨āĻ­ā§āĻ•ā§āĻ¤ āĻĄāĻžāĻŸāĻž āĻ¸āĻžā§Ÿā§‡āĻ¨ā§āĻŸāĻŋāĻ¸ā§āĻŸāĻ°āĻž āĻ•āĻŋāĻ¨ā§āĻ¤ā§ āĻāĻ¤ āĻ¸āĻšāĻœā§‡ āĻĒāĻžāĻ° āĻĒāĻžāĻ¨ āĻ¨āĻž āĨ¤ āĻ¤āĻžāĻĻā§‡āĻ° āĻŸāĻžāĻ°ā§āĻ—ā§‡āĻŸ āĻ†āĻŽāĻžāĻĻā§‡āĻ° āĻ¸ā§āĻŸā§āĻĄā§‡āĻ¨ā§āĻŸāĻĻā§‡āĻ°āĻ•ā§‡ āĻŦā§‡āĻļā§€ āĻ¸āĻŽā§Ÿ āĻĢā§‡āĻ‡āĻ¸āĻŦā§āĻ•ā§‡ āĻ†āĻŸāĻ•ā§‡ āĻ°āĻžāĻ–āĻž, āĻāĻœāĻ¨ā§āĻ¯ āĻāĻŸāĻž āĻ¨āĻŋā§Ÿā§‡ āĻ¤āĻžāĻĻā§‡āĻ° āĻŦāĻŋāĻļāĻžāĻ˛ āĻŽāĻžāĻĨāĻž āĻŦā§āĻ¯āĻĨāĻž āĨ¤ āĻ¤āĻžāĻ°āĻž āĻœāĻžāĻ¨āĻ¤ā§‡ āĻšāĻžā§Ÿ āĻŦāĻŋāĻ āĻĄāĻŋāĻ¸āĻŋāĻĒā§āĻ˛āĻŋāĻ¨ā§‡āĻ° āĻāĻ‡ āĻ•ā§‹-āĻ°āĻŋāĻ˛ā§‡āĻļāĻ¨ā§‡āĻ° āĻĒāĻŋāĻ›āĻ¨ā§‡ āĻ†āĻ¸āĻ˛ āĻ˜āĻŸāĻ¨āĻž āĻ•āĻŋ āĨ¤ āĻ¤āĻžāĻ°āĻž āĻĄāĻŋāĻ¸āĻŋāĻĒā§āĻ˛āĻŋāĻ¨ā§‡āĻ° āĻ¸ā§āĻŸā§āĻĄā§‡āĻ¨ā§āĻŸāĻĻā§‡āĻ° āĻĨā§‡āĻ•ā§‡ āĻ°â€ā§āĻ¯āĻžāĻ¨ā§āĻĄāĻŽ āĻ¸āĻžāĻŦāĻ¸ā§‡āĻŸ āĻ¨āĻŋā§Ÿā§‡ āĻ¤āĻžāĻĻā§‡āĻ° āĻ‰āĻĒāĻ° āĻāĻ•ā§āĻ¸āĻĒā§‡āĻ°āĻŋāĻŽā§‡āĻ¨ā§āĻŸ āĻšāĻžāĻ˛āĻžā§Ÿ – āĻ¤āĻžāĻĻā§‡āĻ° āĻ¨āĻŋāĻ‰āĻœāĻĢāĻŋāĻĄ āĻ•āĻžāĻ¸ā§āĻŸā§‹āĻŽāĻžāĻ‡āĻœ āĻ•āĻ°ā§‡ āĻĢā§‡āĻ˛ā§‡ āĻāĻŦāĻ‚ ā§¨ āĻ§āĻ°āĻ¨ā§‡āĻ° āĻŸā§‡āĻ¸ā§āĻŸ āĻšāĻžāĻ˛āĻžā§Ÿ –

(ā§§) āĻ•āĻŋāĻ›ā§ āĻ˛ā§‹āĻ•āĻœāĻ¨āĻ•ā§‡ āĻŦā§āĻ¯āĻžāĻĄ āĻāĻ° āĻ¨ā§‡āĻŸāĻ“ā§ŸāĻžāĻ°ā§āĻ• āĻĨā§‡āĻ•ā§‡ āĻĒā§‹āĻ¸ā§āĻŸ āĻĻā§‡āĻ–āĻžāĻ¨ā§‹ āĻ•āĻŽāĻŋā§Ÿā§‡ āĻĻā§‡ā§Ÿ āĨ¤ āĻ•āĻŋāĻ›ā§ āĻ˛ā§‹āĻ•āĻœāĻ¨āĻ•ā§‡ āĻŦā§‡āĻļā§€ āĻĒā§‹āĻ¸ā§āĻŸ āĻĻā§‡āĻ–āĻžāĻ¨ā§‹ āĻļā§āĻ°ā§ āĻ•āĻ°ā§‡ āĨ¤

(ā§¨) āĻ•āĻŋāĻ›ā§ āĻ˛ā§‹āĻ•āĻœāĻ¨āĻ•ā§‡ āĻŦā§‡āĻļā§€ āĻŦā§‡āĻļā§€ āĻŦā§āĻ¯āĻžāĻĄ āĻāĻ° āĻ¸āĻŋāĻ¨āĻŋā§ŸāĻ°, āĻœā§āĻ¨āĻŋā§ŸāĻ°āĻĻā§‡āĻ° āĻĢā§āĻ°ā§‡āĻ¨ā§āĻĄ āĻ°āĻŋāĻ•ā§ā§Ÿā§‡āĻ¸ā§āĻŸ āĻ¸āĻžāĻœā§‡āĻ¸ā§āĻŸ āĻ•āĻ°āĻ¤ā§‡ āĻĨāĻžāĻ•ā§‡, āĻ•āĻŋāĻ›ā§ āĻ˛ā§‹āĻ•āĻœāĻ¨āĻ•ā§‡ āĻ•āĻŽāĻŋā§Ÿā§‡ āĻĻā§‡ā§Ÿ āĨ¤

āĻ¯ā§‡āĻšā§‡āĻ¤ā§ āĻāĻŸāĻŋ āĻāĻ•āĻŸāĻŋ āĻ•āĻ˛ā§āĻĒāĻŋāĻ¤ āĻ˜āĻŸāĻ¨āĻž āĻ¸ā§‡āĻšā§‡āĻ¤ā§ āĻāĻ‡ āĻŸā§‡āĻ¸ā§āĻŸā§‡āĻ° āĻĢāĻ˛āĻžāĻĢāĻ˛ āĻ†āĻŽāĻžāĻ° āĻœāĻžāĻ¨āĻž āĻ¨ā§‡āĻ‡ āĨ¤ āĻ¤āĻŦā§‡ āĻĒā§āĻ°āĻĨāĻŽ āĻāĻŦāĻ‚ āĻĻā§āĻŦāĻŋāĻ¤ā§€ā§Ÿ āĻŸā§‡āĻ¸ā§āĻŸ āĻĨā§‡āĻ•ā§‡ āĻ•āĻŋāĻ›ā§āĻŸāĻž “āĻ•āĻ¨āĻĢāĻŋāĻĄā§‡āĻ¨ā§āĻ¸” āĻĒāĻžāĻ“ā§ŸāĻž āĻ¯ā§‡āĻ¤ā§‡ āĻĒāĻžāĻ°ā§‡ āĨ¤ āĻ¯āĻĻāĻŋ āĻĒā§āĻ°āĻĨāĻŽ āĻŸā§‡āĻ¸ā§āĻŸā§‡ āĻĻā§‡āĻ–āĻž āĻ¯āĻžā§Ÿ āĻ¯ā§‡ āĻŦā§‡āĻļā§€ āĻĒā§‹āĻ¸ā§āĻŸ āĻĻā§‡āĻ–āĻžāĻ¨ā§‹āĻ° āĻ•āĻžāĻ°āĻ¨ā§‡ āĻ˛ā§‹āĻ•āĻœāĻ¨ āĻŦā§‡āĻļā§€ āĻ¸āĻŽā§Ÿ āĻ•āĻžāĻŸāĻžāĻšā§āĻ›ā§‡, āĻ†āĻ° āĻĒā§‹āĻ¸ā§āĻŸ āĻ•āĻŽāĻŋā§Ÿā§‡ āĻĻā§‡āĻ“ā§ŸāĻžāĻ° āĻ•āĻžāĻ°āĻ¨ā§‡ āĻ•āĻŽ āĻ¸āĻŽā§Ÿ āĻ•āĻžāĻŸāĻžāĻšā§āĻ›ā§‡ āĻ¤āĻžāĻšāĻ˛ā§‡ āĻ†āĻŽāĻ°āĻž āĻ•āĻŋāĻ›ā§āĻŸāĻž āĻ†āĻ‡āĻĄāĻŋā§ŸāĻž āĻĒāĻžāĻ‡ āĻ¯ā§‡ āĻ†āĻ¸āĻ˛ā§‡ num_friends causes time_spent āĻ…āĻ¨ā§āĻ¯āĻĻāĻŋāĻ•ā§‡ āĻĻā§āĻŦāĻŋāĻ¤ā§€ā§Ÿ āĻŸā§‡āĻ¸ā§āĻŸ āĻĨā§‡āĻ•ā§‡ āĻ†āĻŽāĻ°āĻž āĻāĻ° āĻ‰āĻ˛ā§āĻŸā§‹āĻŸāĻž āĻœāĻžāĻ¨āĻ¤ā§‡ āĻĒāĻžāĻ°āĻŋ āĨ¤ āĻ†āĻ° āĻĻā§āĻŸā§‹ āĻŸā§‡āĻ¸ā§āĻŸā§‡āĻ‡ āĻ¯āĻĻāĻŋ āĻ¨ā§‡āĻ—ā§‡āĻŸāĻŋāĻ­ āĻ°ā§‡āĻœāĻžāĻ˛ā§āĻŸ āĻĒāĻžāĻ‡, āĻ¤āĻžāĻšāĻ˛ā§‡ āĻĢā§‡āĻ‡āĻ¸āĻŦā§āĻ•ā§‡āĻ° āĻ°āĻŋāĻ¸āĻžāĻ°ā§āĻš āĻŸā§€āĻŽā§‡āĻ° āĻ•āĻžāĻœ āĻ†āĻ°āĻ“ āĻŦā§‡ā§œā§‡ āĻ—ā§‡āĻ˛ā§‹ āĨ¤ ā§Šā§Ÿ āĻ•āĻŋ āĻ˜āĻŸāĻ¨āĻž āĻ˜āĻŸāĻ¤ā§‡ āĻĒāĻžāĻ°ā§‡ āĻāĻŸāĻž āĻ¨āĻŋā§Ÿā§‡ āĻāĻ–āĻ¨ āĻ¤āĻžāĻĻā§‡āĻ° āĻšā§āĻ˛āĻšā§‡āĻ°āĻž āĻŦāĻŋāĻļā§āĻ˛ā§‡āĻˇāĻ¨ āĻ•āĻ°āĻ¤ā§‡ āĻšāĻŦā§‡ āĨ¤

āĻ¸āĻšāĻœ āĻ•āĻĨāĻžā§Ÿ, āĻ•ā§‹āĻ°āĻŋāĻ˛ā§‡āĻļāĻ¨ āĻ¨āĻŋāĻļā§āĻšāĻŋāĻ¤āĻ­āĻžāĻŦā§‡ āĻ•āĻœā§‡āĻļāĻ¨ āĻŽāĻŋāĻ¨ āĻ•āĻ°ā§‡ āĻ¨āĻž, āĻ¤āĻŦā§‡ āĻŸā§‹āĻŸāĻžāĻ˛ āĻĒāĻĒā§āĻ˛ā§‡āĻļāĻ¨ā§‡āĻ° āĻ°â€ā§āĻ¯āĻžāĻ¨ā§āĻĄāĻŽ āĻ¸āĻžāĻŦāĻ¸ā§‡āĻŸ āĻ¨āĻŋā§Ÿā§‡ āĻ•āĻŋāĻ›ā§ āĻŸā§‡āĻ¸ā§āĻŸ āĻ•āĻ°ā§‡ āĻ•ā§‹āĻ°āĻŋāĻ˛ā§‡āĻļāĻ¨ā§‡āĻ° āĻĒāĻžāĻļāĻžāĻĒāĻžāĻļāĻŋ āĻ•āĻœā§‡āĻļāĻ¨āĻ“ āĻ†āĻ›ā§‡ āĻ•āĻŋāĻ¨āĻž āĻ¸ā§‡ āĻŦā§āĻ¯āĻžāĻĒāĻžāĻ°ā§‡ āĻ†āĻ‡āĻĄāĻŋā§ŸāĻž āĻĒāĻžāĻ“ā§ŸāĻž āĻ¯ā§‡āĻ¤ā§‡ āĻĒāĻžāĻ°ā§‡ āĨ¤

āĻĒā§āĻ¨āĻļā§āĻš: āĻ†āĻŽāĻžāĻ° āĻāĻ‡ āĻ‰āĻĻāĻžāĻšāĻ°āĻ¨ āĻ¸āĻŽā§āĻĒā§‚āĻ°ā§āĻ¨ āĻŦāĻžāĻ¨ā§‹ā§ŸāĻžāĻŸ āĻšāĻ˛ā§‡āĻ“ āĻĢā§‡āĻ‡āĻ¸āĻŦā§āĻ• āĻ¤āĻžāĻ° āĻ¨āĻŋāĻ‰āĻœāĻĢāĻŋāĻĄ āĻ¨āĻŋā§Ÿā§‡ āĻāĻ•ā§āĻ¸ā§‡āĻĒā§‡āĻ°āĻŋāĻŽā§‡āĻ¨ā§āĻŸ āĻ•āĻ°ā§‡āĻ›ā§‡ āĻāĻŦāĻ‚ āĻ¸ā§‡āĻŸāĻžāĻ° āĻ‡āĻĨāĻŋāĻ•ā§āĻ¯āĻžāĻ˛ āĻĻāĻŋāĻ• āĻ¨āĻŋā§Ÿā§‡ āĻ†āĻ˛ā§‹āĻšāĻ¨āĻž āĻ¸āĻŽāĻžāĻ˛ā§‹āĻšāĻ¨āĻžāĻ“ āĻšā§Ÿā§‡āĻ›ā§‡ āĻ…āĻ¨ā§‡āĻ• āĨ¤

āĻ°ā§‡āĻĢāĻžāĻ°ā§‡āĻ¨ā§āĻ¸: http://www.nytimes.com/2014/06/30/technology/facebook-tinkers-with-users-emotions-in-news-feed-experiment-stirring-outcry.html?_r=1

Categories
Django Python

Django REST Framework: Custom Exception Handler

While using DRF, do you need to handle the exceptions yourselves? Here’s how to do it. First, we need to create an exception handler function like this:

In the exception handler, we get exc which is the exception raised and the context contains the context of the request. However, we didn’t do anything fancy with these. We just called the default exception handler and joined the errors in a flat string. We also added the exception to our response.

Now, we need to tell DRF to call our custom exception handler when it comes across an exception. That is easy:

Open up your settings.py and look for the REST_FRAMEWORK dictionary. Here you need to add the exception handler to the EXCEPTION_HANDLER key. So it should look something like this:

Categories
Django Python

Django: Handling broken migrations

Often for one reason or another, migrations don’t apply properly and we have to fix them manually. If there’s a faulty migration that throws errors when run, we first have to identify what went wrong. Very often on MySQL, we see half applied migrations (probably because MySQL doesn’t have transactions?). In this case we need to do the other half ourselves.

We can easily connect to the database prompt by typing the dbshell command.

The command opens the shell for the respective database engine using the configurations provided in the settings file. That is you don’t have to remember the username or password for the database connection.

Now you have to fix the issues and then you can try running the migration again. In case it fails again, you should alter the database to match the state the migration would have created. For example, if the migration was supposed to alter a column from store_type to store_type_id (from a char field to foreign keys), you have to manually run the query, something like:

Then you have to fake the migration. When a migration is run, Django stores the name of the migration in a table. It helps track which migrations have already run and which needs to be run. When we fake a migration, Django stores the faked migration name in that table without actually running it. If we don’t do this, when we next run migrate command, Django will try to run this migration again and fail.

This is how we fake it:

You can also specify one particular migration when you have multiple migrations running.