This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> library(arules) | |
> data("Adult") | |
> rules <- apriori(Adult,parameter = list(supp = 0.5, conf = 0.9, target = "rules")) | |
> summary(rules) | |
#set of 52 rules | |
#rule length distribution (lhs + rhs):sizes | |
# 1 2 3 4 | |
# 2 13 24 13 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.model_selection import GridSearchCV | |
parameters = {'kernel':('linear', 'rbf'), 'C':[1,2,3,4,5,6,7,8,9,10], 'gamma': | |
[0.01,0.02,0.03,0.04,0.05,0.10,0.2,0.3,0.4,0.5]} | |
svr = svm.SVC() | |
grid = GridSearchCV(svr, parameters) | |
grid.fit(X_train, y_train) | |
predicted = grid.predict(X_test) | |
cnf_matrix = confusion_matrix(y_test, predicted) | |
print(cnf_matrix) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(e1071) | |
library(caTools) | |
data(iris) | |
iris$spl=sample.split(iris,SplitRatio=0.7) | |
train=subset(iris, iris$spl==TRUE) | |
test=subset(iris, iris$spl==FALSE) | |
x=train[,-5] | |
y=train[,5] | |
svm_model <- svm(Species ~ ., data=train) | |
table(predict(svm_model, test[,-5]), test[,5]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn import datasets, svm | |
from sklearn.model_selection import train_test_split | |
from sklearn.metrics import confusion_matrix | |
iris = datasets.load_iris() | |
X = iris.data[:, :2] | |
y = iris.target | |
#Split the data into test and train | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0) | |
# Linear Kernel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BufferedInput: | |
def __init__(self): | |
# the buffer holds the content that has be entered by the user but has not been read by into a variable yet | |
self.buffer = '' | |
def getc(self): | |
self.fill_buffer() | |
byte = self.buffer[0] | |
self.buffer = self.buffer[1:] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo add-apt-repository ppa:fkrull/deadsnakes | |
sudo apt-get update | |
sudo apt-get install python3.5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RPi.GPIO as GPIO | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) | |
GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP) | |
while True: | |
if(GPIO.input(23) ==1): | |
print(“Button 1 pressed”) | |
if(GPIO.input(24) == 0): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UngetableInput: | |
def __init__(self, initialBuffer=''): | |
self.buffer = initialBuffer | |
def getc(self): | |
if not self.buffer: | |
self.buffer = input() | |
c = self.buffer[0] | |
self.buffer = self.buffer[1:] | |
return c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from buffer import UngetableInput | |
token_stream = UngetableInput() | |
def expression(): | |
val = None | |
ch = token_stream.getc() | |
while ch == ' ': | |
ch = token_stream.getc() | |
if ch in {'-', '+', '.'} or ch.isdigit(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function expression: | |
token = next_token() | |
if token is one of (-, +, 0-9, .): | |
putback the token | |
val = number() | |
elif token is (: | |
op = operator() | |
exp1 = expression() | |
exp2 = expression() | |
c = next_token() |
NewerOlder