<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gopalkrishnan on Medium]]></title>
        <description><![CDATA[Stories by Gopalkrishnan on Medium]]></description>
        <link>https://medium.com/@gopal.k1991?source=rss-e8b7d788b206------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qP-eJIS2Pi3uVy4WvcJffQ.jpeg</url>
            <title>Stories by Gopalkrishnan on Medium</title>
            <link>https://medium.com/@gopal.k1991?source=rss-e8b7d788b206------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 11:50:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gopal.k1991/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[From Stats to Stories: Building GenAI-Powered IPL Cricket Analyzer]]></title>
            <link>https://medium.com/@gopal.k1991/from-stats-to-stories-building-genai-powered-ipl-cricket-analyzer-98b6c7ce80eb?source=rss-e8b7d788b206------2</link>
            <guid isPermaLink="false">https://medium.com/p/98b6c7ce80eb</guid>
            <category><![CDATA[cricket]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[ipl]]></category>
            <category><![CDATA[genai]]></category>
            <dc:creator><![CDATA[Gopalkrishnan]]></dc:creator>
            <pubDate>Wed, 06 Nov 2024 11:18:06 GMT</pubDate>
            <atom:updated>2024-11-06T11:18:06.932Z</atom:updated>
            <content:encoded><![CDATA[<p>Cricket isn’t just a game of numbers — it’s a mixture of moments, decisions, and performances. As a developer and cricket enthusiast, I wanted to bridge the gap between raw statistics and meaningful insights. Here’s how I built an AI-powered IPL cricket analyzer that makes complex cricket analytics accessible to everyone.</p><p><strong>The Cricket Analytics Challenge</strong></p><p>Picture this: You’re analyzing IPL batting performances from 2020. You want to know who had the best strike rate, or which bowler took the most wickets in powerplay overs. Traditional methods would require:</p><ul><li>Writing complex SQL queries</li><li>Manual data filtering in Excel</li><li>Creating pivot tables</li><li>Combining data from multiple sources</li></ul><p>I wanted to simplify this process with a conversational interface.</p><p><strong>The Solution: Natural Language Cricket Analysis</strong></p><p>I built a tool that lets you ask cricket questions in plain English. Here’s how it works:</p><ol><li>Understanding Cricket Queries</li></ol><pre>def determine_analysis_type(question):<br>    &quot;&quot;&quot;Determine the type of analysis needed based on the question&quot;&quot;&quot;<br>    question_lower = question.lower()<br>    <br>    # Enhanced analysis patterns with more complex scenarios<br>    analysis_patterns = {<br>        &#39;comparative&#39;: [<br>            &#39;compare&#39;, &#39;versus&#39;, &#39;vs&#39;, &#39;better than&#39;, &#39;worse than&#39;, &#39;higher&#39;, &#39;lower&#39;,<br>            &#39;more than&#39;, &#39;less than&#39;, &#39;difference between&#39;, &#39;comparison&#39;<br>        ],<br>        &#39;conditional&#39;: [<br>            &#39;when&#39;, &#39;if&#39;, &#39;during&#39;, &#39;in case of&#39;, &#39;while&#39;, &#39;under&#39;, &#39;condition&#39;,<br>            &#39;scenario&#39;, &#39;situation&#39;<br>        ],<br>        &#39;trend&#39;: [<br>            &#39;trend&#39;, &#39;pattern&#39;, &#39;over time&#39;, &#39;progression&#39;, &#39;development&#39;, &#39;evolution&#39;,<br>            &#39;change&#39;, &#39;growth&#39;, &#39;decline&#39;<br>        ],<br>        &#39;batting&#39;: [<br>            &#39;batter&#39;, &#39;batting&#39;, &#39;batsman&#39;, &#39;runs&#39;, &#39;strike rate&#39;, &#39;boundaries&#39;, <br>            &#39;scored&#39;, &#39;batting performance&#39;, &#39;run rate&#39;, &#39;average&#39;<br>        ],<br>        &#39;bowling&#39;: [<br>            &#39;bowler&#39;, &#39;bowling&#39;, &#39;economy&#39;, &#39;wickets&#39;, &#39;dot ball&#39;, &#39;bowled&#39;,<br>            &#39;bowling performance&#39;, &#39;wicket taker&#39;, &#39;maiden&#39;<br>        ],<br>        &#39;venue&#39;: [<br>            &#39;venue&#39;, &#39;ground&#39;, &#39;stadium&#39;, &#39;field&#39;, &#39;home&#39;, &#39;away&#39;, &#39;pitch&#39;,<br>            &#39;location&#39;, &#39;city&#39;, &#39;where&#39;<br>        ],<br>        &#39;performance&#39;: [<br>            &#39;performance&#39;, &#39;played&#39;, &#39;achievement&#39;, &#39;record&#39;, &#39;stats&#39;, &#39;statistics&#39;,<br>            &#39;numbers&#39;, &#39;figures&#39;, &#39;analysis&#39;<br>        ]<br>    }</pre><p>The system categorizes questions into different types of analysis — batting, bowling, venue statistics, or comparative analysis.</p><p>2. Smart Season Detection</p><pre>def extract_season_from_question(question, available_seasons):<br>    year_pattern = r&#39;\b(20\d{2})\b&#39;<br>    years = re.findall(year_pattern, question)<br>    valid_years = [int(year) for year in years <br>                  if int(year) in available_seasons]<br>    return valid_years[0] if valid_years else None</pre><p>3. The Power of Prompt Engineering</p><p>The heart of this system lies in its carefully crafted prompt structure. Here’s how I designed it:</p><pre>def create_cricket_prompt(question, available_seasons, df_info):<br>    &quot;&quot;&quot;Create a dynamic prompt based on the question complexity and available data&quot;&quot;&quot;<br>    <br>    # Extract season if mentioned<br>    season = extract_season_from_question(question, available_seasons)<br>    analysis_types = determine_analysis_type(question)<br>    <br>    base_prompt = f&quot;&quot;&quot;<br>    Analyzing IPL cricket data with following context:<br>    Available columns: {df_info}<br>    Question to analyze: {question}<br>    <br>    Analysis Guidelines:<br>    1. {f&#39;Focus on season {season}&#39; if season else &#39;Consider all available seasons if no specific season is mentioned&#39;}<br>    2. Identified analysis types: {&#39;, &#39;.join(analysis_types)}<br>    &quot;&quot;&quot;<br>    <br>    # Add context-specific instructions based on analysis types<br>    if &#39;comparative&#39; in analysis_types:<br>        base_prompt += &quot;&quot;&quot;<br>        For comparative analysis:<br>        - Establish clear baseline metrics<br>        - Calculate relative differences<br>        - Consider statistical significance<br>        - Present both absolute and percentage differences<br>        &quot;&quot;&quot;<br>    <br>    if &#39;conditional&#39; in analysis_types:<br>        base_prompt += &quot;&quot;&quot;<br>        For conditional analysis:<br>        - Clearly identify all conditions<br>        - Apply filters sequentially<br>        - Show results for each condition<br>        - Highlight notable patterns<br>        &quot;&quot;&quot;<br>    <br>    if &#39;trend&#39; in analysis_types:<br>        base_prompt += &quot;&quot;&quot;<br>        For trend analysis:<br>        - Show temporal progression<br>        - Calculate growth rates<br>        - Identify seasonal patterns<br>        - Note significant changes<br>        &quot;&quot;&quot;</pre><p>Also added several statistical formulas to the prompt like strike rate, boundary percentage etc.</p><p><strong>Data Foundation</strong></p><pre>@st.cache_data<br>def load_data():<br>    &quot;&quot;&quot;Load and prepare the cricket data&quot;&quot;&quot;<br>    try:<br>        deliveries_df = pd.read_csv(&#39;data/deliveries.csv&#39;)<br>        matches_df = pd.read_csv(&#39;data/matches.csv&#39;)<br>        <br>        # Convert seasons to numeric<br>        matches_df[&#39;season&#39;] = pd.to_numeric(matches_df[&#39;season&#39;].astype(str).str.split(&#39;/&#39;).str[0])<br>        <br>        # Merge dataframes<br>        df = pd.merge(<br>            deliveries_df,<br>            matches_df,<br>            left_on=&#39;match_id&#39;,<br>            right_on=&#39;id&#39;<br>        )<br>        return df<br>    except Exception as e:<br>        st.error(f&quot;Error loading data: {str(e)}&quot;)<br>        return None</pre><p><strong>Technical Implementation</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*J0F7HLZA-PIZs3A7dnpBEA.png" /></figure><p>Key Components:</p><ol><li>Data Processing:</li></ol><ul><li>Uses Pandas for data manipulation</li><li>Handles ball-by-ball and match data</li><li>Performs data merging and cleaning</li></ul><p>2. Query Understanding:</p><ul><li>Custom logic to interpret cricket questions</li><li>Pattern matching for analysis types</li><li>Season extraction</li></ul><p>3. UI</p><ul><li>Streamlit for clean, interactive interface</li><li>Conversation history tracking</li><li>Data info display</li></ul><p>4. Analysis Engine:</p><ul><li>PandasAI for data analysis</li><li>OpenAI integration for natural language processing</li><li>Custom prompt engineering</li></ul><p><strong>Data Flow</strong></p><ol><li>User inputs question through Streamlit interface</li></ol><p>2. Query is analyzed for analysis type and season</p><p>3. Custom prompt is generated based on question context</p><p>4. PandasAI processes the query using OpenAI</p><p>5. Results are formatted and displayed to user</p><p><strong>Real Results</strong></p><p>Let me show you some actual results from the tool. Below are few prompts and its responses:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*_cd6uGA75u9yUF-GBisZWg.png" /><figcaption>Which batsman hit the most sixes in 2024 season</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*SrQft9aQCMjEBsEdZm5oLg.png" /><figcaption>Show me the top wicket-takers in powerplay overs in 2024 season</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*Ga3qzsgkCudvrL0NRDJz1g.png" /><figcaption>Bumrah’s performance vs other bowlers in death overs in 2024 season</figcaption></figure><p><strong>Future Enhancements</strong></p><ol><li>Accounting for different match scenarios</li><li>Render the responses properly in a tabular format</li><li>Advanced visualization options</li><li>Player matchup scenarios</li><li>Strategy recommendations</li></ol><p><strong>Conclusion</strong></p><p>Cricket analytics doesn’t have to be overwhelming. With the right tools and approach, we can make data-driven insights accessible to everyone — from casual fans to professional analysts. This project demonstrates how GenAI can bridge the gap between complex statistics and actionable insights in sports analytics.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98b6c7ce80eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Text Preprocessing using Python]]></title>
            <link>https://medium.com/analytics-vidhya/text-preprocessing-using-python-ba4ae7971d8c?source=rss-e8b7d788b206------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba4ae7971d8c</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[text-preprocessing]]></category>
            <category><![CDATA[text-analytics]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Gopalkrishnan]]></dc:creator>
            <pubDate>Thu, 12 Dec 2019 10:33:11 GMT</pubDate>
            <atom:updated>2019-12-12T10:37:46.813Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EdoCpMX75nPMwvJXdjUlqg.png" /></figure><p>In this article, we will discuss how we will pre-process the text data so that it can be easy for machine to read and understand it.</p><p>Any machine learning or data modelling project, will have the following important steps to perform analytics:</p><ol><li>Acquire the data (excel, csv, DB, api etc.)</li><li>Go through the data</li><li>Handle missing values</li><li>Visualize the data</li><li>Preprocess or cleansing activity</li><li>Model</li><li>Prediction</li></ol><p>As far as text preprocessing is concerned , we do the following activities:</p><ul><li>Converting all letters to lower or upper case</li><li>Converting numbers into words or removing numbers</li><li>Removing punctuation and white spaces</li><li>Removing stop words</li></ul><p><strong>Converting letters to lower case:</strong></p><p>Python Code:</p><blockquote>text = “India played really well in the world cup against New Zealand”</blockquote><blockquote>text = text.lower()</blockquote><blockquote>print(text)</blockquote><p>Output:<br><strong> india played really well in the world cup against new zealand</strong></p><p><strong>Removing Numbers:</strong></p><p>Depending upon your analysis, one can wish to remove the digits from the data or not.</p><blockquote>Python Code:<br>import re</blockquote><blockquote>text = ‘What is the probability of getting a 2 or a 5 when a die is rolled?’</blockquote><blockquote>output = re.sub(r’\d+’, ‘’, text)</blockquote><blockquote>print(output)</blockquote><p><strong>Output:</strong></p><p><strong>What is the probability of getting a or a when a die is rolled?</strong></p><p><strong>Removing Punctuation:</strong></p><p>The following code removes this set of symbols [!”#$%&amp;’()*+,-./:;&lt;=&gt;?@[\]^_`{|}~]:</p><p><strong>Python Code:</strong></p><blockquote>import re</blockquote><blockquote>text = “This &amp;is [an] example? {of} string. with.? punctuation!!!!”</blockquote><blockquote>output = re.sub(r’[^\w\s]’,’’,text)</blockquote><blockquote>print(output)</blockquote><p><strong>Output:</strong></p><p><strong>This is an example of string with punctuation</strong></p><p><strong>Remove White-spaces:</strong></p><p>Python Code:</p><blockquote>text = “ \t a sentence with white-spaces\t “</blockquote><blockquote>text = text.strip()</blockquote><blockquote>text</blockquote><p>Output:<br><strong> ‘a sentence with white-spaces’</strong></p><h3>Remove stop words</h3><p>“Stop words” are the most common words in a language like “the”, “a”, “on”, “is”, “all”. These words do not carry any important meaning and are usually removed from texts. We can remove those words by using a library called, Natural Language Toolkit(NLTK)</p><blockquote><strong>Python Code:</strong><br>import nltk</blockquote><blockquote>from nltk.corpus import stopwords</blockquote><blockquote>text = “Actor-politician Rajinikanth celebrates his 69th birthday on Thursday. Both politicians and film personalities have taken to social media to wish the superstar.”</blockquote><blockquote>stop_words = set(stopwords.words(‘english’))</blockquote><blockquote>from nltk.tokenize import word_tokenize</blockquote><blockquote>tokens = word_tokenize(text)</blockquote><blockquote>output = [i for i in tokens if not i in stop_words]</blockquote><blockquote>print (output)</blockquote><p>Output:</p><p><strong>[‘Actor-politician’, ‘Rajinikanth’, ‘celebrates’, ‘69th’, ‘birthday’, ‘Thursday’, ‘.’, ‘Both’, ‘politicians’, ‘film’, ‘personalities’, ‘taken’, ‘social’, ‘media’, ‘wish’, ‘superstar’, ‘.’]</strong></p><p>Scikit and Spacy also provides a stop words list, which we can use to remove unnecessary words from a text data.</p><h3>Named entity recognition</h3><p>Named-entity recognition (NER) aims to find named entities in text and classify them into pre-defined categories (names of persons, locations, organizations, times, etc.).</p><p><strong>Python Code:</strong></p><blockquote>from nltk import word_tokenize, pos_tag, ne_chunk</blockquote><blockquote>input_str = “User has confirmed that this issue has been resolved .”</blockquote><blockquote>print((pos_tag(word_tokenize(input_str))))</blockquote><p>Output:</p><p><strong>[(‘User’, ‘NNP’), (‘has’, ‘VBZ’), (‘confirmed’, ‘VBN’), (‘that’, ‘IN’), (‘this’, ‘DT’), (‘issue’, ‘NN’), (‘has’, ‘VBZ’), (‘been’, ‘VBN’), (‘resolved’, ‘VBN’), (‘.’, ‘.’)]</strong></p><p>The fun part is we can extract just the noun part alone from a sentence and can remove from sentence depending upon what kind of analysis we are performing.<br>Python Code:</p><blockquote>from nltk import word_tokenize, pos_tag, ne_chunk</blockquote><blockquote>input_str = “Virat Kohli made a fantastic hundred,which led India to a comprehensive victory .”</blockquote><blockquote>is_noun = lambda pos: pos[:2] == ‘NN’</blockquote><blockquote># do the nlp stuff</blockquote><blockquote>tokenized = nltk.word_tokenize(input_str)</blockquote><blockquote>nouns = [word for (word, pos) in nltk.pos_tag(tokenized) if is_noun(pos)]</blockquote><blockquote>print(nouns)</blockquote><p>Output:</p><p><strong>[‘Virat’, ‘Kohli’, ‘india’, ‘victory’]</strong></p><p>There are many other text preprocessing activities which will further clean the data for better analysis:</p><ol><li>Stemming</li><li>Lemmatization</li><li>Chunking</li><li>Relationship extraction</li></ol><p><strong>Summary:</strong></p><p>In this article we discussed about text preprocessing by removing stopwords, numbers,punctuation and named entity recognition. Once the text is cleaned properly we can create the model for better performance and accuracy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba4ae7971d8c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/text-preprocessing-using-python-ba4ae7971d8c">Text Preprocessing using Python</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Story 1: How to extract data from an endpoint using django REST API]]></title>
            <link>https://medium.com/@gopal.k1991/story-1-how-to-extract-data-from-an-endpoint-using-django-rest-api-6953187f2bf3?source=rss-e8b7d788b206------2</link>
            <guid isPermaLink="false">https://medium.com/p/6953187f2bf3</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[requests-library]]></category>
            <dc:creator><![CDATA[Gopalkrishnan]]></dc:creator>
            <pubDate>Mon, 09 Sep 2019 09:51:08 GMT</pubDate>
            <atom:updated>2019-09-09T09:51:08.267Z</atom:updated>
            <content:encoded><![CDATA[<p>Without data we can’t kick-start the data science process, thus we won’t be able to make predictions or classifications. A data scientist or a ML developer can’t expect a data to be in csv or excel format always. Data scientist should be capable enough to extract data from whatever source it comes from!!</p><p>There was a situation in my project where i had to extract data from an endpoint and pass it through a Machine learning model to classify them according to different categories. Being an amateur developer, it was very new and challenging to me. In this story, i will explain about API and how to extract data from an API endpoint and in the next story we will process the data in database by writing django RESTful API.</p><p>Tools used to perform this are:</p><ul><li>Python</li><li>Django</li></ul><p>What is API?</p><blockquote>API is Application programming interface with which two applications can interact. One of the best example for API usage, is the live location sharing in <strong>whatsapp</strong>, which uses Google MAP API.</blockquote><p>What is REST API?</p><p><strong>REST</strong> is an application architecture model that is usually implemented in the form of functions that send requests and receive responses via Hypertext Transfer Protocol (HTTP). The best thing about REST is that it is not strictly implemented in any particular language or format. Rather, the protocol could be easily integrated into any web app using any language, as long as the core constraints of the REST are in place. Using REST APIs, all web apps that use HTTP (that includes everything on WWW!) is able to link and exchange data in a very simple and easy to implement format. As for sending data back and forth, the json format is very popular.</p><p>Let’s get into action!</p><p>In Python, we are lucky to have an excellent HTTP library: requests. If you don’t have the requests library, you can install it with the command:</p><blockquote>pip install requests</blockquote><p>Now let’s say you want to get a list of action items, via the GET endpoint:</p><blockquote><strong>import requests #importing the requests library</strong></blockquote><blockquote><strong>URL = “</strong><a href="https://jsonplaceholder.typicode.com/todos/1"><strong>https://jsonplaceholder.typicode.com/todos/1</strong></a><strong>&quot; #api endpoint</strong></blockquote><blockquote><strong>r = requests.get(url = URL) <em>#sending get request and saving the response as an object</em></strong></blockquote><blockquote><strong>data=r.json() #extracting data in json format</strong></blockquote><p>print(data) will give you a dictionary of items present in that endpoint. The output is:</p><blockquote><strong>{‘completed’: False, ‘id’: 1, ‘title’: ‘delectus aut autem’, ‘userId’: 1}</strong></blockquote><p>We can also iterate through the keys and values of the dictionary you are working with:</p><blockquote><strong>for key,value in data.items():<br> print (key,’-&gt;’,value)</strong></blockquote><p>Which will give us the following output:</p><blockquote><strong>userId -&gt; 1 id -&gt; 1 title -&gt; delectus aut autem completed -&gt; False</strong></blockquote><p>Here are some important points to ponder upon:</p><ol><li>We should be having access to the API ENDPOINT, then only we can extract data from the endpoint. All the api endpoints have secured keys, and we have to pass them as well in get() function to access data.</li><li>I have used a free api endpoint to illustrate the above example which doesn’t have any password. There are tons of site available which gives free api endpoints to play around.</li><li>There are other methods like PUT,POST and DELETE. I have explained the GET task only, because that is the very first step for extracting data in the process of Data science and Machine learning.</li></ol><p>In the next story, i will explain how to write a django rest framework and process the extracted data in the DB.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6953187f2bf3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>