Monday, 5 November 2018

Relative Layout in Android

The Relative Layout is very flexible layout used in android for custom layout designing. 
It gives us the flexibility to position our component/view based on the relative or 
sibling component’s position. 
Just because it allows us to position the component anywhere we want so it
is considered as most flexible layout. For the same reason 
Relative layout is the most used layout after the Linear Layout in Android. 
It allow its child view to position relative to each other or relative to
 the container or another container.
In Relative Layout, you can use “above, below, left and right” to 
arrange the component’s position in relation to other component.  
For example, in the below image you can see content is placed in related to Heading.
Even though Android has drag and drop system to put one component in related to other inside
 relative layout. 
But actually in the background lots of XML properties are working which does this task. 
So Android developer can design UI either using drag & drop or using XML code. 
Professional developer uses both for designing UI.
Attributes of Relative layout:
Lets see different properties of Relative Layout which will be used while designing Android App UI:
1.above: Position the bottom edge of the view above the given anchor view ID and must 
be a reference of the another resource in the form of id. Example, 
]android:layout_above=”@+id/textView” .
For example, suppose a view with id textview2 is what we want to place above 
another view with id textview. Below is the code and layout image.
2. alignBottom: alignBottom is used to makes the bottom edge of the view match
 the bottom edge of the given anchor view ID and it must be a reference to another 
resource, in the form of id. Example: android:layout_ alignBottom =”@+id/button1″


In the below example we have aligned a view with id textView2 Bottom of another 
view with id textView. Below is the coded and layout image.

<!-- textView2 alignBottom of textView -->
<TextView
   android:layout_width="wrap_content"
android:layout_height="wrap_content"
   android:textAppearance="?android:attr/textAppearanceLarge"
   android:layout_centerHorizontal="true"    
   android:id="@+id/textView2"
   android:layout_alignBottom="@+id/textView"
   android:text="Text2 alignBottom of Text1"
   android:layout_marginBottom="90dp"
/>

3. alignLeft: alignLeft is used to make the left edge of the view match the left 
edge of the given anchor view ID and must be a reference to another resource, in the 
form of Example: android:layout_ alignLeft =”@+id/button1″.
Below is the code and layout image in which we have aligned a view with id 
textView2 left of another view with id textView.

<!-- textView2 alignLeft of textView -->
<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:textAppearance="?android:attr/textAppearanceLarge"
   android:id="@+id/textView2"
   android:layout_alignLeft="@+id/textView"
   android:text="Text2 alignLeft of Text1"
   android:layout_below="@+id/textView"
   android:layout_marginTop="20dp"/>

4. alignRight: alignRight property is used to make the right edge of this view match 
the right edge of the given anchor view ID and must be a reference to another resource, 
in the form like this example: android:layout_alignRight=”@+id/button1″
Below is the code and layout image in which we have aligned a view with id textView2 
right of another view with id textView.

<!-- textView2 alignRight of textView-->
<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:textAppearance="?android:attr/textAppearanceLarge"
   android:id="@+id/textView2"
   android:layout_alignRight="@+id/textView"
   android:text="Text2 alignRight of Text1"
   android:layout_below="@+id/textView"
   android:layout_marginTop="20dp"/>
5.alignStart: alignStart property is used to makes the start edge of this view match 
the start edge of the given anchor view ID and must be a reference to another resource, 
in the form of like this example: android:layout_alignStart=”@+id/button1″
Below is the alignStart code and layout image in which we have aligned a view
 with id textView2 start of another view with id textView.
<!-- Text2 alignStart-->
<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:textAppearance="?android:attr/textAppearanceLarge"
   android:id="@+id/textView2"
   android:text="Text2 align start of Text1"
   android:layout_alignStart="@+id/textView"
/>


6. alignTop: alignTop property is used to makes the top edge of this view match
 the top edge of the given anchor view ID and must be a reference to another resource, 
in the form like this example: android:layout_alignTop=”@+id/button1″.
Below is the alignTop code and layout image in which we have aligned a view 
with id textView Top of another image with id imageView.
<!--text is align top on Image-->
<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:textAppearance="?android:attr/textAppearanceLarge"
   android:id="@+id/textView"
   android:layout_alignTop="@+id/imageView"
   android:text="Text Here is AlignTop on Image"
    />

7.alignParentBottom: If alignParentBottom property is true, makes the bottom 
edge of this view match the bottom edge of the parent. The value of align parent bottom 
is either true or false. Example: android:layout_alignParentBottom=”true”
Important Note:alignParentBottom and alignBottom are two different properties. 
In alignBottom we give the reference of another view in the form of id that the 
view is aligned at the bottom of referenced view but in alignParentBottom the 
bottom edge of the view matches the bottom edge of the parent.
Below is the alignParentBottom code and layout image in which textView is simply
 displayed using the alignParentBottom.

