Skip to content

Instantly share code, notes, and snippets.

View pedroduartecosta's full-sized avatar
🏠
Working from home

Pedro Costa pedroduartecosta

🏠
Working from home
View GitHub Profile
val conf = new SparkConf().setAppName("predictor")
val sc = new SparkContext(conf)
val sqlContext = new SQLContext(sc)
val rawData = sqlContext.read.format("com.databricks.spark.csv")
.option("header", "true")
.option("inferSchema", "true")
.load(dataPath)
.withColumn("DelayOutputVar", col("ArrDelay").cast("double"))
.withColumn("DepDelayDouble", col("DepDelay").cast("double"))
val lr = new LinearRegression()
.setLabelCol("DelayOutputVar")
.setFeaturesCol("features")
val paramGrid = new ParamGridBuilder()
.addGrid(lr.regParam, Array(0.1, 0.01))
.addGrid(lr.fitIntercept)
.addGrid(lr.elasticNetParam, Array(0.0, 1.0))
.build()
val steps:Array[org.apache.spark.ml.PipelineStage] = if(useCategorical){
val categoricalVariables = if(useCategorical){
Array("Origin", "Dest")
}else{
null
}
val categoricalIndexers = if(useCategorical){
categoricalVariables.map(i => new StringIndexer().setInputCol(i).setOutputCol(i+"Index").setHandleInvalid("skip"))
}else{
null
val holdout = model.transform(test).select("prediction", "DelayOutputVar")
val rm = new RegressionMetrics(holdout.rdd.map(x =>
(x(0).asInstanceOf[Double], x(1).asInstanceOf[Double])))
println("sqrt(MSE): " + Math.sqrt(rm.meanSquaredError))
println("mean absolute error: " + rm.meanAbsoluteError)
println("R Squared: " + rm.r2)
println("Explained Variance: " + rm.explainedVariance + "\n")
@pedroduartecosta
pedroduartecosta / cloudSettings
Last active September 16, 2019 19:17
Visual Studio Code Settings Sync Gist
{"lastUpload":"2019-04-22T16:12:57.533Z","extensionVersion":"v3.2.9"}

Keybase proof

I hereby claim:

  • I am pedroduartecosta on github.
  • I am pedroc (https://keybase.io/pedroc) on keybase.
  • I have a public key ASAzPvCsscwUOE487ulXNKdyfk-Vfu-9gwYaWGmGJq1f-wo

To claim this, I am signing this object:

pragma solidity >=0.4.21 <0.6.0;
contract Oracle {
 Request[] requests; //list of requests made to the contract
 uint currentId = 0; //increasing request id
 uint minQuorum = 2; //minimum number of responses to receive before declaring final result
 uint totalOracleCount = 3; // Hardcoded oracle count
}
// defines a general api request
struct Request {
uint id; //request id
string urlToQuery; //API url
string attributeToFetch; //json attribute (key) to retrieve in the response
string agreedValue; //value from key
mapping(uint => string) anwers; //answers provided by the oracles
mapping(address => uint) quorum; //oracles which will query the answer (1=oracle hasn't voted, 2=oracle has voted)
}
function createRequest (
string memory _urlToQuery,
string memory _attributeToFetch
)
public
{
uint lenght = requests.push(Request(currentId, _urlToQuery, _attributeToFetch, ""));
Request storage r = requests[lenght-1];
// Hardcoded oracles address