The code above create a data frame which has the following columns
livch1 (input): value = 1 if the "livch" column of the CSV contains value 1 ; 0 otherwise
livch2 (input): value = 1 if the "livch" column of the CSV contains value 2 ; 0 otherwise
livch3 (input): value = 1 if the "livch" column of the CSV contains value 3+ ; 0 otherwise
age (input): value = numeric value in the "age" column of the CSV
age^2 (input): value = square of numeric value in the "age" column of the CSV
urban (input): value = 1 if the "urban" column of the CSV has value "Y" ; 0 otherwise
use (output): value = 1 if the "use" column of the CSV has value "Y" ; 0 otherwise
Currently csv files and the libsvm format are supported for creating data frame, to load a libsvm-format file, call "DataQuery.libsvm()" instead of "DataQuery.csv(..)".
In the future more option will be added for the supported format
Step 2: Create and train the glm against the training data in step 1
Suppose you want to create logistic regression model from GLM and train the logistic regression model against the data frame
The line "Glm.logistic()" create the logistic regression model, which can be easily changed to create other regression models (For example, calling "Glm.linear()" create a linear regression model)
The line "glm.fit(..)" performs the GLM training.
Step 3: Use the trained regression model to predict on new data
To run the trained glm against the test data, load the testing data into another data frame:
GLM is generalized linear model for exponential family of distribution model b = g(a). g(a) is the inverse link function.
Therefore, for a regressions characterized by inverse link function g(a), the regressions problem be formulated as we are looking for model coefficient set x in
g(A * x) = b + e
And the objective is to find x such for the following objective:
min (g(A * x) - b).transpose * W * (g(A * x) - b)
Suppose we assumes that e consist of uncorrelated naive variables with identical variance, then W = sigma^(-2) * I, and The objective
min (g(A * x) - b) * W * (g(A * x) - b).transpose
is reduced to the OLS form:
min || g(A * x) - b ||^2
Iteratively Re-weighted Least Squares estimation (IRLS)
In regressions, we tried to find a set of model coefficient such for:
A * x = b + e
A * x is known as the model matrix, b as the response vector, e is the error terms.
In OLS (Ordinary Least Square), we assumes that the variance-covariance
matrix V(e) = sigma^2 * W
, where: W is a symmetric positive definite matrix, and is a diagonal matrix sigma is the standard error of e
In OLS (Ordinary Least Square), the objective is to find x_bar such that e.transpose * W * e is minimized (Note that since W is positive definite, e * W * e is alway positive) In other words, we are looking for x_bar such as (A * x_bar - b).transpose * W * (A * x_bar - b) is minimized
Let
y = (A * x - b).transpose * W * (A * x - b)
Now differentiating y with respect to x, we have
dy / dx = A.transpose * W * (A * x - b) * 2
To find min y, set dy / dx = 0 at x = x_bar, we have
A.transpose * W * (A * x_bar - b) = 0
Transform this, we have
A.transpose * W * A * x_bar = A.transpose * W * b
Multiply both side by (A.transpose * W * A).inverse, we have
x_bar = (A.transpose * W * A).inverse * A.transpose * W * b
This is commonly solved using IRLS
The implementation of Glm based on iteratively re-weighted least squares estimation (IRLS)
I have just upload Vagrantfile for latest magento (2.16) and latest Ubuntu (bento/ubuntu-14.04) to github so that interested readers can install the latest magento for development via Vagrant on their computer:
The github repo contains the Vagrantfile and Vagrantfile.config.yml adopted from the "Magento Developer Guide" book but updated based on the trial-and-errors with the latest magento, ubuntu and PHP
The objective is to address several issues with the original Vagrantfile provided by "Magento Developer Guide" so that it is compatible with the latest magento (current version 2.16) and Ubuntu (current version: Ubuntu 14.04.5 LTS)
Some known issues with the original Vagrantfile provided by "Magento Developer Guide" are:
The vm.box "ubuntu/vivid64" for vagrant is not longer provided
The default PHP version (7.1) provided by latest ubuntu (after running apt-get update on bento/ubuntu-14.04) is not compatible with magento 2.16 due to the issues with mcrypt no longer supported in PHP 7.1
php5.6-mbstring and php5.6-zip are needed for the magento 2.16 to work correctly
Version
The following list the version of the various softwares installed by the Vagrantfile on the ubuntu VM:
vm.box: bento/ubuntu-14.04
magento: magento 2 (version: 2.16)
PHP: 5.6
MySQL: 5.6
Currently the Vagrantfile is tested to be working on host computer which is Windows 10
Obtain the magento public and private secret keys (Follow this link) and replace the "[magent_public_key]" and "[magento_private_key]" in Vagrantfile.config.yml with the obtained keys
Obtain a github oauth access key (Follow this link and replace the "[github_oauth]" in Vagrantfile.config.yml with the obtained github oauth token
Change the "email@change.me" in Vagrantfile.config.yml to your email of choice
Change the "[magento_host_path]" in Vagrantfile.config.yml to your local path on your host computer on which you want the magento files to be installed
Run the following command on your host computer:
git clone https://github.com/chen0040/vagrant-magento-2.16.git
cd vagrant-magento-2.16
vagrant up
Add the line "192.168.10.10 magento.box" to /etc/hosts on your host computer (If you host computer is Windows, then the hosts file is located at C:\Windows\System32\drivers\etc\hosts)
Open your browser and enter "http://magento.box" (To change this to your url of choice, replace it in the Vagrantfile.config.yml)
To login to the vagrant vm box, run the command "vagrant ssh". If you are using putty, ssh to 192.168.10.10 (username: vagrant, password: vagrant)
Issues and Solutions
If you encounter some of the issues when running Vagrantfile, you can refer to the following:
Issue: Vagrant was unable to mount VirtualBox shared folders. This is usually because the filesystem "vboxsf" is not available. This filesystem is made available via the VirtualBox Guest Additions and kernel module.