<!-- textView is alignParentBottom -->
<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:textAppearance="?android:attr/textAppearanceLarge"
   android:id="@+id/textView"
   android:text="Text Here is AlignParentBottom with bottom margin of 120dp"
   android:layout_alignParentBottom="true"
   android:layout_alignParentLeft="true"
   android:layout_alignParentStart="true"
   android:layout_marginBottom="120dp" />
8. alignParentEnd: If alignParentEnd property is true, then it makes the
 end edge of this view match the end edge of the parent. The value of align parent 
End is either true or false. Example: android:layout_alignParentEnd=”true”.
Important Note: In alignParentEnd the bottom 
edge of the view matches the bottom edge of the parent.
Below is the alignParentEnd code and layout 
image in which textView is simply displayed on Image in the end.

<!-- Text displayed in the end of parent image-->
<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"

   android:textAppearance="?android:attr/textAppearanceLarge"
   android:id="@+id/textView"
   android:text="Text in Parent End"
   android:layout_alignBottom="@+id/imageView"
   android:layout_alignParentEnd="true"
/>
9. alignParentLeft: If alignParentLeft property is true, makes the left edge 
of this view match the left edge of the parent. The value of align parent left is either
 true or false. Example: android:layout_alignParentLeft=”true”.
Important Note: alignParentLeft and alignLeft are two different properties. In 
alignLeft we give the reference of another view in the form of id that the view is 
aligned to the left of the referenced view but in alignParentLeft the left edge of
 the view matches the left edge of the parent.
Below is the alignParentLeft example code and layout image in which textView 
is simply displayed on parent Image in the left side.

<!-- align parent left in Android -->
<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:textAppearance="?android:attr/textAppearanceLarge"
   android:id="@+id/textView"
   android:text="Text in Parent Left"
   android:layout_alignBottom="@+id/imageView"
   android:layout_alignParentLeft="true"
    />
10. alignParentRight: If alignParentRight property is true, then it makes the right edge 
of this view match the right edge of the parent. 
The value of align parent right is either true or false. 
Example: android:layout_alignParentRight=”true”.
Important Note: alignParentRight and alignRight are two different properties. 
In alignRight we give the reference of
 another view in the form of id that the view is aligned to the right of the referenced 
view but in alignParentRight the right edge of the 
view matches the right edge of the parent.
Below is the alignParentRight example code and layout image in which textView 
is simply displayed on parent Image in the right side.

<!-- alignRightParent Example -->
<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:textAppearance="?android:attr/textAppearanceLarge"
   android:id="@+id/textView"
   android:text="Text in Parent Right"
   android:layout_alignBottom="@+id/imageView"
   android:layout_alignParentRight="true"
 />
11.alignParentStart: If alignParentStart is true, then it makes the start edge 
of this view match the start edge of the parent.
The value of align parent start is either true or false. 
Example: android:layout_alignParentStart=”true”.
Important Note: alignParentStart and alignStart are two different properties, 
In alignStart we give the reference of another view in the form of id 
that the view is aligned at the start of referenced view but in alignParentStart 
the start edge of the view matches the start edge of the parent(RelativeLayout).
Below is the alignParentStart example code and layout image in 
which textView is simply displayed on parent Image in the right side.



<!-- alignParentStart Example -->
<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:textAppearance="?android:attr/textAppearanceLarge"
   android:id="@+id/textView"
   android:text="Text in Parent Start"
   android:layout_alignTop="@+id/imageView"
   android:layout_alignParentStart="true"
    />
12.alignParentTop: If alignParentTop is true, then it 
makes the top edge of this view match the top edge of the parent. 
The value of align parent Top is either true or false. Example: android:layout_alignParenTop=”true”.
Important Note: alignParentTop and alignTop are two different properties, 
In alignTop we give the reference of another view in the form of id that the view is aligned to 
the top of the referenced view but in alignParentTop the top edge of 
the view matches the top edge of the parent(RelativeLayout).
Below is the example code of alignParentTop property and also layout image.

<!-- alignParentTop example -->
<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="Text1 align parent top"
   android:layout_alignParentTop="true"
   android:layout_margin="20dp"
   android:textSize="20sp"
   android:textColor="#000"/>
13.centerInParent: If center in parent is true, 
makes the view in the center of the screen vertically and horizontally. 
The value of center in parent is either true or false. 
Example: android:layout_centerInParent=”true”.
Below is the example code of centerInParent property and also layout image.


