Showing posts with label python 3. Show all posts
Showing posts with label python 3. Show all posts

Saturday, May 5, 2018

What is Support Vector Machines (SVM) ?

Support Vector Machines


A Support Vector Machine (SVM) is a classifier that is defined using a separating hyperplane between the classes.This hyperplane is the N-dimensional version of a line.

Given labeled training data and a binary classification problem, the SVM finds the optimal hyperplane that separates the training data into two classes. This can easily be extended to the problem with N classes.

Let's consider a two-dimensional case with two classes of points. Given that it's 2D, we only have to deal with points and lines in a 2D plane. This is easier to visualize than vectors and hyperplanes in a high-dimensional space. Of course, this is a simplified version of the SVM problem, but it is important to understand it and visualize it before we can apply it to high-dimensional data.


Consider the following figure:



There are two classes of points and we want to find the optimal hyperplane to separate the two classes. But how do we define optimal? In this picture, the solid line represents the best hyperplane.
You can draw many different lines to separate the two classes of points, but this line is the best separator, because it maximizes the distance of each point from the separating line. The points on the dotted lines are called Support Vectors. The perpendicular distance between the two dotted lines is called maximum margin.


What is Confusion Matrix in Machine Learning ?

Confusion matrix


A Confusion matrix is a figure or a table that is used to describe the performance of a classifier. It is usually extracted from a test dataset for which the ground truth is known.
We compare each class with every other class and see how many samples are misclassified.

Friday, May 4, 2018

Naive Bayes classifier


Naïve Bayes classifier

Naïve Bayes is a technique used to build classifiers using Bayes theorem.

Bayes theorem describes the probability of an event occurring based on different conditions that are related to this event.

We build a Naïve Bayes classifier by assigning class labels to problem instances. These problem instances are represented as vectors of feature values. The assumption here is that the value of any given feature is independent of the value of any other feature. This is called the independence assumption, which is the naïve part of a Naïve Bayes classifier.

Monday, April 30, 2018

What is Sigmoid Curve Function ?

Sigmoid function

A sigmoid function is a mathematical function having a characteristic "S"-shaped curve or sigmoid curve.

 Often, sigmoid function refers to the special case of the logistic function shown in the figure-1 and defined by the formula.

Monday, April 23, 2018

How to use Canvas in Tkinter?

Tkinter Canvas

The Canvas is a rectangular area intended for drawing pictures or other complex layouts.
You can place graphics, text, widgets or frames on a Canvas.

Syntax
Here is the simple syntax to create this widget

w= Canvas ( master, option=value, ... )

Friday, April 20, 2018

Tkinter Button in Python 3


Tkinter Button

The Button widget is used to add buttons in a Python application. These buttons can display text or images that convey the purpose of the buttons. You can attach a function or a method to a button which is called automatically when you click the button.

Syntax

w= Button ( master, option=value, ... )


Thursday, April 19, 2018

Tkinter Widgets in Python 3


Tkinter Widgets

Tkinter provides various controls, such as buttons, labels and text boxes used in a GUI application. These controls are commonly called widgets.

There are currently 15 types of widgets in Tkinter. We present these widgets as well as a brief description in the following table-

Saturday, April 14, 2018

How to traverse the Node elements?

Traversing the Node Elements

We can traverse the elements of the node created above by creating a variable and assigning the first element to it.
 Then we use a while loop and nextval pointer to print out all the node elements. Note that we have one more additional data element and the nextval pointers are properly arranged to get the output as a days of a week in a proper sequence.

class daynames:
    def __init__(self, dataval=None):
        self.dataval = dataval
        self.nextval = None

e1 = daynames('Mon')
e2 = daynames('Wed')
e3 = daynames('Tue')
e4 = daynames('Thu')

e1.nextval = e3
e3.nextval = e2
e2.nextval = e4

thisvalue = e1

while thisvalue:
        print(thisvalue.dataval)
        thisvalue = thisvalue.nextval

When the above code is executed, it produces the following result.

Mon
Tue
Wed
Thu

The additional operations like insertion and deletion can be done by implementing appropriate methods by using this node containers in the general data structures like linked lists and trees. So we study them in the next chapters.


How to create a Python Node?


Creation of Nodes

The nodes are created by implementing a class which will hold the pointers along with the data element.

 In the below example we create a class named daynames to hold the name of the weekdays. The nextval pointer is initialized to null and three nodes and initialized with values as shown.

The nextval pointer of node e1 points to e3 while the nextval pointer of node e3 points to e2.

class daynames:
    def __init__(self, dataval=None):
        self.dataval = dataval
        self.nextval = None

e1 = daynames('Mon')
e2 = daynames('Wed')
e3 = daynames('Tue')

e1.nextval = e3
e3.nextval = e2





PYTHON - NODES

PYTHON - NODES


There are situations when the allocation of memory to store the data cannot be in a continuous block of memory. 
So we take help of pointers where the along with the data, the address of the next location of data element is also stored. 
So we know the address of the next data element from the values of current data element. 
In general such structures are known as pointers. But in Python we refer them as Nodes.

Nodes are the foundations on which various other data structures linked lists and trees can be handled in python.


Friday, April 13, 2018

Basic Tuples Operations


Basic Tuples Operations

Tuples respond to the + and * operators much like strings; they mean concatenation and repetition here too, except that the result is a new tuple, not a string.

In fact, tuples respond to all of the general sequence operations we used on strings in the prior chapter −

Python Expression
Results
Description
len)
3
Length
 + 
Concatenation
 * 4
Repetition
3 in 
True
Membership
for x in : print (x),
1 2 3
Iteration





How to Delete Tuple Elements?


Delete Tuple Elements

Removing individual tuple elements is not possible. There is, of course, nothing wrong with putting together another tuple with the undesired elements discarded.
To explicitly remove an entire tuple, just use the del statement. For example −

#!/usr/bin/python3

tup = ('physics', 'chemistry', 1997, 2000);
print (tup);
del (tup);
print ("After deleting tup : ");
print (tup);

This produces the following result. Note an exception raised, this is because after del tup tuple does not exist any more −

('physics', 'chemistry', 1997, 2000)

After deleting tup :
Traceback (most recent call last):
   File "test.py", line 9, in <module>
      print tup;
NameError: name 'tup' is not defined





How to Update Tuples in Python ?


Updating Tuples

Tuples are immutable which means you cannot update or change the values of tuple elements. You are able to take portions of existing tuples to create new tuples as the following example demonstrates −

#!/usr/bin/python

tup1 = (12, 34.56);
tup2 = ('abc', 'xyz');

# Following action is not valid for tuples
# tup1[0] = 100;

# So let's create a new tuple as follows
tup3 = tup1 + tup2;
print (tup3);

When the above code is executed, it produces the following result −

(12, 34.56, 'abc', 'xyz')