<?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 Dinesh on Medium]]></title>
        <description><![CDATA[Stories by Dinesh on Medium]]></description>
        <link>https://medium.com/@ghanta.dinesh?source=rss-1f84211fcd7b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Dinesh on Medium</title>
            <link>https://medium.com/@ghanta.dinesh?source=rss-1f84211fcd7b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 18:23:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ghanta.dinesh/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[Leveraging LLM: A Powerful Approach to Solving Machine Learning Problems]]></title>
            <link>https://medium.com/@ghanta.dinesh/leveraging-llm-a-powerful-approach-to-solving-machine-learning-problems-1f950af151fb?source=rss-1f84211fcd7b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f950af151fb</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[large-language-models]]></category>
            <dc:creator><![CDATA[Dinesh]]></dc:creator>
            <pubDate>Mon, 02 Oct 2023 09:45:43 GMT</pubDate>
            <atom:updated>2023-10-03T09:40:46.557Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction:</h3><p>Machine learning has transformed the way we solve problems, and with the advent of powerful language models like GPT-3.5 (Large Language Model), we have a remarkable tool at our disposal. In this blog post, we’ll delve into a practical example of utilizing LLM to enhance machine learning performance. We’ll use a simple banking dataset to predict whether a customer will subscribe for a term deposit or not. We’ll compare traditional random forest modelling with an approach that incorporates LLM through sentence transformers.</p><h3>Understanding the Banking Dataset:</h3><p>We’ll begin by introducing the dataset we’ll be working with. The banking dataset is publicly available and can be accessed [here](<a href="https://archive.ics.uci.edu/dataset/222/bank+marketing">https://archive.ics.uci.edu/dataset/222/bank+marketing</a>). This dataset contains various features related to banking, such as age, job, marital status, education, and more. Based on these features, the goal is to predict whether a customer will subscribe to a term deposit.</p><h3>Methodology:</h3><p>We will follow a two-step methodology:</p><ol><li><strong>Train a baseline model using a traditional machine learning algorithm.</strong> In this case, we will use a random forest classifier.</li><li><strong>Train a model using LLM sentence embeddings.</strong> We will use the SentenceTransformer library to convert the dataset to embedding vectors, and then train a random forest classifier on the embedding vectors.</li></ol><h4>Step 1: Traditional Random Forest Model</h4><p>We’ll start by building a machine-learning model using the Random Forest algorithm on the original dataset. Random Forest is a popular ensemble learning method that can handle classification tasks effectively.</p><pre>import pandas as pd<br>import matplotlib.pyplot as plt<br>import seaborn as sns<br># model<br>from sklearn.ensemble import RandomForestClassifier<br># Accuracy testing<br>from sklearn.metrics import accuracy_score, confusion_matrix, classification_report<br> <br> <br># Reading training and testing data<br>train_df = pd.read_csv(&#39;train.csv&#39;,sep=&#39;;&#39;)<br> <br> <br>print(train_df.shape)<br>train_df.head()<br> <br># Training dataset<br> <br># Removing the Target Feature &#39;y&#39; from the dataset to model<br>train_x = train_df.iloc[:, :-1]<br># Getting the target feature to compare with the predictions made<br>train_target = train_df.y<br> <br>train_x.head()<br> <br># Object Columns need to be Converted to Numerical values to model<br>encoding_columns = list(train_x.select_dtypes(include=object))<br> <br># encoding_columns<br>encoding_columns<br> <br># Performing Label Encoding<br>edu = {&#39;unknown&#39;: 0,<br>       &#39;primary&#39;: 1,<br>       &#39;secondary&#39;: 2,<br>       &#39;tertiary&#39;: 3}<br> <br># On Training Dataset<br>train_x[&#39;education&#39;] = train_x[&#39;education&#39;].replace(edu)<br><br> <br>print(train_x[&#39;education&#39;].value_counts())<br> <br> <br># Selecting columns for One Hot Encoding<br>ohe_cols = list(train_x.select_dtypes(include=object))<br> <br># Performing One Hot on columns<br>train_x = pd.get_dummies(train_x ,columns = ohe_cols ,prefix=ohe_cols)<br><br>train_x.head()<br> <br># Randomforest Model<br>model = RandomForestClassifier(random_state=42)<br>train_prediction = model.predict(train_x)<br>print(train_prediction[:5])<br>train_target.iloc[:5]<br><br>accuracy = accuracy_score(train_target, train_prediction)<br><br>print(&quot;Accuracy is: &quot;, accuracy)plt.title(&quot;Confusion matrix on Training Data&quot;)<br>sns.heatmap(confusion_matrix(train_prediction, train_target), annot=True, fmt=&#39;d&#39;)<br>plt.xlabel(&quot;Actual Labels&quot;)<br>plt.ylabel(&quot;Predicted Labels&quot;)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4yivRUSArAPrubuZ4lZQaQ.png" /></figure><h4>Step 2: Leveraging LLM Sentence Transformer</h4><p>Next, we’ll leverage the power of LLM, particularly a sentence transformer, to enhance our model. Sentence transformers can convert textual data into meaningful numerical representations (embeddings), capturing semantic information. We’ll transform the dataset using the sentence transformer, generating embedding vectors for each text entry.</p><p>After obtaining the embeddings, we’ll train another Random Forest model using these embeddings as features. This hybrid approach integrates the strength of traditional machine learning with the semantic understanding provided by LLM.</p><pre>import pandas as pd <br>import numpy as np <br><br>from sentence_transformers import SentenceTransformer<br><br>df = pd.read_csv(&quot;train.csv&quot;, sep = &quot;;&quot;)<br>#Convert dataset to text<br>def compile_text(x):<br>    text =  f&quot;&quot;&quot;Age: {x[&#39;age&#39;]},<br>                housing load: {x[&#39;housing&#39;]},<br>                Job: {x[&#39;job&#39;]},<br>                Marital: {x[&#39;marital&#39;]},<br>                Education: {x[&#39;education&#39;]},<br>                Default: {x[&#39;default&#39;]},<br>                Balance: {x[&#39;balance&#39;]},<br>                Personal loan: {x[&#39;loan&#39;]},<br>                contact: {x[&#39;contact&#39;]}<br>                &quot;&quot;&quot;<br>     return text<br><br>#Create sentences<br>sentences = df.apply(lambda x: compile_text(x), axis=1).tolist()<br><br># Sentence transformer Model Hugging face model<br>llm_model = SentenceTransformer(r&quot;sentence-transformers/paraphrase-MiniLM-L6-v2&quot;)<br><br>output = model.encode(sentences=sentences,<br>                      show_progress_bar=True,<br>                      normalize_embeddings=True)<br>embeddings = pd.DataFrame(output)<br><br>train_target = df.y<br><br>llm_model.fit(embeddings,train_target)<br>train_prediction = llm_model.predict(embeddings)<br>print(train_prediction[:5])<br>train_target.iloc[:5]<br><br>accuracy = accuracy_score(train_target, train_prediction)<br>print(&quot;Accuracy is: &quot;, accuracy)<br><br>plt.title(&quot;Confusion matrix on Training Data&quot;)<br>sns.heatmap(confusion_matrix(train_prediction, train_target), annot=True, fmt=&#39;d&#39;)<br>plt.xlabel(&quot;Actual Labels&quot;)<br>plt.ylabel(&quot;Predicted Labels&quot;)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qdI8WXmfRZbnGcJSQfFQBQ.png" /></figure><h4>Evaluation and Results:</h4><p>We perform a thorough comparative analysis, evaluating both models using standard metrics like accuracy, precision, recall, and F1 score. The traditional Random Forest model, despite achieving 100% accuracy, demonstrates its limitations in handling the classification task effectively. On the other hand, the LLM-powered model, with its 98% accuracy, presents a more balanced and meaningful classification, affirming the efficacy of leveraging advanced language models.</p><h3>Conclusion:</h3><p>This blog post highlighted the significance of incorporating Large Language Models (LLMs) in machine learning processes. LLMs are a powerful new tool for solving machine-learning problems. The comparison between a traditional Random Forest model and an LLM-powered model clearly demonstrated the latter’s superior performance and accurate classification. The use of LLMs enhances the model’s ability to understand and represent the data’s semantic context, ultimately leading to more meaningful and reliable predictions. As we continue to advance in the realm of machine learning, embracing innovative technologies like LLMs will undoubtedly reshape the landscape of predictive analytics and decision-making. They can be used to improve the performance of traditional machine-learning algorithms, and they can also be used to develop new machine-learning models that are capable of performing</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f950af151fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>