May 4, 2018

Textual description of firstImageUrl

Solve Linear regression problem mathematically with least square method : Find slope and intercept of linear classifier

Linear regression is one of basic supervised learning which is used to predict outcome. In linear regression problem, we find best fit line using sample points with one independent variable and one dependent variable. Basic idea is to finds a linear function which predicts the dependent variable values as a function of the independent variables.
In order to best fit line which is represented by find linear function - we can use ordinary least squares method(minimize the residuals) or least absolute deviations (minimizing the sum of absolute values of residuals). Residuals means vertical distances between the points of the data set and the fitted line (wiki).
Linear best fit line(blue) for data points(Red) and green line indicates error/residues (Source:wiki

Least square method :-  Using this approach vertical distances between the data set points and the fitted line is computed such that sum of all distances for each point from best fit line is minimum. 

Dataset:- (x, y) = (2,10) (4,9) (3,6) (6,6) (8,6)  (8,3) (10,2)

Algorithm : For finding best fit line (y= . mX+ c) , we have to find value of m(slope) and c(intercept). Follow below steps to find slope and intercept.

1. Compute mean of x and y values. Here x̅  and ȳ are mean of x and y data points.

2.  Calculate slope of line(linear classifier)

3. Calculate intercept of line .

Use python terminal to find mean of x and y data points.
Python 2.7.10 (default, Jul 15 2017, 17:16:57) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> a = [2,4,3,6,8,8,10]
>>> numpy.mean(a)
>>> b = [10,9,6,6,6,3,2]
>>> numpy.mean(b)

x̅ = 5.86
ȳ = 6.0

Find slope(m):  Pre-process sample data in tabular form below and compute slope of line.

iteration# xi yi xi - x̅ yi - ȳ (xi - x̅)(yi -ȳ)= (P) (xi - x̅)2 =(Q)
1 2 10 -3.86 4 -15.44 14.9
2 4 9 -1.86 3 -5.58 3.46
3 3 6 -2.86 0 0 8.18
4 6 6 0.14 0 0 0.02
5 8 6 2.14 0 0 4.58
6 8 3 2.14 -3 -6.42 4.58
7 10 2 4.14 -4 -16.56 17.14
Slope of line:
Compute y-intercept :

Now equation of line  :

Best fit line separates data points below and this line can be used to predict outcome for other test(new) data points.

May 2, 2018

Textual description of firstImageUrl

Spring Boot Microservice using CLI : How to start development of SpringBoot microservice using Spring Command line tool

In few clicks we can start development of microservice using Spring Boot. Follow below steps to setup SpringBoot CLI and start creating microservice.

1. Download file from below repo or below URL.

2. Unzip the downloaded zip file. Open a terminal window and change the terminal prompt to the bin folder.
Optional: Add bin folder to the system path so that Spring Boot can be run from any location.

3. Verify the CLI installation with the following command. On success, the Spring CLI version will be printed in the console:

4. Now we are ready to create our first microservice (REST service using Groovy). Create a file with name app.groovy and paste below code lines in it. I have created a directory "springBootCLI" and created a fie app.groovy in it and added below code in it.

class HelloworldController {
    String sayHello() {
        "Hello, Devinline!"

5. Run Groovy application using following command. I am executing this command from bin directory and executing app.groovy.

  bin ./spring run /Users/n0r0082/springBootCLI/app.groovy 

6. Once application has been successfully started, we can view service output in browser at "http://localhost:8080/".

Spring Boot automatically picked up Tomcat as the webserver and embedded it into the application, deploy it and its accessible on localhost at port 8080.