planning your machine learning model

Planning your machine learning model is one of the most important steps you will take in order to achieve the best results you are looking for.

In looking at how to plan a machine learning project, this video takes you through 3 steps:

a. Researching

b. Building your model

c. Testing your model

❤Subscribe for more free YouTube tips: Subscribe to Data analytics Ireland

❤Share this video with a YouTuber friend: Planning your machine learning model

 

python constructor self and __init__explained

Here in python constructor self and __init__ explained, we will take you through an explanation of self and __init__, how you can use, and the concepts behind them.

We show how to create an object, initiate a class and pass the parameters to the __init__ constructor.

Also we take you through the concept of self and how it can be used to process an object’s parameters and return values where necessary.

❤Subscribe for more free YouTube tips: Subscribe to Data analytics Ireland

❤Share this video with a YouTuber friend: Python constructors explained

 

how to create charts in Tkinter

In how to create charts in Tkinter, Tkinter is one of many libraries that can be used to create charts and graphical user interfaces in Python. Its ease of use and ability to quickly roll out what you desire, make it one of the most popular in use today. In the below video, we create a:

  • Pie chart, a bar chart and a line chart
  • We also use functions and classes to help manage the creation of the charts,
  • It is recommended you follow the video to the end as it will give you a great insight into how these can be used in a video.

❤Subscribe for more free YouTube tips: Subscribe to Data analytics Ireland

❤Share this video with a YouTuber friend:How to create Tkinter charts

 

how to add sine and cosine in python code

Explaining what this post is about
I was recently online and providing help to a fellow python coder, and a query came up about how you would rewrite some code that had included the sine function  and the cosine function

We were asked to see if we could translate this code:

L_1=1;
L_2=1.5;
q_0=0.5;
q_1=pi()/4;
q_2=pi()/6;
%Position of the end effetor
x= q_0+L_1*cos(q_1)-L_2*cos(pi()-q_1-q_2)
y=L_1*sin(q_1)+L_2*sin(pi()-q_1-q_2)

into its python equivalent.

Some background about the output

In order to get the desired result, there is a need to import a package to provide some of the mathematical analysis required, and was achieved through using Numpy statistical analysis

This package allows the following functions to be used in the logic:

  • Pi
  • Cosine
  • Sine

And the result is

As a result, the below shows the output of the above question converted to its Python equivalent:

import numpy as np

a= np.pi
print("PI value is ", a)

L_1=1
L_2=1.5
q_0=0.5
q_1=a/4
q_2=a/6

print("L_1 value is",L_1)
print("L_2 value is",L_2)
print("q_0 value is",q_0)
print("q_1 value is",q_1)
print("q_2 value is",q_2)


x= (q_0+(L_1*(np.cos(q_1)))-(L_2*(np.cos(a-q_1-q_2))))
y= (L_1*(np.sin(q_1))+(L_2*(np.sin(a-q_1-q_2))))

print("x value is " , x)
print("y value is " , y)

with its output showing:

PI value is  3.141592653589793
L_1 value is 1
L_2 value is 1.5
q_0 value is 0.5
q_1 value is 0.7853981633974483
q_2 value is 0.5235987755982988
0.7071067811865476
-0.25881904510252085
x value is  1.5953353488403288
y value is  2.15599552062015

 

how to create an instance of a class

Here in how to create an instance of a class, as described herein, how to create a class in Python, we will further explore the instance of class and how this can be used within a program to assign values to an object. This allows that object to inherit those values contained within the class, making it easier to have consistency regards functionality and data.

This video covers off

(a) creating an instance of a class

(B) Using the __init__ within the class

(C) define the constructor method __init__

(D) Creating an object that calls a class and uses the class to process some piece of data.

What are the benefits of this?

  • You only need to create one class that holds all the attributes required.
  • That class can be called from anywhere within a program, once an instance of it is created.
  • You can update the class, and once completed, those new values will become available to an instance of that class.
  • Makes for better management of objects and their properties, not multiple different versions contained within a program

 

 

How to create a class in Python

How to create a class in Python : In this video explaining classes will be the main topic on how they are constructed,  we explain how to create an instance of a class. Also, we look at what class attributes are and how they can be used to assign key data that can be called anywhere within a program.

The steps involve the following:

(a) Create a class

(B) Assign attributes to the class

(C) Create a method within the class ( similar to a function)

(D) Create an instance of a class to call its attributes and methods.

This video is a follow on from object oriented programming – Python Classes explained

Python Tutorial: Pandas groupby columns ( video 2)

Pandas groupby using column values

In this second video how to groupby using pandas and as part of expanding the data analytics information of this website, we are looking to explain how you can use a groupby selection but only using the column values and not the column names.

