chmod 777/media/ enable
chmod 444/media/ disable 
cat /dev/null > ~/.bash_history && history -c && exit
*****************************************************************
*****************************************************************



***************************************linear regression assignment 2 *****************************
install.packages('MASS')
install.packages('ISLR')
install.packages('DAAG')
install.packages("lattice")

library(ISLR)
library(MASS)
library(DAAG)
library(nlme)
data()
head(Auto)
View(Auto)
lmodel <- cv.lm(Auto, mpg ~ cylinders + displacement + horsepower + weight + acceleration + year + origin, m=2, dots=FALSE, seed=29, plotit = TRUE, printit = TRUE)
lmodel <- cv.lm(Auto, mpg ~ cylinders + displacement + horsepower + weight + acceleration + year + origin, m=3, dots=FALSE, seed=29, plotit = TRUE, printit = TRUE)
lmodel <- cv.lm(Auto, mpg ~ cylinders + displacement + horsepower + weight + acceleration + year + origin, m=8, dots=FALSE, seed=29, plotit = TRUE, printit = TRUE)

cv.error.10=rep(0,10)
set.seed(17)

for(i in 2:10)
{
  lmodel <- cv.lm(Auto, mpg ~ cylinders + displacement + horsepower + weight + acceleration + year + origin, m=i, dots=FALSE, seed=29, plotit = TRUE, printit = TRUE)
  cv.error.10[i]=attr(lmodel,"ms")
}
j<-1
for(j in 1:10)
{
  print(cv.error.10[j])
}
X = c(1,2,3,4,5,6,7,8,9,10)
Y = cv.error.10

plot(X, Y, type = 'l', xlab = "Value of K", ylab = "mean square error", main = "with change in value of K there is change in Mean Square Error")

********************************assigment 3*********************************

install.packages("arules")
install.packages("arulesViz")
install.packages("plotly")

library(arules)
library(arulesViz)
library(datasets)

data(Groceries)
View(Groceries)
summary(Groceries)

itemFrequencyPlot(Groceries, topN=20, type="absolute")
rules<-apriori( Groceries, parameter = list( supp = 0.001, conf = 0.8 ))
View(rules)
options(digits = 2)
inspect(rules[1:5])

rules<-apriori( Groceries,parameter = list( supp = 0.001, conf = 0.8, maxlen = 3 ))

subset.matrix<-is.subset(rules, rules)
subset.matrix[lower.tri( subset.matrix, diag=T )] <- NA

redundant<-colSums(subset.matrix,na.rm = T ) >= 1
rules.pruned <- rules[!redundant]
summary(rules)

rules <- apriori(Groceries, parameter = list( supp = 0.001, conf = 0.08), appearance = list( default="lhs", rhs="whole milk"), control=list(verbose=F))
rules <- sort(rules, decreasing=TRUE, by="confidence")
inspect(rules[1:5])

rules<- apriori(Groceries, parameter = list(supp = 0.001, conf=0.15,minlen=2), appearance=list(default="rhs", lhs="whole milk"), control=list(verbose=F))
rules<- sort(rules, decreasing=TRUE, by="confidence")
inspect(rules[1:5])

plot(rules, method="graph", engine="interactive", shading=NA)

********************************k means clustering  Assignment 4**********************************

import numpy as np

import matplotlib.pyplot as plt


import pandas as pd
dataset = pd.read_csv('C:/Users/admin/Downloads/Mall_Customers.csv')
X = dataset.iloc[:, [3, 4]].values


from sklearn.cluster import KMeans



for i in range(1, 11):

kmeans = KMeans(n_clusters = i, init = 'k-means++', random_state = 42)

kmeans.fit(X)



kmeans = KMeans(n_clusters = 5, init = 'k-means++', random_state = 42)

y_kmeans = kmeans.fit_predict(X)



plt.scatter(X[y_kmeans == 0, 0], X[y_kmeans == 0, 1], s = 50, c = 'red', label = 'Cluster 1')

plt.scatter(X[y_kmeans == 1, 0], X[y_kmeans == 1, 1], s = 50, c = 'blue', label = 'Cluster 2')

plt.scatter(X[y_kmeans == 2, 0], X[y_kmeans == 2, 1], s = 50, c = 'green', label = 'Cluster 3')

plt.scatter(X[y_kmeans == 3, 0], X[y_kmeans == 3, 1], s = 50, c = 'cyan', label = 'Cluster 4')

plt.scatter(X[y_kmeans == 4, 0], X[y_kmeans == 4, 1], s = 50, c = 'magenta', label = 'Cluster 5')

plt.scatter(kmeans.cluster_centers_[:, 0], kmeans.cluster_centers_[:, 1], s = 150, c = 'yellow', label = 'Centroids')

plt.title('Clusters of CUSTOMERS')

plt.xlabel('Annual Income (k$)')

plt.ylabel('Spending Score (1-100)')


