Index by combination using Pascal’s triangle. Get index by combination. Java index by combination. Java combination index. Combination index visual explanation. Get combination position. Calculate combination index. Combinations with repetition index. Calculate combination index using Pascal Triangle. How to create Pascal Triangle. How Pascal Triangle was invented. Pascal triangle explained. Pascal‘s triangle actual meaning. Combinations with repetition to index.

If you need to get index by given combination (in context of combinations with repetition), please read my latest article published here on my github pages blog: https://vgrankin.github.io/data-science/pascals-triangle/ where I demonstrate how to get index of given combination using Pascal’s triangle!

Btw we invent Pascal’s triangle from scratch along the way, so for those who are interested in how to actually create Pascal’s triangle it will be a very interesting read!

Cheers & GL with data science! 🙂

Symfony 4 PHP REST API JWT Example, Symfony 4 REST API boilerplate, Json Web Tokens authentication REST API. How to implement REST API using Symfony framework. PHP Phalcon REST API example.

Hello my friends!

Recently I needed to create a JWT based REST API using Symfony framework.

So here is my take on it: https://github.com/vgrankin/symfony_4_jwt_restapi_demo

This project is created using PHP 7, Symfony 4, MariaDB, Firebase JWT library, PHPUnit and Guzzle library  (which is used by PHPUnit tests to test API endpoints).

I tried to include as much documentation as possible for you to easily pick up the code (you need to be familiar with Symfony though, but if you aren’t there is still good information for you – for example you can look at /src/Service/AuthService.php to get idea on how to use Firebase JWT library to create and validate JWT tokens). So if you are thinking of implementing REST API JWT based “bycicle”, check this repository out! It also is made with best REST API practices in mind btw! So a lot of interesting stuff is there in the code!

As a bonus you can also check my other repository, which is also a REST API JWT microservice, which uses Phalcon PHP framework and MongoDB. Here is a link: https://github.com/vgrankin/phalcon_jwt_restapi_demo. One note though is that probably it is better to look at Symfony 4 implementation if you want to follow REST API standards more or less strictly (or at least if you are looking for consistency), because my Phalcon based implementation is not heavily relying on REST API guidelines (but README.md of this repository mentions what needs to be improved). That said Phalcon implementation still is a good example of how JWT based REST API can be implemented and how to use Phalcon PHP framework for that.

Hope it helps! Cheers! 🙂

My new course “Deep Learning – Visual Exploration”

Hello my friends! Hopefully your software engineering journey is pleasant and you are doing great!

This blog post will be about my new course on Udemy. It is called “Deep Learning – Visual Exploration for Deep Understandig“.

It is intended for beginner level students or even experienced users who want to REALLY understand what is happening under the hood of deep neural networks!

Specifically we will create (absolutely from scratch) and explore feedforward deep neural network (which is a most common type of DNNs). Most important and unique trait of my new course is that we will do it VISUALLY.

So if you are just starting with deep learning or if you want to understand concepts like weights, biases and activation functions VISUALLY and get a crystal clear intuition on how exactly deep neural network is doing it’s magic, then take a look at this course:

https://www.udemy.com/deep-learning-visual-exploration-for-deep-understanding

Currently my course is available at 24.99EUR, but to make it more interesting for you and hopefully a win-win proposal for you and me, here is a coupon code you can use which will allow you to get this course for only 10.99EUR:

https://www.udemy.com/deep-learning-visual-exploration-for-deep-understanding/?couponCode=PHPCODERBLOG

Thank you!

How to calculate accuracy, precision, recall and f1-score? Deep learning precision recall f score, calculating precision recall, python precision recall, scikit precision recall, ml metrics to use, binary classification metrics, f score scikit, scikit-learn metrics

Here is how you can calculate accuracy, precision, recall and f1-score for your binary classification predictions, a plain vanilla implementation in python:

