You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Data-Science-For-Beginners/translations/te/1-Introduction/01-defining-data-science/notebook.ipynb

322 lines
18 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# సవాలు: డేటా సైన్స్ గురించి పాఠ్యం విశ్లేషణ\n",
"\n",
"ఈ ఉదాహరణలో, సంప్రదాయ డేటా సైన్స్ ప్రక్రియ అన్ని దశలను కవర్ చేసే ఒక సులభమైన వ్యాయామం చేద్దాం. మీరు ఎలాంటి కోడ్ రాయాల్సిన అవసరం లేదు, కింది సెల్‌లపై క్లిక్ చేసి వాటిని అమలు చేయవచ్చు మరియు ఫలితాన్ని గమనించవచ్చు. ఒక సవాలుగా, మీరు ఈ కోడ్‌ను వేరే డేటాతో ప్రయత్నించాలని ప్రోత్సహించబడతారు.\n",
"\n",
"## లక్ష్యం\n",
"\n",
"ఈ పాఠంలో, మేము డేటా సైన్స్‌కు సంబంధించిన విభిన్న భావనలు చర్చిస్తున్నాము. కొంత **పాఠ్య తవ్వకం** చేయడం ద్వారా మరిన్ని సంబంధిత భావనలు కనుగొనడానికి ప్రయత్నిద్దాం. మేము డేటా సైన్స్ గురించి ఒక పాఠ్యంతో మొదలుపెట్టి, దాని నుండి కీలక పదాల‌ను తీసుకుని, తర్వాత ఫలితాన్ని దృశ్యమానంగా చూపించడానికి ప్రయత్నిస్తాం.\n",
"\n",
"పాఠ్యంగా నేను వికీపీడియా నుండి డేటా సైన్స్ పేజీని ఉపయోగిస్తాను:\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"url = 'https://en.wikipedia.org/wiki/Data_science'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## దశ 1: డేటాను పొందడం\n",
"\n",
"ప్రతి డేటా సైన్స్ ప్రక్రియలో మొదటి దశ డేటాను పొందడం. దీని కోసం మేము `requests` లైబ్రరీని ఉపయోగించబోతున్నాం:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"\n",
"# Define a custom header.\n",
"headers = {\n",
" 'User-Agent': 'DataScienceChallenge/1.0 (myemail@gmail.com)'\n",
"}\n",
"\n",
"# Pass the headers into the get request\n",
"response = requests.get(url, headers=headers)\n",
"\n",
"if response.status_code == 200:\n",
" text = response.content.decode('utf-8')\n",
" print(text[:1000])\n",
"else:\n",
" print(f\"Error: {response.status_code}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## దశ 2: డేటాను మార్చడం\n",
"\n",
"తర్వాతి దశగా డేటాను ప్రాసెస్‍చేయడానికి అనుకూలమైన రూపంగా మార్చడం. మనం పేజీ నుండి HTML సోర్స్ కోడ్‌ను డౌన్‌లోడ్ చేసుకున్నాము, దీన్ని ప్లెయిన్ టెక్స్ట్‌గా మార్చాలి.\n",
"\n",
"ఇది చేయడానికి అనేక మార్గాలు ఉన్నాయి. మనం [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/) ఉపయోగిస్తాము, ఇది HTML పార్సింగ్ కోసం ప్రాచుర్యం పొందిన Python లైబ్రరీ. BeautifulSoup మాకు నిర్దిష్ట HTML అంశాలను లక్ష్యం చేయడానికీ అవకాశం ఇస్తుంది, అందుచే మనం Wikipedia యొక్క ప్రధాన వ్యాసం కంటెంట్‌పై దృష్టి పెట్టవచ్చు, మరియు కొన్ని నావిగేషన్ మెనూలు, సైడ్ బార్‌లు, ఫూటర్లు మరియు ఇతర ప్రాసంగికం కాని భాగాలను తగ్గించవచ్చు (యాదృచ్ఛికంగా కొన్ని బోయిలర్‌ప్లేట్ టెక్స్ట్ ఇంకా ఉండొచ్చు). \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"మొదట, మనం HTML పార్సింగ్ కోసం BeautifulSoup గ్రంథాలయాన్ని ఇన్‌స్టాల్ చేయవలసింది:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"!{sys.executable} -m pip install beautifulsoup4"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from bs4 import BeautifulSoup\n",
"\n",
"# Parse the HTML content\n",
"soup = BeautifulSoup(text, 'html.parser')\n",
"\n",
"# Extract only the main article content from Wikipedia\n",
"# Wikipedia uses 'mw-parser-output' class for the main article content\n",
"content = soup.find('div', class_='mw-parser-output')\n",
"\n",
"def clean_wikipedia_content(content_node):\n",
" \"\"\"Remove common non-article elements from a Wikipedia content node.\"\"\"\n",
" # Strip jump links, navboxes, reference lists/superscripts, edit sections, TOC, sidebars, etc.\n",
" selectors = [\n",
" '.mw-jump-link',\n",
" '.navbox',\n",
" '.reflist',\n",
" 'sup.reference',\n",
" '.mw-editsection',\n",
" '.hatnote',\n",
" '.metadata',\n",
" '.infobox',\n",
" '#toc',\n",
" '.toc',\n",
" '.sidebar',\n",
" ]\n",
" for selector in selectors:\n",
" for el in content_node.select(selector):\n",
" el.decompose()\n",
"\n",
"if content:\n",
" # Clean the content node to better approximate article text only.\n",
" clean_wikipedia_content(content)\n",
" text = content.get_text(separator=' ', strip=True)\n",
" print(text[:1000])\n",
"else:\n",
" print(\"Could not find main content. Using full page text.\")\n",
" text = soup.get_text(separator=' ', strip=True)\n",
" print(text[:1000])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## దశ 3: అవగాహన పొందడం\n",
"\n",
"అత్యంత ముఖ్యమైన దశ ఏమిటంటే మన డేటాను అలాంటి రూపంలోకి మార్చడం, దాని నుండి మనం అవగాహన పొందగలుగుతాము. మన సందర్భంలో, మనం టెక్స్ట్ నుండి కీలకపదాలను తీసుకోవాలనుకుంటున్నాం, మరియు ఏ కీలకపదాలు మరింత అర్ధం గలవో చూడాలి.\n",
"\n",
"మనం పాథాన్ లైబ్రరీ [RAKE](https://github.com/aneesha/RAKE)ను కీలకపదాల తీసుకోవడానికి ఉపయోగించబడతాం. మొదట, ఇది తగ్గి ఉంటే ఈ లైబ్రరీని ఇన్‌స్టాల్ చేసుకోదాం: \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"!{sys.executable} -m pip install nlp_rake"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"ప్రధాన ఫంక్షనాలిటీ `Rake` ఆబ్జెక్ట్ నుండి అందుబాటులో ఉంటుంది, దీన్ని మేము కొన్ని పారామితులు ఉపయోగించి అనుకూలీకరించుకోవచ్చు. మా సందర్భంలో, ఒక కీవర్డ్ కనిష్ఠదైర్ఘ్యం 5 అక్షరాలు గా, డాక్యుమెంట్ లో కీవర్డ్ కనిష్ఠ సాంద్రత 3 గా, మరియు కీవర్డ్ లో గరిష్ఠ పదాల సంఖ్య - 2 గా సెట్ చేస్తాము. ఇతర విలువలతో ప్రయోగించి ఫలితాన్ని పరిశీలించండి.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import nlp_rake\n",
"extractor = nlp_rake.Rake(max_words=2,min_freq=3,min_chars=5)\n",
"res = extractor.apply(text)\n",
"res"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"మేము సంబంధించిన ప్రాధాన్యత డిగ్రీతో పాటు పదాల జాబితాను పొందాము. మీరు చూడగలిగినట్లుగా, యంత్రమైన అభ్యాసం మరియు పెద్ద డేటా వంటి అత్యంత సంబంధిత శాస్త్రాలు జాబితాలో పై స్థానాల్లో ఉన్నాయి.\n",
"\n",
"## దశ 4: ఫలితాన్ని దృశ్యరూపంలో చూపించడం\n",
"\n",
"డేటాను అందరికీ బాగా అర్థం కావడానికి దృశ్యరూపం ఉత్తమమైంది. అందుకే కొన్ని వివరాలు పొందటానికి డేటాను దృశ్యరూపంలో చూపించడం సాధారణం. పదసమూహాల సంబంధాన్ని సులువుగా చూపించేందుకు Python లో `matplotlib` లైబ్రరీని ఉపయోగించవచ్చు:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"def plot(pair_list):\n",
" k,v = zip(*pair_list)\n",
" plt.bar(range(len(k)),v)\n",
" plt.xticks(range(len(k)),k,rotation='vertical')\n",
" plt.show()\n",
"\n",
"plot(res)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"అయితే, పదపు ఆధారాల సరళిని చూడడానికి మరొక మంచి విధానం ఉంది - **Word Cloud** ఉపయోగించడం. మా కీవర్డ్ జాబితా నుండి పదపు మేఘాన్ని చిత్రీకరించడానికి మేము మరొక లైబ్రరీని ఇన్స్టాల్ చేయాలి.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!{sys.executable} -m pip install wordcloud"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`WordCloud` ఆబ్జెక్ట్ అసలు పాఠ్యం లేదా పదాలతో కూడిన వారి ఫ్రీక్వెన్సీలతో కూడిన ముందుగా లెక్కించబడిన జాబితాను తీసుకొని, ఒక చిత్రాన్ని తిరిగి ఇస్తుంది, దీనిని తరువాత `matplotlib` ఉపయోగించి ప్రదర్శించవచ్చు:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from wordcloud import WordCloud\n",
"import matplotlib.pyplot as plt\n",
"\n",
"wc = WordCloud(background_color='white',width=800,height=600)\n",
"plt.figure(figsize=(15,7))\n",
"plt.imshow(wc.generate_from_frequencies({ k:v for k,v in res }))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"మేము అసలు వచనాన్ని కూడా `WordCloud` కి పాస్ చేయవచ్చు - మేము సమాన ఫలితాన్ని పొందగలమో చూడండి:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(15,7))\n",
"plt.imshow(wc.generate(text))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"wc.generate(text).to_file('images/ds_wordcloud.png')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"మీరు ఇప్పుడు ఆ పద మేఘం మరింత ఆకర్షణీయంగా కనిపిస్తోంది అయితే, ఇది చాలా శబ్దం కూడా కలిగి ఉంది (ఉదా: `Retrieved on` వంటి సంబంధం లేని పదాలు). ఇంకా, మనం రెండు పదాల కలయిక నుండి ఉన్న తక్కువ కీవర్డ్స్ మాత్రమే పొందుతున్నాము, ఉదాహరణకు *డేటా సైంటిస్ట్*, లేదా *కంప్యూటర్ సైన్స్*. ఇది ఎందుకంటే RAKE ఆల్గోరిథం టెక్ట్స్ నుండి మంచి కీవర్డ్స్ ఎంచుకోవడంలో బాగా పనిచేస్తుంది. ఈ ఉదాహరణ డేటా ప్రీ-ప్రాసెసింగ్ మరియు శుభ్రపరిచే ప్రక్రియ యొక్క ప్రాముఖ్యతను స్పష్టం చేస్తుంది, ఎందుకంటే చివరికి స్పష్టమైన చిత్రం మనకు మెరుగైన నిర్ణయాలు తీసుకోవడానికి అనుమతిస్తుంది.\n",
"\n",
"ఈ వ్యాయామంలో మనం వికీపీడియా టెక్ట్స్ నుండి కొంత అర్థం çıkar గడానికి ఒక సులభమైన ప్రక్రియను పూర్తిచేశాము, కీవర్డ్స్ మరియు పద మేఘం రూపంలో. ఈ ఉదాహరణ సులభమైనది, కానీ ఇది డేటా సైంటిస్ట్ డేటాతో పని చేసేటప్పుడు తీసుకునే అన్ని సాధారణ దశలను బాగా చూపిస్తోంది, డేటా సేకరణ నుండి ప్రారంభమై విజువలైజేషన్ వరకు.\n",
"\n",
"మన కోర్సులో ఆ దశలన్నింటినీ వివరంగా చర్చిస్తాము.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n\n<!-- CO-OP TRANSLATOR DISCLAIMER START -->\n**అస్వీకరణ**:\nఈ పత్రం AI అనువాద సేవ [Co-op Translator](https://github.com/Azure/co-op-translator) ఉపయోగించి అనువదించబడింది. మేము ఖచ్చితత్వానికి ప్రయత్నిస్తున్నప్పటికీ, ఆటోమేటెడ్ అనువాదాలు తప్పులు లేదా అసమగ్రతలను కలిగి ఉండవచ్చు. దాని స్వదేశ భాషలో ఉన్న అసలు పత్రాన్ని అధికారం కలిగిన మూలంగా పరిగణించాలి. కీలకమైన సమాచారం కోసం, ప్రొఫెషనల్ మానవ అనువాదాన్ని సిఫారసు చేస్తాము. ఈ అనువాదం ఉపయోగం వల్ల కలిగే ఏవైనా అపార్థాలు లేదా తప్పుదారులు కోసం మేము బాధ్యత వహించము.\n<!-- CO-OP TRANSLATOR DISCLAIMER END -->\n"
]
}
],
"metadata": {
"interpreter": {
"hash": "c28e7b6bf4e5b397b8288a85bf0a94ea8d3585ce2b01919feb195678ec71581b"
},
"kernelspec": {
"display_name": "Python 3.8.11 64-bit ('base': conda)",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.11"
}
},
"nbformat": 4,
"nbformat_minor": 2
}