plt.legend()

plt.show()


************************************************SVM  Assignment 5****************************************

import numpy as np

import matplotlib.pyplot as plt

from matplotlib import style

style.use("ggplot")

from sklearn import svm

x=[1,5,1.5,8,1,9]

y=[2,8,1.8,8,0.6,11]

plt.scatter(x,y)

plt.show()

x=np.array([[1,2],[5,8],[1.5,1.8],[8,8],[1,0.6],[9,11]])

y=[0,1,0,1,0,1]

clf=svm.SVC(kernel='linear',C=1.0)

clf.fit(x,y)

print(clf.predict(x))

w = clf.coef_[0]
print(w)


a = -w[0] / w[1]

xx = np.linspace(0, 12)
yy = a * xx - clf.intercept_[0] / w[1]

h0 = plt.plot(xx, yy, 'k-', label="non weighted div")

plt.scatter(x[:, 0], x[:, 1], c=y)
plt.legend()
plt.show()


********************************pca assignment 8*********************************
> mydata<-read.csv("C:/Users/admin/Downloads/pca_gsp.csv")
> mydata<-read.csv(file.choose())
> attach(mydata)
> summary(mydata)
> names(mydata)
> X <- mydata
> cor(X)
> X <- cbind(Ag, Mining, Constr, Manuf, Manuf_nd, Transp, Comm, Energy, TradeW, TradeR,
+            RE, Services, Govt)
> X <- cbind(Ag, Mining, Constr, Manuf, Manuf_nd, Transp, Comm, Energy, TradeW, TradeR,
+            RE, Services, Govt)
> summary(X)
> cor(X)
> pcal<-princomp(X, scores=TRUE, cor=TRUE)
> summary(pcal)
> loadings(pcal)
> loadings(pcal)
> plot(pcal)
> screeplot(pcal,type="line",main="Screen Plot")
> biplot(pcal)
> pcal$scores[1:10,]



***********Assgn 7*************************************************ass 7******************************
package com.gg.ml;

import java.io.File;


import weka.classifiers.Classifier;

import weka.classifiers.Evaluation;
import weka.classifiers.bayes.NaiveBayesMultinomial;
import weka.core.Instances;
import weka.core.converters.ArffLoader;
import weka.filters.Filter;
import weka.filters.unsupervised.attribute.StringToWordVector;

/**

 * @author Gowtham Girithar Srirangasamy
 *
 */
public class NaiveBayesDemo {
/** file names are defined */
public static final String TRAINING_DATA_SET_FILENAME = "naive-train.arff";
public static final String TESTING_DATA_SET_FILENAME = "naive-test.arff";
public static final String PREDICTION_DATA_SET_FILENAME = "naive-confused.arff";

/**

* This method is to load the data set.

* @param fileName
* @return
* @throws Exception
*/
public static Instances getDataSet(String fileName) throws Exception {
/**
* we can set the file i.e., loader.setFile("finename") to load the data
*/
StringToWordVector filter = new StringToWordVector();
int classIdx = 1;
/** the arffloader to load the arff file */
ArffLoader loader = new ArffLoader();
/** load the traing data */
loader.setSource(NaiveBayesDemo.class.getResourceAsStream("/"+fileName));
/**
* we can also set the file like loader3.setFile(new
* File("test-confused.arff"));
*/
//loader.setFile(new File(fileName));
Instances dataSet = loader.getDataSet();
/** set the index based on the data given in the arff files */
dataSet.setClassIndex(classIdx);
filter.setInputFormat(dataSet);
dataSet = Filter.useFilter(dataSet, filter);
return dataSet;
}

/**

* This method is used to process the input and return the statistics.

* @throws Exception
*/
public static void process() throws Exception {

Instances trainingDataSet = getDataSet(TRAINING_DATA_SET_FILENAME);

Instances testingDataSet = getDataSet(TESTING_DATA_SET_FILENAME);
Instances predictingDataSet = getDataSet(PREDICTION_DATA_SET_FILENAME);
/** Classifier here is Linear Regression */
Classifier classifier = new NaiveBayesMultinomial();
/** */
classifier.buildClassifier(trainingDataSet);
/**
* train the alogorithm with the training data and evaluate the
* algorithm with testing data
*/
Evaluation eval = new Evaluation(trainingDataSet);
eval.evaluateModel(classifier, testingDataSet);
/** Print the algorithm summary */
System.out.println("** Naive Bayes Evaluation with Datasets **");
System.out.println(eval.toSummaryString());
System.out.print(" the expression for the input data as per alogorithm is ");
System.out.println(classifier);
for (int i = 0; i < predictingDataSet.numInstances(); i++) {
System.out.println(predictingDataSet.instance(i));
double index = classifier.classifyInstance(predictingDataSet.instance(i));
String className = trainingDataSet.attribute(0).value((int) index);
System.out.println(className);
}

}


}









************************************************************************