<?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 Anshit Vishwakarma on Medium]]></title>
        <description><![CDATA[Stories by Anshit Vishwakarma on Medium]]></description>
        <link>https://medium.com/@anshitvishwa111?source=rss-44f264c57ecc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*H8LM_u3Q41tupqcM2RI8JA@2x.jpeg</url>
            <title>Stories by Anshit Vishwakarma on Medium</title>
            <link>https://medium.com/@anshitvishwa111?source=rss-44f264c57ecc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 04:08:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anshitvishwa111/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[Can You Ever Prove Something Was Written by AI?]]></title>
            <link>https://medium.com/@anshitvishwa111/can-you-ever-prove-something-was-written-by-ai-4ac2cd28bf14?source=rss-44f264c57ecc------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ac2cd28bf14</guid>
            <category><![CDATA[anthropic-claude]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[watermark]]></category>
            <dc:creator><![CDATA[Anshit Vishwakarma]]></dc:creator>
            <pubDate>Thu, 20 Aug 2026 11:43:35 GMT</pubDate>
            <atom:updated>2026-08-20T11:43:35.824Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Anthropic just started watermarking everything Claude writes. So I built a watermark myself, attacked it, and found the number nobody is talking about.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*9xwLq4iu3M3jFYTGCC6-6Q.png" /><figcaption>First it was memes. Now they’re watermarking our AI responses too. What’s next? 😭</figcaption></figure><p>Imagine you are a student. You wrote your essay yourself. Every word. You ran it through a grammar checker, because everyone does, and you handed it in.</p><p>Three days later you are sitting across from a professor who has printed your essay with a number stamped on the top: <strong>98% AI-generated</strong>. There is a meeting scheduled with the academic integrity board. You are asked to prove you wrote it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*4zlS0R8DqBPsX3cQvyrFjw.png" /><figcaption>Academic integrity board se resignation nahi maang sakte bhai</figcaption></figure><p>How exactly would you do that?</p><p>This scenario stopped being hypothetical this month. On August 2nd, Anthropic began embedding an invisible watermark into <strong>every single thing Claude writes</strong>. Not a label. Not a disclaimer you can delete. A statistical fingerprint woven into the word choices themselves, which travels with the text when you copy and paste it anywhere.</p><p>The internet reacted about how you would expect. Reddit threads called it a scarlet letter and a digital tattoo. Users posted screenshots of cancelled subscriptions. Others fired back that the only reason to object is if you were planning to lie about it.</p><iframe src="https://cdn.embedly.com/widgets/media.html?type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=twitter&amp;url=https%3A//x.com/Hesamation/status/2087877713327538244&amp;image=https%3A//i.embed.ly/1/image%3Furl%3Dhttps%253A%252F%252Fpbs.twimg.com%252Fmedia%252FHPmhtqSW8AAUauP.jpg%253Alarge%26key%3Da19fcc184b9711e1b4764040d3dc5c07" width="500" height="281" frameborder="0" scrolling="no"><a href="https://medium.com/media/2cbe53f5e912ddfea7ff877233219c5a/href">https://medium.com/media/2cbe53f5e912ddfea7ff877233219c5a/href</a></iframe><p>Almost nobody in that argument was discussing whether the thing actually works.</p><p>So I built one. I implemented a text watermark from scratch, ran it through an AI model, then tried to break it — and measured what happened at every step. What follows is what the experiments actually showed, including one result that contradicts what most people confidently believe, and one number that should worry anyone who has ever been accused by a detector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*Msu8y19FvX6cLall-R15sg.png" /><figcaption>Hit the follow button, my brotha!</figcaption></figure><h3>First: a watermark is not an AI detector</h3><p>These two things get mashed together constantly, and the entire story falls apart if you confuse them.</p><p>An <strong>AI detector</strong> — the kind schools have used for two years — reads your text and guesses. It looks for tell-tale writing habits: a certain rhythm, a fondness for phrases like “it’s not X, it’s Y.” It is essentially a very well-read bouncer squinting at your ID. It has no idea what actually happened. It is pattern-matching on style.</p><p>A <strong>watermark</strong> is a different animal entirely. The signal is deliberately planted at the moment the text is created, by the company that made the model. You are no longer guessing at style. You are checking for a signature you already know the shape of.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vmdF8X1UGxk9h0t4Cdvj4A.png" /><figcaption>A simple illustrator to explain the difference between the two!</figcaption></figure><p>Anthropic itself drew this line, saying that spotting stylistic tells is fundamentally different from checking a watermark. They are right, and it matters more than the outrage cycle noticed.</p><p>Here is how the watermark works, stripped of all mathematics.</p><p>Every time the AI picks a word, it usually has several that would work fine. Overcast or grey. Started or began. Before it chooses, a secret key silently splits the dictionary into two halves — call them the <strong>green list</strong> and the red list. The AI is then nudged, gently, to prefer green words. Not forced. Nudged.</p><p>Any single word tells you nothing. A human writer would land on green words 25% of the time purely by chance, because that is how the split was drawn. But across hundreds of words, the nudges pile up into something no coincidence can explain.</p><p>That is the entire trick. And in my experiment it looked like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*6N93yjdmPqM3ZjYzVxHK_g.png" /><figcaption><em>Human-written text lands on green words at almost exactly the rate you would expect from chance. Watermarked text does not.</em></figcaption></figure><p>Twenty-seven percent versus sixty-two percent. If you flipped a coin 120 times and got heads 62% of the time, you would stop believing it was a fair coin. That is the same reasoning, and it is the <em>only</em> reasoning involved.</p><h3>Finding 1: Length is everything</h3><p>Here is the first thing that surprised me. Whether a text can be identified as AI-written is not really a property of the text. It is a property of how much of it you have.</p><p>Evidence accumulates. Each word contributes a tiny nudge of confidence, and those nudges add up — but slowly, and with diminishing returns. Double the length and you do not double the certainty.</p><p>I took watermarked passages and chopped them to different lengths to see when detection became reliable:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*aVpkTduGXPOm8s7PKCWw8A.png" /><figcaption><em>Below roughly 20 words, there is simply nothing to find. By essay length, detection is near-perfect.</em></figcaption></figure><p>A tweet cannot be watermarked. Not “is hard to” — <strong><em>cannot</em></strong>. There is not enough room in a sentence for a statistical pattern to separate itself from coincidence. A product description, a Slack message, a text to your landlord: all effectively invisible.</p><p>An essay, a cover letter, a news article? Caught, easily, every time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/0*MxMEIfMzRQKTqUnM" /><figcaption>@grok is this true ?</figcaption></figure><h3>Finding 2: The watermark can only ride on freedom</h3><p>This is the result I found most interesting, and the one I have not seen reported anywhere.</p><p>Anthropic mentioned in passing that code carries less of a watermark than prose, because when writing code the model has fewer genuinely interchangeable options. Every outlet repeated this. Nobody checked it.</p><p>So I measured, for every single word the model produced, how much genuine choice it had at that moment — and then whether the watermark managed to attach itself there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*Gty-UTkcsdj2lkpz1lTZgw.png" /><figcaption><em>Left: the watermark thrives on free choices and vanishes on forced ones. Right: the signal fades smoothly to nothing as freedom disappears.</em></figcaption></figure><p>When the model was writing freely — storytelling, description, argument — the green rate hit <strong>74%</strong>. Overwhelming evidence.</p><p>When the next word was essentially forced — a closing bracket, required syntax, the second half of a common phrase — the green rate was <strong>20%</strong>. That is <em>below</em> the 25% chance line. Not weak evidence. Not faint evidence. Statistically indistinguishable from noise. Zero.</p><p>And in my sample, 22% of all words fell into that dead zone.</p><p>So the code caveat is not a footnote or a temporary bug. It is structural. A watermark is a message hidden inside choices, and where there are no choices, there is no message. The more constrained the writing — code, legal boilerplate, technical documentation, a recipe, a formula — the less of it survives.</p><blockquote><strong>Why this matters: </strong>Anthropic said code is harder to watermark. This experiment shows why, from first principles: it is not that the system is worse at code, it is that code does not contain enough arbitrary decisions to hide a signal in.</blockquote><h3>Finding 3: Paraphrasing does not save you</h3><p>Go read any thread about this and you will find the same confident advice repeated: just reword it. Swap some synonyms, restructure a few sentences, and the watermark is gone.</p><p>I tested it. I took watermarked passages and replaced an increasing share of the words with synonyms, then re-checked each one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*Y6JgFpCOTf5HMQFYuESdUQ.png" /><figcaption><em>Even with half of every word replaced, the watermark survived in 88% of passages.</em></figcaption></figure><p>Replace 30% of the words: caught 100% of the time. Replace half of them: still caught 88% of the time. The signal only genuinely collapsed past 70% replacement — at which point the text had degraded into unreadable nonsense.</p><p>Here is a real sample from my experiment at 50% replacement:</p><p><em>“She suggested that year teetotal bottomland represent a sign of warmer conditions and preferred person whiteness roof over fact rough case branches…”</em></p><p>That passage is still flagged as AI-written. It is also worthless as writing. That is the trap: by the time you have edited enough to erase the watermark, you have destroyed the thing you were trying to keep.</p><blockquote>Anthropic said light editing probably will not remove the watermark. Based on my results, that is an understatement. Heavy editing barely removes it either.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*gwrXMIsxuqvhmYnLeAUYkw.png" /><figcaption>Corporate wants you to find the difference !?</figcaption></figure><p>There is an honest counterpoint. Feeding text through a different AI to rewrite it wholesale is far more effective than swapping synonyms by hand. But as Anthropic pointed out, at that stage it is fair to ask whether the result is really your writing at all.</p><h3>The number nobody is talking about</h3><p>Everything so far might suggest watermarking is a triumph. In a narrow sense, it is. In my tests it separated AI text from human text perfectly, with a false positive rate near zero. Compared to the style-guessing detectors schools currently rely on, that is a genuine and underappreciated improvement.</p><p>But there is a gap at the centre of this that no amount of clever mathematics can close.</p><p>Every detection test answers this question: <strong><em>“If a human wrote this, how surprising would this evidence be?”</em></strong></p><p>Nobody has ever been punished based on that question. What actually matters to the student in that meeting is the reverse: <strong><em>“Given this evidence, what is the chance I actually cheated?”</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*9hVgAvCCE8lu2Ix4A2Mq5Q.png" /><figcaption>*Le Students after making that statement!</figcaption></figure><p>These sound like the same question. They are not, and treating them as identical has a name in law and statistics.</p><blockquote><strong>The prosecutor’s fallacy: </strong>Confusing “this evidence would be rare if you were innocent” with “you are probably guilty.” They only match up if you also know how common the crime is to begin with. Ignore that, and you convict innocent people at scale.</blockquote><p>The bridge between those two questions is something no detector can measure: how many people were actually cheating in the first place.</p><p>Take a realistic classroom. 500 essays. A typical style-based AI detector that catches 90% of cheaters and falsely flags 5% of honest students. Suppose 5% of the class genuinely used AI.</p><p>Here is what that looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*_B-yBFOWAlfph-r4o-IYsg.png" /><figcaption><em>Each square is one student. Red squares are people who did nothing wrong and got accused anyway.</em></figcaption></figure><p>The detector flags 46 students. Twenty-two of them cheated. <strong>Twenty-four did not.</strong></p><p>A flagged student is guilty with a probability of <strong>49%</strong>. The accusation carries less information than a coin flip. And this is with a detector that sounds impressive when you describe it as “90% accurate.”</p><p>It gets worse. Detectors are known to disproportionately flag people writing in English as a second language — their more measured, more conventional phrasing reads as machine-like. Push the false alarm rate up to 20% for that group, and the chance a flagged student actually cheated collapses to roughly 1 in 5.</p><p>The watermark genuinely fixes part of this. Its false positive rate is not 5% — it is closer to 1 in 30,000, and unlike a style detector, that number is calculable in advance rather than hopefully estimated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*EJVKGwIA69F-SCPtzpicfA.png" /><figcaption><em>A watermark check stays trustworthy even when AI use is rare. Style-based detectors fall apart exactly where they are used most.</em></figcaption></figure><p>That difference is real and it deserves more credit than the backlash gave it. But notice what it does not fix.</p><h3>So — can you ever prove it?</h3><p>After building the thing and trying to break it, here is my honest answer.</p><p>A watermark can establish that <strong>a particular passage of text came out of a particular AI model</strong> with about as much confidence as statistics ever offers. On a full essay, the evidence is overwhelming. That part is close to solved.</p><p>But look at what it still cannot tell you:</p><ul><li>Who typed the prompt.</li><li>Whether the person wrote a full draft first and asked for edits, or asked for the whole thing from nothing.</li><li>Whether the ideas, structure and argument were theirs.</li><li>Whether using AI was even against the rules in their situation.</li></ul><p>A watermark detects a tool. It cannot detect dishonesty. Those are not the same thing, and the distance between them is exactly where a student, a journalist, or an employee gets hurt.</p><p>The Reddit user who complained about getting a digital tattoo for asking Claude to reorganise a paragraph was, technically, wrong — my results suggest light editing of your own writing leaves almost nothing for the watermark to grab onto. But the underlying fear was not irrational. It was aimed at the wrong target. The danger was never the watermark. It is the <strong>institution that treats any positive result as a verdict</strong>, without asking how many people it is testing, how many of them were ever likely to be guilty, and what happens to the ones it gets wrong.</p><p>We are about to hand that institution a much sharper instrument. Sharper instruments are only an improvement in careful hands.</p><p>The question worth arguing about was never whether AI text can be detected. It increasingly can. The question is who gets to run the test, at what confidence threshold, and what a person is owed when the number on the printout is wrong.</p><p>Right now, nobody has answered that. And unlike the watermarking problem, no amount of clever mathematics is going to answer it for us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*3zxQZ7hQ5INEJjqZz2Iitw.gif" /><figcaption>Peace out !</figcaption></figure><blockquote><strong>How I ran this</strong></blockquote><blockquote>I implemented a green-list text watermark of the kind described by Kirchenbauer and colleagues in 2023, applied it to an open language model, and measured detection using a standard statistical test. Anthropic’s production system uses a different and more sophisticated algorithm from Google DeepMind called SynthID-Text. The underlying logic — bias low-stakes word choices using a secret key, then test the result against chance — is shared, and that logic is what these experiments probe.</blockquote><blockquote>Nothing here reverse-engineers or defeats any deployed system. The paraphrasing experiment measures how quickly evidence decays, which is what determines whether an accusation is defensible; it is not a recipe for evading anything, and as the sample above shows, it does not work anyway.</blockquote><blockquote>The full notebook is published alongside this article. Run it yourself and check my numbers.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ac2cd28bf14" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hosting Machine Learning Models as an API Service]]></title>
            <link>https://medium.com/@anshitvishwa111/hosting-machine-learning-models-as-an-api-service-1cf5cb5a1e2f?source=rss-44f264c57ecc------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cf5cb5a1e2f</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[postman]]></category>
            <dc:creator><![CDATA[Anshit Vishwakarma]]></dc:creator>
            <pubDate>Fri, 05 Jul 2024 00:32:45 GMT</pubDate>
            <atom:updated>2024-07-05T02:09:27.641Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello everyone, and welcome to my second article, which delves a bit deeper into technical territory. Over the past few months, I’ve been immersed in the world of hosting machine learning models as API services, a process that enables others to utilize these models seamlessly. In this article, we’ll break down each step of this process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KDR5kN0VVZaxBUCb.jpeg" /><figcaption>are you guys reading research papers?</figcaption></figure><h3>Why Host ML Models as a Service?</h3><p>As a Python developer and data scientist, I have a desire to build web apps to showcase my work. However, managing both machine learning and app development can be overwhelming. Therefore, I needed a solution to easily integrate my machine learning models with web applications developed by others who might have more expertise in that area.</p><p>By building a REST API for my model, I can keep my code separate from other developers. This clear division of labor helps define responsibilities and prevents me from directly blocking teammates who are not involved with the machine learning aspect of the project. Another advantage is that my model can be used by multiple developers working on different platforms, such as web or mobile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iVQz_wmxgvoD4vqi.jpeg" /><figcaption>Not sure if REST stands for Relaxation</figcaption></figure><p>In this article, I’ll walk you through this process and cover the following aspects and steps:</p><ol><li>Choose a framework</li><li>Prepare your model</li><li>Define your API endpoints</li><li>Testing the API</li><li>Testing with Postman</li><li>Deployment</li></ol><h3>Choose a Framework: Flask</h3><p>The reason for selecting Flask is that it is a very light web framework that helps in creating web apps with minimal lines of code. Although there are many frameworks for Python for creating web apps like Django, Web2py, Grok, TurboGears, etc., Flask allows for quick and easy development, making it a great tool for beginners who want to learn building web applications. Flask relies completely on Python for coding-related tasks, rather than depending on other tools. To use Flask effectively, you should have a good understanding of Python, a bit of HTML and CSS, and a database management system if any kind of data-related work is involved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/0*zJHwBzo5j0TT9AOG.jpg" /><figcaption>I can do this all day!</figcaption></figure><h4>Features of Flask</h4><ul><li><strong>Lightweight and flexible</strong>: Highly customizable and can be used for a wide range of applications.</li><li><strong>Built-in development server and debugger</strong>: Makes it easy to test and debug your application.</li><li><strong>Extensible</strong>: A wide range of plugins and extensions can be used to extend the functionality of the framework.</li><li><strong>Supports various templating engines</strong>: Easy to render dynamic content in your application.</li></ul><h4>Pros of Flask</h4><ul><li><strong>Easy to use</strong>: Simple API and documentation.</li><li><strong>Flexible and customizable</strong>: Suitable for a wide range of applications.</li><li><strong>Good for small to medium-sized applications</strong>: Great choice for building small to medium-sized applications.</li><li><strong>Great for rapid prototyping and development</strong>.</li></ul><h4>Cons of Flask</h4><ul><li><strong>Not suitable for large-scale applications</strong>: Due to its nature, Flask is unsuitable for building large and complex projects.</li><li><strong>Limited functionality compared to other frameworks</strong>: Flask may not have as much built-in functionality as other frameworks.</li><li><strong>Requires additional setup for larger applications</strong>.</li></ul><h3>Prepare Your Model</h3><p>For the purpose of this article, I’ll use a simple example of a machine learning model. I have a customer database of an e-commerce company, which includes attributes such as average session length, average time spent on the app, time spent on the website, length of membership, and yearly amount spent by the user.</p><p>The company wants a model to predict the expected yearly amount spent by existing as well as new users to help focus on customers who can generate more revenue in the future. Let’s delve into coding this ML problem!</p><pre># Import necessary libraries<br>import pandas as pd  # For data handling<br>import pickle       # For saving the trained model<br>from sklearn.model_selection import train_test_split  # For splitting data<br>from sklearn.linear_model import LinearRegression  # For fitting the model<br><br># Load the dataset from a CSV file<br>df = pd.read_csv(&#39;Ecommerce Customers.csv&#39;)<br><br># Define the features (input) and label (output) columns<br>features = [&#39;Avg. Session Length&#39;, &#39;Time on App&#39;, &#39;Time on Website&#39;, &#39;Length of Membership&#39;]<br>label = &quot;Yearly Amount Spent&quot;<br><br># Extract input features (X) and output labels (y)<br>X = df[features]<br>y = df[label]<br><br># Split the data into training and testing sets<br>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4, random_state=42)<br><br># Create a Linear Regression model<br>regression_model = LinearRegression()<br><br># Train the model on the training data<br>regression_model.fit(X_train, y_train)<br><br># Make predictions using the trained model<br>predictions = regression_model.predict(X_test)<br><br># Print the model&#39;s predictions<br>print(predictions)<br><br># Save the trained model to a file named &quot;model.pkl&quot;<br>pickle.dump(regression_model, open(&quot;model.pkl&quot;, &quot;wb&quot;))</pre><p>This model is for tutorial purposes and can be improved in many ways. The pickle.dump(regression_model, open(&quot;model.pkl&quot;, &quot;wb&quot;)) line saves the trained model to a file named model.pkl, allowing it to be loaded later for making predictions without retraining.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*27J3JB-PTpcyIcoX.jpg" /><figcaption>Hard times create strong men, strong men create good times, good times create weak men, and weak men create hard times</figcaption></figure><h3>Define Your API Endpoints</h3><p>An API endpoint is a URL that your application uses to access your model. When a user sends a request to your API endpoint, the server processes the request and sends the response back to the client. You may also need to indicate any authentication or security protocols required, such as an API key or OAuth token.</p><p>The following code creates a Flask web application to load a machine learning model. When we run the app, it will be in debug mode to help identify and fix issues during development. We also define a /predict route that accepts HTTP POST requests, expecting a JSON payload containing data. It converts this JSON data into a DataFrame, uses the loaded model to make predictions, and returns the predictions as a JSON response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/0*bTYEExoSjexyhz6M" /><figcaption>potato, potahto</figcaption></figure><pre>import pandas as pd<br>import pickle<br>from flask import Flask, request, jsonify<br><br># Create a Flask app<br>app = Flask(__name__)<br><br># Load the machine learning model from a pickle file<br>model = pickle.load(open(&quot;model.pkl&quot;, &quot;rb&quot;))<br><br>@app.route(&#39;/keepalive&#39;, methods=[&#39;GET&#39;])<br>def api_health():<br>    return jsonify(Message=&quot;Success&quot;)<br><br># Define a route for making predictions<br>@app.route(&quot;/predict&quot;, methods=[&quot;POST&quot;])<br>def predict():<br>    # Get JSON data from the request<br>    json_ = request.json<br><br>    # Convert JSON data into a DataFrame<br>    df = pd.DataFrame(json_)<br><br>    # Use the loaded model to make predictions on the DataFrame<br>    prediction = model.predict(df)<br><br>    # Return the predictions as a JSON response<br>    return jsonify({&quot;Prediction&quot;: list(prediction)})<br><br># Run the Flask app when this script is executed<br>if __name__ == &quot;__main__&quot;:<br>    app.run(debug=True)</pre><p>Tip: It’s good practice to have a keep-alive endpoint (/keepalive) to check if the application is live, especially when the API is in production.</p><h3>Testing the REST API</h3><p>We can test our API with a request.py script, which sends a request to the server for predictions. Here is the full code:</p><pre>import requests<br><br># Define the URL of your Flask API<br>url = &#39;http://127.0.0.1:5000/predict&#39;<br><br># Define the input data as a dictionary<br>data = {<br>    &quot;Avg. Session Length&quot;: [34.49726773, 31.92627203, 33.00091476, 34.30555663],<br>    &quot;Time on App&quot;: [12.65565115, 11.10946073, 11.33027806, 13.71751367],<br>    &quot;Time on Website&quot;: [50.57766802, 80.26895887, 37.11059744, 36.72128268],<br>    &quot;Length of Membership&quot;: [1.082620633, 2.664034182, 4.104543202, 3.120178783]<br>}<br><br># Send a POST request to the API with the input data<br>response = requests.post(url, json=data)<br><br># Check the HTTP response status code<br>if response.status_code == 200:<br>    # Parse and print the JSON response (assuming it contains the prediction)<br>    prediction = response.json()<br>    print(prediction)<br>else:<br>    # Handle the case where the API request failed<br>    print(f&#39;API Request Failed with Status Code: {response.status_code}&#39;)<br>    print(f&#39;Response Content: {response.text}&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*Vpoqf0spRLTiUaam" /><figcaption>Brave Men test in prod XD</figcaption></figure><p>We use the requests library to send a POST request to our Flask-based REST API, accessible at the specified URL. Sample input data is provided in JSON format. If the API responds with a 200 status code, we parse and display the JSON response, assuming it contains a prediction. In the event of a failure, we print the status code and response content, enabling us to test the API’s behavior with the given data.</p><h3>Testing with Postman</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*78hEcbiaqEedYRjR" /><figcaption>Postman is awesome!</figcaption></figure><p>Postman is a widely-used API testing and development tool that simplifies the process of testing and interacting with RESTful APIs. To test a REST API using Postman, follow these steps:</p><ol><li>Install Postman: Download and install Postman from the official website.</li><li>Open Postman: Launch Postman after installation.</li><li>Create a New Request: Click on “New” to create a new request. Give it a name and select the HTTP method (e.g., GET or POST).</li><li>Specify the URL: In the request, provide the URL of the API endpoint you want to test.</li><li>Set Request Parameters: Depending on your API’s requirements, configure headers, authentication, and request body. For POST requests, use the “Body” tab to define input data.</li><li>Send the Request: Click the “Send” button to send the request to the API.</li><li>Inspect the Response: Postman will display the response, including the status code, headers, and response body, allowing you to test and verify the API’s functionality.</li></ol><h3>Deployment</h3><p>Once you have built your model and REST API and finished testing locally, you can deploy your API just as you would any Flask app to the many hosting services on the web. By deploying on the web, users everywhere can make requests to your URL to get predictions. Guides for deployment are included in the Flask documentation: <a href="https://flask.palletsprojects.com/en/2.0.x/deploying/">Flask Deployment</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/0*3ue9aXM2HARXUB1N.jpg" /></figure><p>I hope this article assists you in hosting your machine learning models as API services, making them accessible for a wide range of applications and developers. Until our next learning adventure, happy coding!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*FySgVN9geKhiXx3W.jpg" /><figcaption>Bazinga!</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cf5cb5a1e2f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fashion’s Secret Weapon: Unleashing Data Science in the Apparel Retail Industry]]></title>
            <link>https://medium.com/@anshitvishwa111/fashions-secret-weapon-unleashing-data-science-in-the-apparel-retail-industry-b21a915a9a4c?source=rss-44f264c57ecc------2</link>
            <guid isPermaLink="false">https://medium.com/p/b21a915a9a4c</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[retail-industry]]></category>
            <category><![CDATA[e-commerce-business]]></category>
            <dc:creator><![CDATA[Anshit Vishwakarma]]></dc:creator>
            <pubDate>Sat, 23 Sep 2023 10:19:34 GMT</pubDate>
            <atom:updated>2023-09-24T07:58:01.853Z</atom:updated>
            <content:encoded><![CDATA[<p>Data Science has permeated nearly every facet of our daily lives. From checking the morning news to scrolling through Instagram reels, planning weekend activities based on weather forecasts (a familiar plight for those in Bangalore), or even utilizing GPT models to streamline your code, the influence of data science is inescapable. It brings to mind a famous line from the movie “3 Idiots”: “From the tip of the pen to the bottom of your pants’ zip, it’s all Data Science, sir.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*4Xllm_l04NbD8iC-V60Hug.gif" /><figcaption>What is Machine (Learning)?</figcaption></figure><p>Yet, amidst our immersion in data-driven algorithms created by direct-to-consumer (D2C) companies, we often fail to fully appreciate the extent to which Data Science has infiltrated the world of business-to-business (B2B) operations, particularly within the retail industry — an industry that this article will delve into.</p><p>The rise of e-commerce behemoths like Amazon and Flipkart has revolutionized consumer behavior. Shoppers can now peruse product catalogs at any hour, as opposed to adhering to traditional store hours of 10 AM to 9 PM. Beyond this convenience, they can compare products across various sellers, considering factors like price, quality, and delivery time. The option to return a product within 15 days, whether satisfied or not, has left conventional retailers struggling to compete with these giants. Consequently, retailers such as Walmart, H&amp;M, and Zara have been compelled to pivot toward a more omnichannel approach to conducting business. The magnitude of this shift in consumer behavior cannot be underestimated; we’ve witnessed companies that failed to adapt to these changes shuttering their doors (a recent example being Big Bazaar in India). But does this imply that retail companies are left with no competitive edge against e-commerce giants?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*f3Vb_xKWCEhTi9RY.jpg" /></figure><p>In my personal experience, there are still areas where traditional retail holds an advantage over e-commerce. Take apparel, for instance: people tend to purchase clothing items such as T-shirts, socks, shoes, and undergarments from e-commerce websites, where fitting is less of a concern, as they typically have a size in mind that suits them. However, when it comes to items like chinos, jeans, suits, and the like, individuals often prefer to try them on in stores, ensuring the fit complements their body shape before making a decision. The tactile experience of feeling the fabric also adds value to the in-store shopping process. This can be likened to the shift from traditional pen-and-paper exams to online testing methods for exams like JEE, NEET, and BITSAT. While many have embraced the convenience of online exams, some, like me, still prefer the tangible nature of pen and paper, allowing us to view multiple pages of questions simultaneously, jot down calculations alongside problems, and revisit skipped questions at our leisure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*VnC6BeiYHkqIRUUY" /></figure><p>Most retail companies are now focusing on enhancing the in-store shopping experience, a commendable direction to take. While e-commerce apps are accessible round-the-clock, a visit to the shopping mall may occur just once a week, akin to the difference between streaming a movie on an OTT platform and watching it in a theater. However, what truly constitutes a remarkable shopping experience, and how are retail companies utilizing data science to address the underlying challenges? We will explore each of these factors in depth in the following sections.</p><h4>Assortment Planning</h4><p>Step into any retail store, and what do you see? The entire space is meticulously organized, guiding you effortlessly through a carefully curated array of products. It’s like a symphony of choices choreographed for your convenience. This choreography is what we call ‘Assortment Planning.’ In the retail industry, it’s a secret sauce, an art form, and a science that defines a store’s success by harmonizing product offerings with customer preferences, market dynamics, and strategic objectives.</p><p>Assortment planning is akin to retail wizardry that turns a store into a captivating shopping journey. Picture this: You wander into the “Men’s Jeans” section, and there they are — an ensemble of brands, proudly displayed on mannequins, neatly hung on racks, and sorted by size. It’s a shopping ballet designed to cater to your desires, and it’s all powered by data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/0*D4MV7p6OLCnr68g8.jpeg" /><figcaption>I knowwwww!!!</figcaption></figure><p>Data science, the magician behind the curtain, wields historical sales data, dissects market trends, and deciphers countless other relevant factors to forecast demand for various products. Using intricate machine learning models like time series forecasting and demand prediction algorithms, data science unveils insights into what products are likely to be the stars of the future. This foresight empowers retailers to stock their shelves with precisely what they’ll be craving.</p><p>But data science doesn’t stop there. It dives deeper into the nuances of your shopping behavior. It’s the Sherlock Holmes of retail, uncovering the mysteries of what products tend to be snatched up together. Think about it — you grab a pair of shoes, and voilà, the socks right next to them start calling your name. That’s not luck; it’s the brilliance of data-driven recommendations. It’s the retailer’s way of saying, “Why not take both and save a little?” This is how data science orchestrates the art of cross-selling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/0*1L-_YT4fWMg5MS4k.png" /><figcaption>You’re the Hitchcock to my Skully ❤</figcaption></figure><p>Now, let’s step backstage into the world of apparel retail chains like Shoppers Stop, Aditya Birla Fashion, etc. Here, buyers play a fascinating, yet challenging, game of prediction. They have to place orders with vendors a whopping six months before a season kicks off. Imagine ordering swimwear in the heart of winter! The question that haunts them is this: How can a business predict the future of fashion based on sales data that only stretches to June 2022 for a season starting in January 2023?</p><p>This is where the real magic happens. The trick is to keep an eye on the global fashion stage — think Paris Fashion Week — and spot emerging trends in the making. But here’s the ultimate hack: whatever haute couture the top-tier brands like Balenciaga, Louis Vuitton, or Gucci are flaunting today, you’ll find it replicated in the market in just a few months, in a more budget-friendly version. Retail juggernauts like H&amp;M and Zara have transformed their supply chains into nimble machines, churning out affordable fashion replicas in the blink of an eye.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*fByH1c_8hv538VUo.jpg" /><figcaption>Pamu? Obibas? Niki?</figcaption></figure><p>In the world of assortment planning, data science is the compass, the crystal ball, and the magician’s wand rolled into one. It turns raw data into retail poetry, crafting the perfect retail symphony where you’re not just a shopper; you’re the star of the show. So next time you stroll through your favorite store, remember that the products on those shelves aren’t there by chance — they’re there by data-driven design.</p><h4>Markdown Planning</h4><p>In today’s retail landscape, shoppers have become savvy deal hunters. It’s almost as if they have a sixth sense for discounts. When it comes to apparel, initial profit margins can be enticing, but here’s the catch: to make way for the latest trends and keep up with the ever-evolving competition, retailers need to master the art of markdowns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*gi2s4Fv0cdD_GJRZ.gif" /></figure><p>Welcome to the world of “Markdown Planning” in retail — a strategic dance of pricing and inventory management. It’s the secret sauce that transforms underperforming products into hot commodities, all while minimizing losses and creating space for fresh inventory. The primary mission here is to decode how our products will perform under different price adjustments and recommend price points that maximize profitability. Picture this: a retail stage set for grand sales events that coincide with major celebrations like Eid, New Year, and Diwali. To achieve this harmonious blend of sales and festivities, retailers must predict how products will fare at various potential discount percentages.</p><p>Sounds straightforward, right? Well, here’s the plot twist: Retailers introduce new fashion items each year, and these newcomers lack a sales history. So, how do you predict the audience’s applause for these newcomers?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hVfigRW38o-1JHib" /><figcaption>Ever heard about Clustering?</figcaption></figure><p>Enter the data scientists, the magicians behind the scenes. They employ advanced techniques like clustering to group products with similar selling patterns and attributes during the season. It’s like arranging products into squads, each with its unique character and style. Once these squads are formed, data scientists perform a sophisticated dance of regression analysis. This enables them to predict how each product will perform at various markdown percentages. Imagine it as predicting the plot twists and turns of a gripping story. Armed with these insights, retailers can strategically set price points that maximize profit margins while staying within their budget.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/0*dtiiMhmxRtJNrR6G.jpg" /><figcaption>Data Scientists: With great analytical skills comes great responsibility!</figcaption></figure><p>Markdown planning isn’t just about discounts; it’s about crafting a captivating retail experience. It’s about giving customers what they desire — the thrill of a great deal. It’s also about keeping the retail stage dynamic, ready for the next show-stopping collection.</p><p>So, the next time you snag that irresistible markdown, remember that it’s not just a number — it’s the result of meticulous data analysis and strategic planning, designed to ensure both retailers and customers leave the store with smiles on their faces. It’s the magic behind the sale, making retail a thrilling experience for all involved.</p><p>Too much to chew on for a first article, isn’t it? But fear not, we’re just getting started on our journey through the retail world’s data-driven wonders. Assortment and Markdown planning are just the tip of the retail iceberg, and there’s a treasure trove of challenges waiting to be explored.</p><p>In my upcoming articles, I’ll be your guide through the twists and turns of supply chain conundrums and more. Together, we’ll uncover how data science dons its superhero cape to rescue businesses from the brink.</p><p>So, until next time when we dive even deeper into the exciting world of data science in retail, it’s time to bid adieu. Keep those curiosity engines revved up and stay tuned for more data-driven adventures. Thanks for reading. Goodbye for now! 🚀🛒</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*9DaWLSk4rR_vG79E.jpg" /><figcaption>Bazinga!</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b21a915a9a4c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>