<?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 Radhwane Chebaane on Medium]]></title>
        <description><![CDATA[Stories by Radhwane Chebaane on Medium]]></description>
        <link>https://medium.com/@radcheb?source=rss-868b995d2579------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*i3xay1oZHGLRQsvS6lYWHw.jpeg</url>
            <title>Stories by Radhwane Chebaane on Medium</title>
            <link>https://medium.com/@radcheb?source=rss-868b995d2579------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 07:08:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@radcheb/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[Bootstrapping your Machine Learning platform with Kubeflow and GCP]]></title>
            <link>https://medium.com/radcheb/bootstrapping-your-machine-learning-platform-with-kubeflow-and-gcp-ead2129cc206?source=rss-868b995d2579------2</link>
            <guid isPermaLink="false">https://medium.com/p/ead2129cc206</guid>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[kubeflow]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Radhwane Chebaane]]></dc:creator>
            <pubDate>Tue, 30 Jul 2019 21:57:45 GMT</pubDate>
            <atom:updated>2019-07-30T21:57:45.328Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A gentle guide on how to set up a fresh a small and cost-effective prototyping platform before starting any ML project using Kubernetes and Kubeflow on Google Cloud Platform.</em></p><p>By <a href="https://www.linkedin.com/in/radhwane-chebaane-483b3a7b/">Radhwane Chebaane</a></p><h3>What is a Machine Learning platform</h3><p>A machine learning project starts with data preparation, passing by features engineering and finally model selection and hyperparameter tuning. All these steps require a lot of experimentation and trials in order to select the correct choices. A handy data scientist would record all the experimentation details and keep track of results for further exploration. Hence a single platform to store and explore the experiments data make the data scientist life much easier.</p><p>Each step relays on previous step results, this chaining of data and jobs has already been solved by many data orchestration projects such as Airflow, Luigi, etc but none is really suited to machine learning prototyping and provide support for parameter tuning, distributed training, etc.</p><p>Here comes Kubeflow, a cloud-native platform for machine learning. Kubeflow is cloud-native, it runs on top of Kubenetes, the most trending containers platform.</p><h3>Getting started with Kubeflow</h3><h4>Prerequisites: a Kubernetes cluster</h4><p>In order to install Kubeflow, you need a ready Kubernetes cluster. Although Kubernetes installation is out of this article scope, you can have a local mini Kubernetes cluster with the <a href="https://kubernetes.io/docs/setup/learning-environment/minikube/">Minikube tool</a>. I would be rather using a Kubernetes cluster on Google Cloud Platform since I still have my 300$ credit on GCP. To get started with Google Kubernetes Engine (GKE), you can follow these steps <a href="https://cloud.google.com/kubernetes-engine/docs/quickstart">here</a>. Throughout this tutorial, I will give only the steps required to run on GCP, but it should be the same for a local Minikube.</p><p>You will need also to install Kustomize, needed by Kubeflow to help manage deployments. Installation guide can be found here.</p><h4>Installing Kubeflow</h4><p>First, set up the following environment variables for later use:</p><ol><li>Set your GCP project ID (skip if using Minikube). In the command below, replace &lt;YOUR-PROJECT-ID&gt;with your <a href="https://cloud.google.com/resource-manager/docs/creating-managing-projects#identifying_projects">project ID</a>:</li></ol><pre>export PROJECT=&lt;YOUR-PROJECT-ID&gt;<br>gcloud config set project ${PROJECT}</pre><p>2. Set the zone for your GCP configuration (skip if using Minikube). Choose a zone that offers the resources you need. See the guide to <a href="https://cloud.google.com/compute/docs/regions-zones/">GCP regions and zones</a>.</p><ul><li>Ensure you have enough Compute Engine regional capacity. By default, the GKE cluster setup described in this guide requires 16 CPUs.</li><li>If you want a GPU, ensure your zone offers GPUs.</li></ul><p>For example, the following commands set the zone to us-central1-c:</p><pre>export ZONE=us-central1-c<br>gcloud config set compute/zone ${ZONE}</pre><p>3. Set theDEPLOYMENT_NAME environment variable as kubeflow:</p><pre>export DEPLOYMENT_NAME=kubeflow</pre><p>4. Create an OAuth client for Cloud IAP on GCP</p><p>Follow these steps to create an OAuth client needed later when deploying Kubeflow: <a href="https://www.kubeflow.org/docs/gke/deploy/oauth-setup/">https://www.kubeflow.org/docs/gke/deploy/oauth-setup/</a></p><p>and create environment variables from the OAuth client ID and secret that you obtained earlier:</p><pre>export CLIENT_ID<strong>=</strong>&lt;CLIENT_ID from OAuth page&gt;<br>export CLIENT_SECRET<strong>=</strong>&lt;CLIENT_SECRET from OAuth page&gt;</pre><h4>Deploy Kubeflow</h4><p>Follow these steps to deploy Kubeflow:</p><ol><li>Create user credentials. You only need to run this command once:</li></ol><pre>gcloud auth application-default login</pre><p>2. Download and unpack Kubeflow client <strong>kfctl</strong> from the <a href="https://github.com/kubeflow/kubeflow/releases/">Kubeflow releases page</a>, we will be using Kubeflow version <strong>0.6.1</strong>. You can also add kfctl to your PATH for easier use.</p><pre>export PLATFORM=darwin # use &#39;dawrwin&#39; for mac otherwise linux or windows  <br>wget <a href="https://github.com/kubeflow/kubeflow/releases/download/v0.6.1/kfctl_v0.6.1_linux.tar.gz">https://github.com/kubeflow/kubeflow/releases/download/v0.6.1/kfctl_v0.6.1_$</a>PLATFORM<a href="https://github.com/kubeflow/kubeflow/releases/download/v0.6.1/kfctl_v0.6.1_linux.tar.gz">.tar.gz</a><br>tar -xvf <a href="https://github.com/kubeflow/kubeflow/releases/download/v0.6.1/kfctl_v0.6.1_linux.tar.gz">kfctl_v0.6.1_$</a>PLATFORM<a href="https://github.com/kubeflow/kubeflow/releases/download/v0.6.1/kfctl_v0.6.1_linux.tar.gz">.tar</a>.gz <br># Optionnal: Add kfctl to PATH<br>sudo cp kfctl /usr/bin<br>sudo chmod a+x /usr/bin/kfctl</pre><p>3. Create the Kubeflow cluster</p><pre># <strong>KFAPP</strong> the <em>name</em> of a directory where you want Kubeflow configurations to be stored.<br>export KFAPP<strong>=kubeflow-cluster<br></strong>kfctl init ${KFAPP} --platform gcp --project ${PROJECT}</pre><pre>cd ${KFAPP}<br>kfctl generate all -V --zone ${ZONE}<br>kfctl apply all -V</pre><p>4. Check the resources deployed in namespace kubeflow :</p><pre>kubectl -n kubeflow get  all</pre><p>You can also visit Kubeflow UI at:</p><pre>https://<strong>kubeflow-cluster</strong>.endpoints.&lt;project&gt;.cloud.goog/</pre><h4>Create a Cloud Storage bucket</h4><p>The next step is to create a Cloud Storage bucket to hold your models and artifacts. They need to be stored in a globally available storage system thus Cloud Storage is a good choice. The following command will create a bucket in <strong>us-central1</strong> region:</p><pre>export REGION=us-central1<br>export BUCKET_NAME=${PROJECT}-${KFAPP}-bucket<br>gsutil mb -c regional -l ${REGION} gs://${BUCKET_NAME}</pre><h4>Set Up Your Notebooks</h4><p>There are multiple benefits of integrating Jupyter Notebooks in Kubeflow for enterprise environments. These benefits include:</p><ul><li>Integrating well with the rest of the infrastructure with respect to authentication, access control and resource access (GPUs, etc).</li><li>Enabling easier notebook sharing across the organization.</li></ul><p>To create a notebook, first, create a <strong>Notebook Server</strong> from the Kubeflow UI. Click on “+ NEW SERVER”, give it a name, choose the needed resource and than “LAUNCH”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*B0lBUO0Rnv-LFys4AD7iqA.png" /></figure><p>When it is ready, you can click on connect to start using Jupyter</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*92nnH7vUcIwZK1e3.png" /><figcaption>Jupyter ready</figcaption></figure><h3>A simple use case: POSOS challenge</h3><p>The POSOS challenge is an academic text classification challenge provided by POSOS, a french startup building medication-related question-answering platform.</p><p>The challenge consists of finding the best category of medical-related questions (text) amoung 50 provided categories.</p><p>Train and test data can be downloaded from the ENS website: <a href="https://challengedata.ens.fr/participants/challenges/17/">https://challengedata.ens.fr/participants/challenges/17/</a></p><p>Upload data to your Jupyter server working directory. Let’s start by reading data:</p><pre>xtrain_df = pd.read_csv(“input_train.csv”, sep=”;”)<br>ytrain_df = pd.read_csv(“output_train.csv”, sep=”;”)<br>xtest_df = pd.read_csv(“input_test.csv”, sep=”;”)<br>display(xtrain_df.shape, ytrain_df.shape, xtest_df.shape)</pre><p>Actually, we 8028 labeled questions and we need to infer labels for 2035 question. Ounce data loaded, let’s build a train and a validation set:</p><pre>train_columns = “question”<br>label_column = “intention”<br>X_train, X_valid, y_train, y_valid = train_test_split(xtrain_df[train_columns], ytrain_df[label_column], test_size=0.2, random_state=1234)</pre><p>For the purpose of this tutorial, we will make a quick model, just to be able to test the Kubeflow platform. Let&#39;s transform textual variables to numerical vector with TF-IDF, then we will apply a Naive Bayes estimator to classify questions. We will group all these operations in a scikit-learn pipeline:</p><pre>text_clf = Pipeline([<br>     (&#39;vect&#39;, CountVectorizer()),<br>     (&#39;tfidf&#39;, TfidfTransformer()),<br>     (&#39;clf&#39;, MultinomialNB()),<br> ])<br>text_clf.fit(X_train, y_train)<br>y_prediction = text_clf.predict(X_valid)<br>np.mean(y_prediction == y_valid.values)<br>// 0.3026151930261519</pre><p>Great, this gives already an average accuracy of 30%.</p><p>Let’s try an SVM classifier instead of Naive Bayes:</p><pre>text_clf = Pipeline([<br>     (&#39;vect&#39;, CountVectorizer()),<br>     (&#39;tfidf&#39;, TfidfTransformer()),<br>     (&#39;clf&#39;, SGDClassifier(loss=&#39;hinge&#39;, penalty=&#39;l2&#39;,<br>                           alpha=1e-3, random_state=1234,<br>                           max_iter=5, tol=None)),<br> ])<br>text_clf.fit(X_train, y_train)<br>y_prediction = text_clf.predict(X_valid)<br>np.mean(y_prediction == y_valid.values)<br>// 0.6301369863013698</pre><p>Wow, this gives already 63% accuracy. Let’s submit to the challenge platform:</p><pre>y_test = text_clf.predict(xtest_df[train_columns])<br>y_test_df = xtest_df[[&quot;ID&quot;]]<br>y_test_df[&quot;intention&quot;] = y_test<br>y_test_df.to_csv(&quot;posos_svm.csv&quot;, index=False)</pre><p>This model scores 61.1% on the test set, which put us at rank 40 out of 47. You should be surprised how such an old-fashion and simple model can yield such a decent score.</p><p>Let’s save the model for later use</p><pre>dump(clf, &#39;posos-classifier&#39;)</pre><p>In the next episode, we will perform some preprocessing and feature engineering with Kubeflow before building any models. We will also explore deep learning and embeddings to push our accuracy further, stay tuned.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ead2129cc206" width="1" height="1" alt=""><hr><p><a href="https://medium.com/radcheb/bootstrapping-your-machine-learning-platform-with-kubeflow-and-gcp-ead2129cc206">Bootstrapping your Machine Learning platform with Kubeflow and GCP</a> was originally published in <a href="https://medium.com/radcheb">radcheb</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>