<!-- centerInParent example -->
<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="Text1 center in parent"
   android:layout_centerInParent="true"
   android:textSize="20sp"
   android:textColor="#000"
/>
14.centerHorizontal: If centerHorizontal property is true, makes the view horizontally center. 
The value of centerHorizontal is either true or false.Example: android:layout_centerHorizontal=”true”.
Below is the example code of centerHorizontal property and also layout image.

<!-- centerHorizontal example -->
<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="Text1 center Horizontal"
   android:layout_centerHorizontal="true"
   android:textSize="20sp"
   android:textColor="#000"
/>
 15.centerVertical: If centerVertical property is true, make the view vertically center. 
The value of align parent bottom is either true or false. 
Example: android:layout_centerVertical=”true”.
Below is the example code of centerVertical property and also layout image.

<!-- centerVertical example -->
<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="Text1 center vertical"
   android:layout_centerVertical="true"
   android:textSize="20sp"
   android:textColor="#000"
/>

Friday, 19 October 2018

Data Mining Process in R Language

Phases in a typical Data Mining effort:

1.  Discovery
     Frame business problem
     Identify analytics component
     Formulate initial hypotheses

2.  Data Preparation
     Obtain dataset form internal and external sources
     Data consistency checks in terms of definitions of fields, units of measurement, time periods etc.,
     Sample

3.  Data Exploration and Conditioning
     Missing data handling, Range reason ability, Outliers,
     Graphical or Visual Analysis
     Transformation, Creation of new variables, and Normalization
     Partitioning into Training, validation, and Test datasets

4.  Model Planning
    - Determine data mining task such as prediction, classification etc.
     - Select appropriate data mining methods and techniques such as regression, neural networks, clustering etc.
     
5.  Model Building
     Building different candidate models using selected techniques and their variants using training data
     Refine and select the final model using validation data
     Evaluate the final model on test data
  
6.  Results Interpretation
      Model evaluation using key performance metrics

7. Model Deployment
       Pilot project to integrate and run the model on operational systems

Similar data mining methodologies developed by SAS and IBM Modeler (SPSS Clementine) are called SEMAA and CRISP-DM respectively

Data mining techniques can be divided into Supervised Learning Methods and Unsupervised Learning Methods

Supervised Learning
-  In supervised learning, algorithms are used to learn the function 'f' that can map input variables (X) into output variables (Y)
                        Y = f(X)
- Idea is to approximate 'f' such that new data on input variables (X) can predict the output variables (Y) with minimum possible error (ε)


Supervised Learning problem can be grouped into prediction and classification problems

Unsupervised Learning
  -  In Unsupervised Learning, algorithms are used to learn the underlying structure or patterns hidden in the data

Unsupervised Learning problems can be grouped into clustering and association rule learning problems

Target Population
  - Subset of the population under study
  - Results are generalized to the target population

Sample 
  - Subset of the target population

Simple Random Sampling
  - A sampling method where in each observation has an equal chance of being selected.

Random Sampling
  - A sampling method where in each observation does not necessarily have an equal chance of being selected

Sampling with Replacement
  - Sample values are independent

Sampling without Replacement
  - Sample values aren't independent

Sampling results in less no. of observation than the no. of total observation in the dataset

Data Mining algorithms
  - Varying limitations on number of observation and variables

Limitation due to computing power and storage capacity

Limitations due to statistical being used

How many observation to build accurate models?

Rare Event, e.g., low response rate in advertising by traditional mail or email
 - Oversampling of 'success' cases
 - Arise mainly in classification tasks
 - Costs of misclassification
 - Costs of failing to identify 'success' cases are generally more than costs of detailed review of all cases
 - Prediction of 'success is likely to come at cost of misclassifying more 'failure' cases as 'success' cases than usual

Wednesday, 17 October 2018

Steps to write a programe with Examples of Programming in R Language

Steps to write a programme
  • A programme is a set of instructions or commands which are written in a sequence of operations i.e., what comes first and what comes after that.
  • The objective of a programme is to obtain a defined outcome based on input variables.
  • The computer is instructed to perform the defined task.
  • Computer is an obedient worker but it has its own language.
  • We do not understand computer's language and computer does not understand our language.
  • The software help us and work like an interpreter between us and computer.
  • We say something in software's language and software informs it to computer.
  • Computer does the task and informs back to software.
  • The software translates it to our language and informs us.
  • Programme in R is written as a function using function.
  • Write down the objective, i.e., what we want to obtain as an outcome.
  • Translate it in the language of R.
  • Identify the input and output variables.
  • Identify the nature of input and output, i.e., numeric string, factor, matrix etc.
  • Input and output variables can be single variable, vector, matrix or even a function itself.
  • The input variables are the component of function which are reported in the argument of function ( ) .
  • The output of a function can also be input to another function.
  • The output of an outcome can be formatted as per the need and requirement.   