# i made this method based on this discussion:
# https://stackoverflow.com/questions/14117997/what-does-recall-mean-in-machine-learning
def calculate_recall_precision(label, prediction):
    true_positives = 0
    false_positives = 0
    true_negatives = 0
    false_negatives = 0

    for i in range(0, len(label)):
        if prediction[i] == 1:
            if prediction[i] == label[i]:
                true_positives += 1
            else:
                false_positives += 1
        else:
            if prediction[i] == label[i]:
                true_negatives += 1
            else:
                false_negatives += 1

    # a ratio of correctly predicted observation to the total observations
    accuracy = (true_positives + true_negatives) \
               / (true_positives + true_negatives + false_positives + false_negatives)

    # precision is "how useful the search results are"
    precision = true_positives / (true_positives + false_positives)
    # recall is "how complete the results are"
    recall = true_positives / (true_positives + false_negatives)

    f1_score = 2 / ((1 / precision) + (1 / recall))

    return accuracy, precision, recall, f1_score

# usage example:
y_true = [1, 1, 0, 1, 1]
y_pred = [0, 1, 0, 0, 1]

accuracy, precision, recall, f1_score = calculate_recall_precision(y_true, y_pred)

print("Accuracy: ", accuracy)
print("Precision: ", precision)
print("Recall: ", recall)
print("F1 score: ", f1_score)

# outputs:
# Accuracy:  0.6
# Precision:  1.0
# Recall:  0.5
# F1 score:  0.6666666666666666

And here is the same result using scikit-learn library (which allows flexibility for calculating these metrics):

from sklearn.metrics import precision_recall_fscore_support, accuracy_score

accuracy = accuracy_score(y_true, y_pred)
precision, recall, f1_score, _ = precision_recall_fscore_support(y_true, y_pred, average='binary')

print("Accuracy: ", accuracy)
print("Precision: ", precision)
print("Recall: ", recall)
print("F1 score: ", f1_score)

# outputs:
# Accuracy:  0.6
# Precision:  1.0
# Recall:  0.5
# F1 score:  0.666666666667

What is data point in Machine Learning, what means data point, data point deep learning, data point meaning, why data point name, data point statistics

How a row of features (for example Name, Age, Sex et.c) can be named simply as “data point”? This can be not that obvious.

But if you think about some set of features (x1,x2..xn) they may be represented as actual point in n-dimenstional space.

For example on a 2D plane of Work experience (x axis) and Salary (y axis) specific work experience and salary can be shown as a dot/point on a x-y axis, for example with coordinates (10, 70,000) – 70K$ for a 10 years of experience.

So a “data point” from ML/statistics vocabulary fits perfectly here.

Pandas count rows where, pandas count rows by condition, pandas row count by condition, pandas conditional row count, pandas count where

import pandas as pd

csv = pd.read_csv('data.csv')

cnt = len(csv[csv['Age'] == 22]) 
print(cnt) #outputs number of rows where age is 22

cnt = len(csv[(csv['Age'] == 22) & (csv['Sex'] == 'female')])
print(cnt) #outputs number of rows where age is 22 and sex is female

cnt = len(csv[(csv['Age'] < 10) | (csv['Age'] > 30 )])
print(cnt) #outputs number of rows where age is less than 10 or greater than 30

Learn PHP 7 Arrays, PHP arrays, PHP for beginners, PHP array tutorial, PHP 7 arrays, PHP 7 working with arrays, PHP enumerated arrays, PHP associative arrays, PHP multi dimensional arrays, PHP sort array, PHP create array, PHP modify array, PHP access array, PHP range, PHP split array, PHP array_slice, PHP array_push, PHP array_unshift, PHP array_pop, PHP array_shift, PHP iterate array, PHP foreach, PHP array_walk, PHP array_key_exists, PHP in_array, PHP array_keys, PHP array_values, PHP php sort, PHP rsort, PHP asort, PHP arsort, PHP ksort, PHP krsort, PHP usort, PHP natural sorting, PHP natsort, PHP merge arrays, PHP array_merge, PHP comparing arrays, PHP array_diff, PHP array_diff_assoc, PHP array_diff_key, PHP array_diff_uassoc, PHP array_diff_ukey, PHP ArrayObject class

Hey guyz! I’m switching more to videos on youtube, rather than writing blog posts (i will still do it however). Here is my new series on PHP arrays! (all vids will be for the latest, most recent PHP 7 version!). Also, feel free to subscribe to WellExplained youtube channel to get notifications on new videos!

Here we go:

