Sneha R
Sneha R
EXPERIMENT – 11
1. Load the data: Load the dataset that you want to classify or predict. The dataset
should be split into a training set and a test set.
2. Normalize the data: Normalize the data by scaling the features to have zero mean
and unit variance.
3. Choose the kernel function: Choose a kernel function that maps the data to a
higherdimensional space. The most commonly used kernel functions are the linear
kernel, the polynomial kernel, and the radial basis function (RBF) kernel.
4. Train the model: Train the SVM model on the training data using the chosen kernel
function.
5. Choose the regularization parameter: Choose the regularization parameter (C) that
controls the trade-off between maximizing the margin and minimizing the
classification error.
6. Test the model: Test the SVM model on the test data to evaluate its performance.
7. Tune the hyperparameters: Tune the hyperparameters of the SVM model using
techniques such as grid search or random search to find the best combination of
kernel function, regularization parameter, and other hyperparameters.
8. Deploy the model: Deploy the trained SVM model to make predictions on new data.
Program Code:-
dataset = read.csv('social.csv')
dataset = dataset[3:5]
library(caTools) set.seed(123)
install.packages('e1071') library(e1071)
classifier = svm(formula = Purchased ~ .,
data = training_set, type = 'C-
classification' kernel = 'linear')
OUTPUT:-
EXPERIMENT – 12
2. Data Pre-processing: Check for missing values and handle them, handle outliers if
any, and remove or transform variables that do not contribute to the model.
3. Split the dataset: Split the dataset into a training set and a testing set. The training
set is used to train the model, while the testing set is used to evaluate the
performance of the model.
4. Feature Scaling: Scale the input variables (or the independent variables) to have the
same range to ensure that no variable dominates the others in the modeling process.
5. Model Training: Train the logistic regression model using the training set. The logistic
regression model calculates the probability of the output variable taking a particular
value given the input variables (or the independent variables).
6. Model Evaluation: Evaluate the performance of the model using the testing set.
There are several metrics to evaluate the performance of the model, such as
accuracy, precision, recall, F1 score, and area under the ROC curve.
7. Model Improvement: If the model does not perform well, try to improve the model
by changing the hyperparameters, selecting the relevant features, or using other
modeling techniques.
8. Model Deployment: Once the model is finalized and performs well on the testing set,
deploy it to the production environment for making predictions on new data.
Program Code:-
install.packages("dplyr")
install.packages("caTools")
install.packages("ROCR")
# loading packages
library(dplyr)
library(caTools)
library(ROCR) dataSet =
mtcars View(dataSet)
table(split)
# Training model
family = "binomial")
logistic_model
summary(logistic_model)
predict_reg <-
predict(logistic_model,
table(test_reg$vs, predict_reg)
Output:-
EXPERIMENT – 13
Algorithm:-
1. Read each item in the transaction.
2. Calculate the support of every item.
3. If support is less than minimum support, discard the item. Else, insert it into frequent
itemset.
4. Calculate confidence for each non- empty subset.
5. If confidence is less than minimum confidence, discard the subset. Else, it into strong
rules.
Program Code:-
install.packages("arules")
install.packages("arulesViz")
install.packages("RColorBrewer")
library(arules) library(arulesViz)
library(RColorBrewer)
data("Groceries") rules <-
apriori(Groceries, parameter =
list(supp = 0.01, conf = 0.2))
inspect(rules[1:10])
arules::itemFrequencyPlot
Output:-