ONE-WAY CLASSIFICATION ________________________________________________________________________________________________ Definition : Analysis of variance (ANOVA) uses F-tests to statistically assess the equality of means when you have three or more groups. When we come across a problem when we need to compare more than two means then we perform Analysis of variance (ANOVA). Assumptions for ANOVA …

What is ggplot2 ? It is a package in R. An implementation of the grammar of graphics. It is a ‘third’ graphics system for R(along with base and lattice), build based upon the grid system. Available from CRAN via install.package().

Central Tendency or Average. Last time I discussed about Data Types. Today I am going to discuss about “Central Tendency” or “Average”. The word “Average” denotes a ‘representative’ or ‘typical value’ of a whole set of observations. Average usually occupies a central position, so it is also known as measures …

Definition: Cox regression (or proportional hazards regression) is a method for investigating

Hello, Today we will discuss the codes snippets and implementation of different Machine Learning Algorithm. The code snippets is in Python as well as in R. Linear Regression Python Code

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#Import Library #Import other necessary libraries like pandas, numpy... from sklearn import linear_model #Load Train and Test datasets #Identify feature and response variable(s) and values must be numeric and numpy arrays x_train=input_variables_values_training_datasets y_train=target_variables_values_training_datasets x_test=input_variables_values_test_datasets # Create linear regression object linear = linear_model.LinearRegression() # Train the model using the training sets and check score linear.fit(x_train, y_train) linear.score(x_train, y_train) #Equation coefficient and Intercept print('Coefficient: \n', linear.coef_) print('Intercept: \n', linear.intercept_) #Predict Output predicted= linear.predict(x_test) |

R Code

1 2 3 4 5 6 7 8 9 10 11 12 |
#Load Train and Test datasets #Identify feature and response variable(s) and values must be numeric and numpy arrays x_train <- input_variables_values_training_datasets y_train <- target_variables_values_training_datasets x_test <- input_variables_values_test_datasets x <- cbind(x_train,y_train) <span class="c"># Train the model using the training sets and check score </span><span class="hl std">linear</span> <span class="hl kwb"><-</span> <span class="hl kwd">lm</span><span class="hl std">(y_train</span> <span class="hl opt">~</span> <span class="hl std">.</span><span class="hl std">,</span> <span class="hl kwc">data</span> <span class="hl std">= x</span><span class="hl std">) summary(linear)</span><span class="c"> #Predict Output predicted= </span><span class="n">predict</span><span class="p">(linear,</span><span class="n">x_test</span><span class="p">) </span> |

Logistic Regression Python Code

1 2 3 4 5 6 7 8 9 10 11 12 13 |
#Import Library from sklearn.linear_model import LogisticRegression #Assumed you have, X (predictor) and Y (target) for training data set and x_test(predictor) of test_dataset # Create logistic regression object model = LogisticRegression() # Train the model using the training sets and check score model.fit(X, y) model.score(X, y) #Equation coefficient and Intercept print('Coefficient: \n', model.coef_) print('Intercept: \n', model.intercept_) #Predict Output predicted= model.predict(x_test) |

R Code

1 2 3 4 5 6 |
x <- cbind(x_train,y_train) <span class="c"># Train the model using the training sets and check score </span><span class="hl std">logistic</span> <span class="hl kwb"><-</span> g<span class="hl kwd">lm</span><span class="hl std">(y_train</span> <span class="hl opt">~</span> <span class="hl std">.</span><span class="hl std">,</span> <span class="hl kwc">data</span> <span class="hl std">= x,family='binomial'</span><span class="hl std">) summary(logistic)</span><span class="c"> #Predict Output predicted= </span><span class="n">predict</span><span class="p">(</span><span class="hl std">logistic</span><span class="p">,</span><span class="n">x_test</span><span class="p">)</span> |

Decision Tree Decision Tree Python Code

1 2 3 4 5 6 7 8 9 10 11 12 |
#Import Library #Import other necessary libraries like pandas, numpy... from sklearn import tree #Assumed you have, X (predictor) and Y (target) for training data set and x_test(predictor) of test_dataset # Create tree object model = tree.DecisionTreeClassifier(criterion='gini') # for classification, here you can change the algorithm as gini or entropy (information gain) by default it is gini # model = tree.DecisionTreeRegressor() for regression # Train the model using the training sets and check score model.fit(X, y) model.score(X, y) #Predict Output predicted= model.predict(x_test) |

…

Hello, I thought of starting a series in which I will Implement various Machine Leaning techniques using Python. To start with today we will look at Logistic Regression in Python and I have used iPython Notebook. Here is the data set used as part of this demo Download We will …