<?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 Levi Matheri on Medium]]></title>
        <description><![CDATA[Stories by Levi Matheri on Medium]]></description>
        <link>https://medium.com/@levimatheri?source=rss-f4f262f21e0b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wY7Oyp9L77iIfipp6dHlRQ.png</url>
            <title>Stories by Levi Matheri on Medium</title>
            <link>https://medium.com/@levimatheri?source=rss-f4f262f21e0b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 17:57:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@levimatheri/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[Flutter: Email verification and password reset]]></title>
            <link>https://medium.com/@levimatheri/flutter-email-verification-and-password-reset-db2eed893d1d?source=rss-f4f262f21e0b------2</link>
            <guid isPermaLink="false">https://medium.com/p/db2eed893d1d</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Levi Matheri]]></dc:creator>
            <pubDate>Sun, 17 Mar 2019 19:01:44 GMT</pubDate>
            <atom:updated>2019-03-17T19:05:50.218Z</atom:updated>
            <content:encoded><![CDATA[<p>When it comes to user experience in mobile application development, it is important to consider email verification. This concept allows for creation of a relationship between a company and its users. Messages can be sent to actual people and this can be helpful for marketing purposes and the overall affirmation of users as they use the app. The concept of password reset is self-explanatory; users often forget passwords. Therefore, we cannot overemphasize the importance of a password reset feature.</p><p>This idea can seem difficult to implement at first, especially when working with a new framework like Flutter. However, we can leverage the Firebase API that exposes functions that trivialize email verification (assuming you are using Firebase as the back-end authentication). In fact, it is as easy as a few lines of code. With no further ado, let’s get into it!</p><h3>Email verification</h3><p>To help with centralizing authentication workflow, I typically dedicate one class to handle signing up, signing in and out, and email verification/password resets.</p><pre>import &#39;dart:async&#39;;<br>import &#39;package:firebase_auth/firebase_auth.dart&#39;;<br>import &#39;package:cloud_firestore/cloud_firestore.dart&#39;;</pre><pre>abstract class BaseAuth {<br>   Future&lt;String&gt; signIn(String email, String password);<br>   Future&lt;String&gt; signUp(String username, String email, String password);<br>   Future&lt;void&gt; signOut();<br>}</pre><pre>class Auth implements BaseAuth {<br>   final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;</pre><pre>   @override<br>   Future&lt;String&gt; signUp(String username, String email, String password) async {<br>      FirebaseUser user = await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password);</pre><pre>     try {<br>        await user.sendEmailVerification();<br>        return user.uid;</pre><pre>     } catch (e) {<br>        print(&quot;An error occured while trying to send email        verification&quot;);<br>        print(e.message);<br>     }<br>   }<br>}</pre><p>The signUp function takes in the username, email and password as parameters and creates a new user with the details. You can already see how easy this is — Firebase takes care of hashing and salting the users’ passwords. We then send the new user an email verification. It will usually look like this:</p><h4>noreply@[PROJECT-NAME].firebaseapp.com</h4><p>Sat, Mar 9, 1:03 PM (8 days ago)</p><p>to [USERNAME]</p><p>Hello,</p><p>Follow this link to verify your email address.</p><p><a href="https://myusica-4818e.firebaseapp.com/__/auth/action?mode=verifyEmail&amp;oobCode=O4aOh85My-mWTJiPr3u06d9UlPnRWSVF05ik9ZlFYSUAAAFpY6ARGg&amp;apiKey=AIzaSyDYNYWsjViPNQvi3RXqEjFYkl1dlTouLJY&amp;lang=en">[URL</a> LINK]</p><p>If you didn’t ask to verify this address, you can ignore this email.</p><p>Thanks,</p><p>Your [PROJECT] team</p><p>Once the user has followed the link, their email will be verified. At this point, the user can now sign in to your app, therefore you should always check if the current user’s email is verified or not before signing them in. How do we do that in Flutter? Simple! The user object has a isEmailVerified boolean member that we can check to see if a user’s email is verified as shown below.</p><pre>@override<br>Future&lt;String&gt; signIn(String email, String password) async {<br>    FirebaseUser user = await  _firebaseAuth.signInWithEmailAndPassword(email: email, password:password);</pre><pre>    if (user.isEmailVerified) return user.uid;<br>    return null;<br>}</pre><p>I’m loving how easy this is as much as you are!</p><h3>Password reset</h3><p>Lastly, password reset is the easiest part of it all as shown below.</p><pre>@override<br>Future&lt;void&gt; resetPassword(String email) async {<br>    await _firebaseAuth.sendPasswordResetEmail(email: email);<br>}</pre><p>That’s it, a one-liner! The user should then receive an email with instructions on how to reset their password.</p><h3>Conclusion</h3><p>Email verification and password resets are important aspects in user experience design. For a simple application, Flutter makes it easy to implement these features as Firebase handles the complex details behind these operations. Of course it’s possible to customize the emails sent to users directly from the Firebase console with no sweat.</p><p>If you liked this article, hit the clap button and leave a comment below for any questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db2eed893d1d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a classifier to predict activity category of a human]]></title>
            <link>https://medium.datadriveninvestor.com/building-a-classifier-to-predict-activity-category-of-a-human-84eaf2d9803e?source=rss-f4f262f21e0b------2</link>
            <guid isPermaLink="false">https://medium.com/p/84eaf2d9803e</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Levi Matheri]]></dc:creator>
            <pubDate>Fri, 30 Nov 2018 05:58:20 GMT</pubDate>
            <atom:updated>2018-12-04T00:54:54.332Z</atom:updated>
            <content:encoded><![CDATA[<p>According to <a href="http://archive.ics.uci.edu/ml/index.php">UCI Machine Learning Repository</a>, the Human Activity Recognition data set is derived from recordings of 30 subjects in their day-to-day activities while carrying around a waist-mounted smartphone with embedded inertial sensors. Each person performed six activities, namely: walking, walking upstairs, walking downstairs, sitting, standing and laying. The procedure for how the data was obtained from the sensors, the data and its description, as well as the pre-processing can all be obtained <a href="http://archive.ics.uci.edu/ml/datasets/Human+Activity+Recognition+Using+Smartphones">here</a>.</p><p>I built a multi-class classifier using a <a href="https://en.wikipedia.org/wiki/Support_vector_machine">Support Vector Machine</a> (SVM). An SVM seeks to separate the categories of data with a clear decision boundary that has a large distance to the nearest data point of any class. I will now walk through my approach.</p><p>Using <a href="https://colab.research.google.com/">Google Colab</a>, we open a new Python3 notebook. The data files can be imported into Google Drive and accessed from Google Colab. We can import these files into our notebook using the following lines of code.</p><pre>from google.colab import drive<br>drive.mount(&#39;/content/gdrive&#39;)</pre><p>The server will then ask us to follow a link which will forward us to authorize Google Drive File Stream to access our Google drive. A token will be created which we will then copy into the text input provided on the notebook. When all is said and done, we should see Mounted at /content/gdrive.</p><p>We will now split our data into training and testing data. First of all, we obtain our feature list from <em>features.txt </em>thus:</p><pre>with open(&#39;/content/gdrive/My Drive/features.txt&#39;) as feature_file:<br>  names = feature_file.readlines()<br>  names = map(lambda x: x.strip(), names)<br>  names = list(names)</pre><p>Then split our data:</p><pre>X_train = pd.read_csv(&#39;/content/gdrive/My Drive/X_train.txt&#39;, header=None, delimiter=r&quot;\s+&quot;, names=names)<br>X_test = pd.read_csv(&#39;/content/gdrive/My Drive/X_test.txt&#39;, header=None, delimiter=r&quot;\s+&quot;, names=names)<br>y_train = pd.read_csv(&#39;/content/gdrive/My Drive/y_train.txt&#39;, header=None)<br>y_test = pd.read_csv(&#39;/content/gdrive/My Drive/y_test.txt&#39;, header=None</pre><pre>y_train.columns = [&#39;label&#39;]<br>y_test.columns = [&#39;label&#39;]</pre><pre># we will need this for fitting the model<br>y_train_fin = y_train.values.ravel()<br>y_test_fin = y_test.values.ravel()</pre><p>To ensure our data is normalized, we use sklearn&#39;s StandardScaler from the preprocessing module and transform our data, essentially removing the mean and scaling to unit variance. We can do this with a few lines of code as shown below.</p><pre>from sklearn.preprocessing import StandardScaler<br><br>scaler = StandardScaler()<br>X_train_fin = scaler.fit_transform(X_train)<br>X_test_fin = scaler.transform(X_test)</pre><p>We can implement the SVM model using different forms of kernels. I basically went through Linear, Gaussian and Polynomial kernels to gauge which model would achieve the highest accuracy. In order to get a more accurate representation of the findings, we use the <a href="https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.KFold.html">KFold crossvalidation</a> technique. We split the training data into k consecutive folds. Each fold is used once as a validation while the k -1 remaining folds are used as the training set. We then consolidate the scores for the various models and print the result as follows:</p><pre>from sklearn.model_selection import KFold<br>from sklearn import svm<br>import numpy as np</pre><pre>svc_linear = svm.SVC(kernel=&#39;linear&#39;)<br>svc_gaussian = svm.SVC(kernel=&#39;rbf&#39;)<br>svc_poly = svm.SVC(kernel=&#39;poly&#39;)</pre><pre># split into 5 folds<br>k_fold = KFold(n_splits=5)</pre><pre>scores_linear = np.array([svc_linear.fit(X_train_fin[train], y_train_fin[train]).score(X_train_fin[test], y_train_fin[test]) <br>for train, test in k_fold.split(X_train_fin)])</pre><pre>scores_gaussian = np.array([svc_gaussian.fit(X_train_fin[train], y_train_fin[train]).score(X_train_fin[test], y_train_fin[test]) <br>for train, test in k_fold.split(X_train_fin)])</pre><pre>scores_poly = np.array([svc_poly.fit(X_train_fin[train], y_train_fin[train]).score(X_train_fin[test], y_train_fin[test]) <br>for train, test in k_fold.split(X_train_fin)])</pre><pre>print(&quot;Scores for linear SVM &quot;, scores_linear)<br>print(&quot;Train accuracy LINEAR: %0.2f (+/- %0.2f)&quot; % (scores_linear.mean(), scores_linear.std()/2))<br>print(&quot;Scores for gaussian SVM &quot;, scores_gaussian)<br>print(&quot;Train accuracy GAUSSIAN: %0.2f (+/- %0.2f)&quot; % (scores_gaussian.mean(), scores_gaussian.std()/2))<br>print(&quot;Scores for polynomial SVM &quot;, scores_poly)<br>print(&quot;Train accuracy POLY: %0.2f (+/- %0.2f)&quot; % (scores_poly.mean(), scores_poly.std()/2))</pre><pre>print(&quot;Train accuracy: %0.2f (+/- %0.2f)&quot; % (scores.mean(), scores.std()/2))</pre><p>After running the above code, we get this:</p><pre>Scores for linear SVM  [0.92454113 0.90210741 0.93197279 0.94761905 0.96462585]<br>Train accuracy LINEAR: 0.93 (+/- 0.01)<br>Scores for gaussian SVM  [0.92726037 0.90754589 0.91632653 0.92789116 0.95782313]<br>Train accuracy GAUSSIAN: 0.93 (+/- 0.01)<br>Scores for polynomial SVM  [0.91434398 0.90210741 0.91768707 0.92040816 0.93061224]<br>Train accuracy POLY: 0.92 (+/- 0.00)</pre><p>As we can see, Linear and Gaussian SVM kernels are comparable. We can then see how each does on the test set:</p><pre>y_pred_linear = svc_linear.predict(X_test_fin)<br>y_pred_gaussian = svc_gaussian.predict(X_test_fin)<br>y_pred_poly = svc_poly.predict(X_test_fin)</pre><pre>from sklearn.metrics import accuracy_score</pre><pre>print(&quot;Linear &quot;, accuracy_score(y_test_fin, y_pred_linear))<br>print(&quot;Gaussian &quot;, accuracy_score(y_test_fin, y_pred_gaussian))<br>print(&quot;Poly &quot;, accuracy_score(y_test_fin, y_pred_poly))</pre><p>After running the above code, we obtain the following results:</p><pre>Linear  0.9491007804546997<br>Gaussian  0.9433322022395657<br>Poly  0.9124533423820834</pre><p>As we can see, the Linear kernel did best, although still quite comparable with the Gaussian kernel.</p><p>Furthermore, going with Linear kernel, we can create a cross-tab to get a better visualization of how well the SVM does on the test set:</p><pre>svc_linear.fit(X_train_fin, y_train_fin)</pre><pre>crosstab = pd.crosstab(y_test_fin.flatten(),   svc_linear.predict(X_test_fin),<br>                   rownames=[&#39;True&#39;], colnames=[&#39;Predicted&#39;],<br>                   margins=True)<br>crosstab</pre><p>We obtain the table below. It looks like our model did very well. However, it seems our model had a little bit of trouble dealing with 4 and 5. Why? Because if we look at the activities they represent, 4 represents sitting while 5 represents standing. It is evident that these activities are stationary, the accelerometer and gyroscope data on these activities would be quite similar.</p><pre>+------------+------+------+------+------+------+------+------+<br>| Predicted  |  1   |  2   |  3   |  4   |  5   |  6   | All  |<br>+------------+------+------+------+------+------+------+------+<br>| True       |      |      |      |      |      |      |      |<br>| 1          | 495  |   0  |   1  |   0  |   0  |   0  |  496 |<br>| 2          |  16  | 453  |   2  |   0  |   0  |   0  |  471 |<br>| 3          |   6  |  15  | 399  |   0  |   0  |   0  |  420 |<br>| 4          |   0  |   2  |   0  | 434  |  55  |   0  |  491 |<br>| 5          |   0  |   0  |   0  |  18  | 514  |   0  |  532 |<br>| 6          |   0  |   0  |   0  |   0  |   0  | 537  |  537 |<br>| All        | 517  | 470  | 402  | 452  | 569  | 537  | 2947 |<br>+------------+------+------+------+------+------+------+------+</pre><p>That’s it! One thing we could try with this is apply <a href="https://en.wikipedia.org/wiki/Principal_component_analysis">Principal Component Analysis (PCA)</a> to reduce the dimensionality of the data. This is because we have so many features which could lead to overfitting. Another thing would be to make this a binary classification problem where we try to predict if an activity is stationary or mobile.</p><h3>Conclusion</h3><p>I hope you found this article insightful and helpful. Please share your thoughts in consideration.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84eaf2d9803e" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/building-a-classifier-to-predict-activity-category-of-a-human-84eaf2d9803e">Building a classifier to predict activity category of a human</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>