Tips :
  1. Loops usually slower the speed of programmes, so better is to use vectors and matrices.
  2. Use # symbol to write comment to understand the syntax.
  3. Use the variable names which are easy to understand.
  4. Don't forget to initialize the variables.


Example 1

Input variables : x, y, n (if x and y have different number of observations, choose different numbers, say n1 and n2)


We need summation, so use sum function or alternatively computer it through vectors.




Numpy in Python

Numpy
  • Numpy is the core library for scientific computing in Python.
  • It provides a high-performance multidimensional array object, and tools for working with these arrays.
Multi-dimension array-
Example:-

Advantage of Numpy over List
  • Less Memory
  • Fast
  • Convenient











Numpy Operations 
  • Find the dimension of the array
  • Find the byte size of each element
  • Find the data type of the elements











Numpy Special Functions


Monday, 15 October 2018

R Programming vs Python Comparison

R Programming

R is a programming language and free software environment for statistical computing and graphics that is supported by the R Foundation for Statistical Computing.



Python


python is an interpreted high-level programming language for general-purpose programming. It has a design philosophy that notably using significant white-space.

 1. Ease of Learning :-
    R is not ease to Learn and Python is easy to learn.

2. Speed :-
    R is a Low Level Language Slower and Python is a High Level Language Faster.

3. Data Handling Capabilities :- 
    R is Convenient for large Datasets and Python is Progressing with new Releases.

4. Graphics and Visualization :-
      R is Easy and Better and Python is Complex and Tedious.

5. Deep Learning Support :-
     R is New to Deep Learning and Python is Works Amazingly (TensorFlow).

6. Flexibility :- 
     R is Statistical Tests and Models and Python is Websites and Applications.

7. Code Repository & Libraries
    R is Huge Repository more Libraries and Python is Lesser Libraries.

8. Popularity Index :-
  


9. Job Scenario :-
 


10. Community & Customer Support :-


Friday, 12 October 2018

Linear Layout in Android

Linear layout is a simple layout used in android for layout designing. In the Linear layout all the elements are displayed in linear fashion means all the childs/elements of a linear layout are displayed according to its orientation. The value for orientation property can be either horizontal or vertical.
Types Of Linear Layout Orientation
There are two types of linear layout orientation:
  1. Vertical
  2. Horizontal
As the name specified these two orientations are used to arrange there child one after the other, in a line, either vertically or horizontally. Let’s we describe these in detail.
1.Vertical:
In this all the child are arranged vertically in a line one after the other. In below code snippets we have specified orientation “vertical” so the childs/views of this layout are displayed vertically.
2. Horizontal:
In this all the child are arranged horizontally in a line one after the other. In below code snippets we have specified orientation “horizontal” so the childs/views of this layout are displayed horizontally.


Important Note: All of the layout managers can be nested. This means that you can put a Relative Layout or Frame Layout as a child to Linear Layout.
Main Attributes In Linear Layout:
Now let’s  we discuss about the attributes that helps us to configure a linear layout and its child controls. Some of the most important attributes you will use with linear layout include:
1. orientation: The orientation attribute used to set the childs/views horizontally or vertically. In Linear layout default orientation is vertical.


Example:  Orientation vertical:
Example: Orientation Horizontal:
2. gravity: The gravity attribute is an optional attribute which is used to control the alignment of the layout like left, right, center, top, bottom etc.
Example: We have set gravity right for linear layout. So the buttons gets align from right side in Horizontal orientation.



3. layout_weight: The layout weight attribute specify each child control’s relative importance within the parent linear layout.
Example: weight property for button in linear layout. In the below example one button is of weight 2 and other is of weight 1.
In the layout image you can notice Button with weight 2 gets more size related the other.

4. weightSum: weightSum is the sum up of all the child attributes weight. This attribute is required if we define weight property of the childs.
Example: In the same above example of weight, we can define weightSum value 3.

Example of Linear Layout:
Now lets design 2 linear layout UI. First we have designed using weight attribute and second without using it. So below layout output will clear the difference between them:

Example 1: First we will design Android Linear Layout without using weight property
In this example we have used one TextView and 4 Button. The orientation is set to vertical.
Below is the code of activity_main.xml
Output Screen:

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 (351) 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