In this introductory video we summarize what you may expect in the upcoming video series on working with arrays in PHP 7. You will see what you need to know to master arrays in PHP and it is also exactly what you need to pass Zend PHP Certification exam on arrays (if you plan to).

So if you want to get good at PHP arrays (both in theory and practice), this is a good video to start from!

WordPress use shortcode to render HTML snippet. Shortcode with parameters to render template. Using shortcodes to insert HTML template into editor. Shortcode to render partial template. Shortcode custom template. Shortcode custom html.

Let’s say you want to insert an HTML code like this in your page:

<div class="pure-g">                
	<div class="pure-u-16-24">
		<article class="my-custom-article-class">
			<h1>My Custom Header</h1>
			<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
			<p>Another lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
		</article>
	</div>
</div>

The problem is that you use the same HTML structure all over your pages (even in the same page). The only thing different is header (h1) and text (p) so you want to use shortcode to automate the process.

Here is a function, which you can add to your functions.php file of your current theme:

<?php

/**
 * Shortcode to render template with given arguments (values)
 * 
 * @param array $attr Array of parameters to use to render template-part with given id ($attr['id'])
 * 
 * usage example: [snippet id="1" header="My h1 instead of #header#" text="Text to use instead of #text# placeholder"]
 * (in this case it will look for: template-parts/snippet-1.php)
 * 
 * Template example (let's say it is your-current-theme-path/template-parts/snippet-1.php):
 * <div>
 *   <h1>#header#</h1>
 *   <p>#text#</p>
 * </div>
 */
add_shortcode('snippet', function ($attr) {

    // id must be set to get correct snippet (template-part)!
    if (!is_array($attr) || !isset($attr['id'])) {
        return;
    }
    
    $fileContent = trim(file_get_contents(locate_template("template-parts/snippet-" . $attr['id'] . ".php")));    
    if ($fileContent) {
        // fill placeholders with actual data
        if (is_array($attr)) {
            foreach ($attr as $k => $v) {
                $fileContent = str_replace("#" . $k . "#", $v, $fileContent);
            }
        }
    }
    
    return $fileContent;
});

As documentation on this function says, you can now create your template, let’s say snippet-simplearticle.php (put it to this location: your-current-theme-path/template-parts).
Now you can place your HTML template there:

<div class="pure-g">                
	<div class="pure-u-16-24">
		<article class="my-custom-article-class">
			<h1>#header#</h1>
			<p>#text#</p>
			<p>#text2#
		</article>
	</div>
</div>

And this is how your shortcode (which you can insert into WYSIWYG of the page you are interested in) looks like:

[snippet id="simplearticle" header="Me special header" text="My impressive paragraph" text2="My another paragraph!"]

Done! Hope it helps!

Learn PHP 7, PHP manual based course, PHP 5.6, Learn PHP 5 & 7 this way to rise above & beyond competition, PHP fundamentals, PHP OOP for beginners, php training, php courses, How to prepare for Zend PHP Certification. Recommend good PHP course udemy. PHP online courses. PHP courses for beginners. How to learn PHP 7. Recommend PHP courses. PHP fundamentals. All in one PHP course. Recommend Zend PHP Certification courses. Best way to learn PHP. Learn PHP online. PHP study guide, PHP udemy, PHP basics. Learn PHP. Best PHP course online. How to become PHP expert.

Hi! Just want to inform you that if you are looking for a PHP course which lays very strong foundation (to pass technical PHP interview or to pass Zend PHP Certification), then you can take a 21 hour course instructed by me which is available on udemy.com. My whole 10+ years experience is invested in this course and it is based on PHP.net manual, which makes it even more outstanding!

In the course we cover everything from operators to control structures, from namespaces to object oriented programming. Everything you need to become a great PHP developer FROM SCRATCH is included! Even experienced developers will greatly benefit, because we cover every concept in great detail (along with PHP.net documentation we provide additional examples and as experienced developer I also add a lot of useful and practical value on every topic covered, to make sure you fully got each concept!).

So if you are interested, then I’ll be glad to see you in the course!

Here is a link to a course where you can find a lot of free-preview lectures to decide if you want to take this course!

https://www.udemy.com/learn-php-5-and-7-this-way-to-rise-above-and-beyond-competition/

You can also get more information on official page of the course here:

wellexplained.net


Thanks!