Below we import our data into a dataframe, and then group as follows:

  • Aggregate function
  • Using the cut function and assigning values to bins.
  • Assigning labels to the data frame output based on the bin values.

 

 

Why would you want to use Pandas groupby and column values?

This video looks to help understand the why going by values might be easier than column names:

  • Column names can change from project to project, using by values allows easy implementation of getting the output regardless of the names used.
  • You could apply this to any Python class, and as long as you can inherit will allow the code to run smoothly.
  • Implementing by value allows a clear understanding of the desired output as the values are clearly understood to generate what is required.
  • You need to understand how data within your data set falls within a particular cohort:
    • This use of values in different programs just needs to change, the underlying logic remains the same.
    • Using column names still means that to group them, the logic still needs to be written.

Python tutorial: Pandas groupby ( Video 1)

In this first video about pandas groupby and as part of expanding the data analytics information of this website, we are looking to explain how you can use a groupby selection to sort your data into similar datasets better so they can be better analysed. In the video below, we import our data into a dataframe, and then group as follows:

  • Directly naming the column
  • Through get_group
  • Using a loop
  • Utilising a lambda function

 

 

Regular expressions python

Regular expressions explained

Regular expressions are a set of characters usually in a particular sequence that helps find a match/pattern for a specific piece of data in a dataset.

The purpose is to allow a uniform of set characters that can be reused multiple times, based on the requirements of the user, without having to build each time.

The patterns are similar to those that you would find in Perl.

How are regular expressions built?

To start, in regular expressions, there are metacharacters, which are characters that have a special meaning. Their values are as follows:

. ^ $ * + ? { } [ ] \ | ( )

.e = All occurrences which have one “e”, and value before that e. There can be multiple e, eg ..e means check two characters before e.

^ =Check if a string starts with a particular pattern.

*  = Match zero or more occurrences of a pattern, at least one of the characters can be found.

+ = Looks to match exact patterns, one or more times, and if they are not precisely equal, then nothing is returned.

? =Check if a string after ? exists in a pattern and returns it. If a value before the ? is directly beside the value after ? then returns both values.

—> e.g. t?e is the search pattern. “The” is the string. The result will return only the value e, but if the string is “te”, then it will return te, as the letters are directly beside each other.

da{2} = Check to see if a character has a set of other characters following it. E.g. sees if d has two “a” following it.

[abc] = These are the characters you are looking for in the data. Could also use [a-c] and will give you the same result. Change to uppercase to get only those with uppercase.

\ = Denoting a backslash used to escape all metacharacters, so if they need to be found in a string, they can be. Used to escape $ in a string so they can be found as a literal value.

| = This is used when you want an “or” operator in the logic, i.e. check for one or more values from a pattern, either or both can be present.

() = Looks to group pattern searches or a partial match, to see if they are together or not.

 

Special sequences, making it easier again

\a = Matches if the specified characters are at the start of the string been searched.

\b = Matches if the specified characters are at the beginning or the end of the string been searched.

\B = Matches if the specified characters are NOT at the beginning or the end of the string been searched.

\d = Matches any digits 0-9.

\D = Matches any character is not a digit.

\s = Matches where a string contains a whitespace character.

\S = Matches where a string contains a non-whitespace character.

\w = Matches if digits or character or _ found

\W = Matches if non-digits and or characters or _found

\z = matches if the specified characters are at the end of the string.

 

 

For further references and reading materials, please see the below websites, the last one is really useful in testing any regular expressions you would like to build:

See further reading material here: regular expression RE explained

Another complementary page to the link above regular expression REGEX explained

I found this link on the internet, and would thoroughly recommend you bookmark it. It will also allow you to play around with regular expressions and test them before you put into your code, a very recommended resource Testing regular expressions

 

What are the reserved keywords in Python

What are python reserved keywords?

When coding in the Python language there are particular python reserved words that the system uses, which cannot be accessed as a variable or a function as the computer program uses them to perform specific tasks.

When you try to use them, the system will block it and throws out an error. Running the below code in Python

import keyword
keywordlist = keyword.kwlist
print(keywordlist)

Produces the below keyword values
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del',
'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal',
'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

When writing your code, it is important to follow the following guidelines:

(A) Research the keywords first for the language you are writing in.

(B) Ensure that your programming language highlights keywords when used, so you can fix the issue.

(C) Setup your computer program in debug mode to highlight keywords use.

With some programs running into thousands of lines of code, with additional functions and variables, it can become harder to spot the problem, so good rigour in the initial stages of coding will help down the road any issues that you may find that need to fixed.

This code was run in Python version 3.8