This file contains 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
/* ------------------------------------------------------------------------- | |
* | |
* worker_spi.c | |
* Sample background worker code that demonstrates various coding | |
* patterns: establishing a database connection; starting and committing | |
* transactions; using GUC variables, and heeding SIGHUP to reread | |
* the configuration file; reporting to pg_stat_activity; using the | |
* process latch to sleep and exit in case of postmaster death. | |
* | |
* This code connects to a database, creates a schema and table, and summarizes |
This file contains 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
package org.theplateisbad.consumer; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.PreparedStatement; | |
import java.sql.ResultSet; | |
import java.sql.SQLException; | |
import java.sql.Statement; | |
import java.util.List; | |
import java.util.Timer; |
This file contains 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) | |
data <- seq(1,10) | |
classes <- c('b','b','b','b','a','a','a','a','b','b') | |
mysvm = svm (data, classes, type='C', kernel='radial', gamma=0.1, cost=10) | |
pred = predict (mysvm, data) | |
print(table(pred, classes)) |
This file contains 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
x <- predict(mysvm,c(2)) | |
print(as.character(x[1:1])) | |
[1] "b" | |
x <- predict(mysvm,c(7)) | |
print(as.character(x[1:1])) |
This file contains 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
CREATE OR REPLACE FUNCTION r_predict1(inp integer) | |
RETURNS text AS | |
$BODY$ | |
library(e1071) | |
data <- seq(1,10) | |
classes <- c('b','b','b','b','a','a','a','a','b','b') | |
mysvm = svm (data, classes, type='C', kernel='radial', gamma=0.1, cost=10) | |
result <- predict(mysvm, inp) |
This file contains 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
CREATE OR REPLACE FUNCTION r_predict2(inp integer) | |
RETURNS text AS | |
$BODY$ | |
if (pg.state.firstpass) | |
{ | |
library(e1071) | |
data <- seq(1,10) | |
classes <- c('b','b','b','b','a','a','a','a','b','b') | |
mysvm = svm (data, classes, type='C', kernel='radial', gamma=0.1, cost=10) |
This file contains 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) | |
data <- seq(1,10) | |
classes <- c('b','b','b','b','a','a','a','a','b','b') | |
mysvm = svm (data, classes, type='C', kernel='radial', gamma=0.1, cost=10) | |
saveRDS(mysvm, "mysvm.rds") |
This file contains 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
CREATE OR REPLACE FUNCTION r_predict3(inp integer) | |
RETURNS text AS | |
$BODY$ | |
if (pg.state.firstpass) | |
{ | |
library(e1071) | |
mysvm <- readRDS("mysvm.rds") | |
assign("pg.state.firstpass", FALSE, env=.GlobalEnv) |
This file contains 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
CREATE OR REPLACE FUNCTION r_predict4(inp integer) | |
RETURNS text AS | |
$BODY$ | |
result <- predict(mysvm, inp) | |
return(as.character(result[1:1])) | |
$BODY$ | |
LANGUAGE plr IMMUTABLE STRICT | |
COST 100; |
This file contains 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
CREATE OR REPLACE FUNCTION r_predict5(inp integer[]) | |
RETURNS SETOF text AS | |
$BODY$ | |
if (pg.state.firstpass) | |
{ | |
library(e1071) | |
mysvm <- readRDS("mysvm.rds") | |
assign("pg.state.firstpass", FALSE, env=.GlobalEnv) |
OlderNewer