Friday, 14 September 2018

Basic calculations: Logical operators in R Languages

Logical Operators and Comparisons

The following table shows the operations and functions for logical comparisons (True or False).




Examples :

> x = 1 : 6       # Generates x=1,2,3,4,5,6
> (x > 2) & (x < 5)  # Checks whether the values are greater than 2 and less than 5

[1]  FALSE  FALSE  TRUE  TRUE  FALSE  FALSE

> x [(x > 2) & (x < 5)]  # Finds which values are greater than 2 and smaller than 5.
[1]   3  4



Logical Operators and Comparisons 



  • The shoter form performs element-wise comparisons in almost the same way as arithmetic operators.
  • The longer from evaluates left to right examining only the first element of each vector. Evaluation proceeds only until the result is determined.
Example of   " The longer form evaluates left to right examining only the first element of each vector"
> x = 1 : 6           # Generates x = 1,2,3,4,5,6

> (x > 2)  && (x < 5) 
 [1]  FALSE

is equivalent to:

> (x[1] > 2) & (x[1] < 5)
  [1]  FALSE


Note that x[1] is only the first element in x.

> x[ (x > 2) && (x < 5) ] 
   integer(0)                # Finds which values are greater than 2 and smaller than 5
This statement is equivalent to 

> x [ (x[1] > 2) & (x[1] < 5) ]
integer (0)


Thursday, 13 September 2018

Introduction to Python

What is Python?

Python is an interpreted High level programming Language for General purpose programming.
Python is created by Guido Van Rossem and first release in 1991.It is very dynamic and easy to use.



Scope :-
  • Application Development
  • Graphical Development
  • Game Development
  • Web Designing
  • Data Science
  • Machine Learning
  • Deep Learning 
Who Uses a Python?

YouTube :-  

The popular YouTube video sharing service is largely written in Python.


Google :-  

Google makes extensive use of Python in its web search systems.

Dropbox :-

Dropbox storage service codes both its server and desktop client software primarily in Python.

Raspberry :-

The Rasberry Pi single-board computer promotes Python as its educational language.

BitTorrent :-

BitTorrent peer-to-peer file sharing system began its life as a Python program.

NASA :-

NASA, Los Alamos, Fermilab, JPL, and other use Python for scientific programming tasks.

NSA :-

The NSA uses Python for cryptography and intelligence analysis.


NETFLIX :-

Netflix and Yelp have both documented the role of Python in their software infrastructures.


Python Features 
  •  Python is simple and easy to learn and also read and write.
  • Python is an example of a FLOSS (Free/Libre and Open Source Software)  which means one can freely distribute copies of this software, read it's source code, modify it, etc.
  • Python is a (High-level Language) one does need to bother about the low-level details like memory allocation, etc. while writing Python script
  • It is supported by many platforms like Linux, Windows, FreeBSD, Macintosh, Sloaris, OS/2, Amiga, AROS, AS/400, BeOS, OS/390, PlayStation, Windows CE, etc.
  • Python supports procedure-oriented programming as well as object-oriented programming.
  • Python code can invoke C and C++ libraries, can be called from and C++ programs, can integrate with Java and .NET components.
Top 5 Reasons to Learn Python

1. Dynamically Typed
     No type when declaring a variable
     Skip headaches of Java type casting
Java:      int x = 1;
               x = (int) x/2;              
                                         x now equals 0
                                         x can never equal 0.5
Python:     x = 1
                  x = x/2               x now equals 0.5

2. Simple Syntax 
  • Some programming languages will kill you with parentheses, brackets, braces, commas and colons.
  • With Python you spend less time debugging syntax and more time programming.
3. One-Liners 
  • Elegant 1-line solutions to what takes a whole block of code in other language.
  • One example: swap x and y
          Java:          int temp = x;
                            x = y;
                            y = temp;
          Python:     x,y = y,x         Wow! Now that's Pythonic

4. English-like Commands
            Java:       String name = "Bob";
                             System.out.println (name);
            Python:    name = "Bob"
                              print (name)

5. Intuitive Data Structures
          Lists, Tuples, Sets, Dictionaries
          Powerful, yet simple and intuitive to use
          Flexible (mixed data types)


Tuesday, 11 September 2018

Basic calculations: Missing data and logical operators in R Language

Missing data

R represents missing observations through the data value NA
We can detect missing values using is.na

> x  <-  NA             # assign NA to variable x
> is.na (x)               # is it missing ?
   [1]    TRUE

Now try a vector to know if any value is missing?

> x <-  c(11, NA, 13)
> is.na (x)
  [1] FALSE TRUE FALSE














Example : How to work with missing data

> x  <-  c(11, NA, 13)  # vector
> mean (x)     11 + NA + 13/2
  [1]   NA
> mean (x, na.rm = TRUE )  # NAs can be removed 
 [1]  12
                    11 + 13/2 = 12
The null object, called NULL, is returned by some functions and expressions.

Note that NA and NULL are not the same.

NA is a placeholder for something that exists but is missing.

NULL stands for something that never existed at all.





Logical Operators and Comparisons

The following table shows the operations and functions for logical comparisons (True or False)

TRUE and FALSE are reserved words denoting logical constants.


Logical Operators and Comparisons



  • The shorter form performs element-wise comparisons in almost the same way as arithmetic operators.
  • The longer form evaluates left to right examining only the first element of each vector. Evaluation proceeds only until the result is determined.
  • The longer form is appropriate for programming control-flow and typically preferred in if clauses (conditional).
TRUE and FALSE are reserved words denoting logical constants


Example

 > x  <- 5
Is x less than 10 or x is greater than 5 ?
 > (x < 10) | | (x > 5)   # | | means OR
 [1]  TRUE

Is x greater than 10 or x is greater than 5 ?
> (x > 10) | |  (x > 5)
[1] FALSE


Monday, 10 September 2018

Statisticsl Functions - Correlation and Example in R Language

Descriptive Statistics :

First hand tools which gives first hand information.
  • Central tendency of data
  • Variation in data
  • Structure and shape of data tendency
  • Relationship study (correlation coefficient, rank correlation, correlation ratio, regression etc.)
Bivariate Data

Quantitative measures provide quantitative measure of relationship.

Graphical plots provide first hand visual information about the nature and degree of relationship between two variables.

Relationship can be linear or nonlinear.



x, y : Two data vectors

Data    x = (x1,x2,....,xn)                       y = (y1,y2,...,yn)

cov (x,y) :    covariance between x and y
var (x)Variance of x


Correlation coefficient

Measures the degree of linear relationship between the two variables.
cor (x,y) : correlation between x and y




Example :-

Covariance:

Example :-

Correlation coefficient:
Exact positive linear dependence

> cor ( c(1,2,3,4) , c(1,2.3,4)  )
 [1]  1



Data on Daily water Demand




Statistical Function bivariate three dimensional plot in R Language

Bivariate Plot :

Provide first hand visual information about the nature and degree of relationship between two variables.

Relationship can be linear or nonlinear.

We discuss several types of plots through example.


Scatter Plot :

plot command:
x, y : Two data vectors
plot (x,y)
plot (x, y, type)



Get more details from help: help ("type")
Other options:

main             an overall title for the plot.
suba              sub title for the plot.
xlaba             title for the x axis.
ylaba             title for the y axis.
aspthe           y/x aspect ratio.

Example :

Daily water demand in a city depends upon weather temperature.

We know from experience that water consumption increase as weather temperature increase. 

Date on 27 days is collected as follows:
Daily water demand (in million liters)
water <- c (33710, 31666, 33495, 32758, 34067, 36069, 37497, 33044, 35216, 35383, 37066, 38037, 38495, 39895, 41311, 42849, 43038, 43873, 43923, 45078, 46935, 47951, 46085, 48003, 45050, 42924, 46061)

Temperature (in centigrade)
temp <- c (23,25,25,26,27,28,30,26,29,32,33,34,35,38,39,42,43,44,45,45,.5,
45, 46,44,44,41,37,40)


Plot command:
 
x, y :  Two data vectors
Various type of plot are possible to draw.

plot (x, y)

plot (water, temp)

 

plot (water, temp, "1")

"1" for lines,






plot (water, temp, "0")

"0" for both 'overplotted'

 


plot (water, temp, "h")

"h" for 'histogram' like 
(or 'high-density')
vertical lines 


 


plot (water, temp, "s")

"s" for stair steps.





Smooth Scatter plot

scatter.smooth (x, y) provides scatter plot with smooth curve 
Example: scatter.smooth (water, temp)


Matrix Scatter plot

The command pairs ( ) allows the simple creation of a matrix of scatter plots.
> pairs ( cbind (water, temp) )


3 Dimensional Scatter Plot:

Scatterplot3d ( ) Plots a three dimensional (3D) point cloud
> install.packages ("sccatterplot3d")
> library (scatterplot3d)
> setwd ("c: /RCourse/")
> data3d <- read.csv ("data-age-height-weight.csv")
> data3d
> scatterplot3d (data3d [, 1: 3])


More functions
  • contour ( )        for contour lines
  • dotchart ( )       for dot charts (replacement for bar charts)
  • image ( )           pictures with colors as third dimension
  • mosaicplot ( )   mosaic plot for (multidimensional) diagrams of of categorical variables (contingency tables)
  • persp ( )           perspective surfaces over the x-y plane


Sunday, 9 September 2018

Association Rule Mining in R Language

Association Rule Mining
  • In idea mining, Association Rule Learning is a popular and well researched method for discovering interesting relations between variables in large database.
  • It is intended to identify strong rules discovered in database using different measures of interests.
  • The rule found in the sales data of a supermarket would indicated that if a customer buys onions and potatoes together, he or she is likely to also buy hamburger meat.
  • Such information can be used as the basis for decisions about marketing activities such as, e.g., promotional pricing or product placements.

Constraints on below measures are used to select useful and best rules of all rules by R. After analyzing these values for all the rules, best rules for WB have been obtained.


E.g. :- Consider rule: {Jack the Ripper (1988)} => {Strawberry Blonde}
Let Jack the Ripper =X and Strawberry Blonde =Y, Then

Support (X U Y) = No of transactions involving both Jack the Ripper and Strawberry Blonde/Total no of transactions.

Confidence= No of transactions where Strawberry Blonde was also bought when Jack the Ripper was bought/ No of transactions where Jack the Ripper was bought

Lift = Ratio of observed support to the expected support


Popular Posts

Categories

100 Python Programs for Beginner (49) AI (34) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (173) C (77) C# (12) C++ (82) Course (67) Coursera (226) Cybersecurity (24) data management (11) Data Science (128) Data Strucures (8) Deep Learning (20) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (34) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (59) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (3) Pandas (4) PHP (20) Projects (29) Python (929) Python Coding Challenge (352) Python Quiz (22) Python Tips (2) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (3) Software (17) SQL (42) UX Research (1) web application (8) Web development (2) web scraping (2)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses