Gradient boosting code example

Example 1: how to insert gradient in css

body{
  /*Radial Gradient*/
  background-image: radial-gradient(#EA52F8 5.66%, #0066FF 94.35%);
  /*Linear Gradient*/
  background-image: linear-gradient(45.34deg, #EA52F8 5.66%, #0066FF 94.35%);
}

Example 2: linear gradient css

/* A gradient tilted 100 degrees,
   starting gray and finishing black */

.class {
    background: linear-gradient(100deg, rgba(63, 63, 63, 0.8) 0%, rgba(255, 255, 255, 0) 25%);
}

/* A gradient going from the bottom to top
   starting red and finishing orange */

.class {
    background: linear-gradient(to top, #f32b60, #ff8f1f);
}

Example 3: Gradient-Boosted Trees (GBTs) learning algorithm for classification

# Gradient-Boosted Trees (GBTs) learning algorithm for classification

from numpy import allclose
from pyspark.ml.linalg import Vectors
from pyspark.ml.feature import StringIndexer
df = spark.createDataFrame([
  (1.0, Vectors.dense(1.0)),
  (0.0, Vectors.sparse(1, [], []))], ["label", "features"])
stringIndexer = StringIndexer(inputCol="label", outputCol="indexed")
si_model = stringIndexer.fit(df)
td = si_model.transform(df)
gbt = GBTClassifier(maxIter=5, maxDepth=2, labelCol="indexed", seed=42)
model = gbt.fit(td)
model.featuresImportances
SparseVector(1, {0: 1.0})
allclose(model.treeWeights, [1.0, 0.1, 0.1, 0.1])
# True
test0 = spark.createDataFrame([Vectors.dense(-1.0),)], ["features"])
model.transform(test0).head().prediction
# 0.0
test1 = spark.createDataFrame([(Vectors.sparse(1, [0], [1.0]),)], ["features"])
model.transform(test1).head().prediction
# 1.0
model.totalNumNodes
# 15
print(model.toDebugString)
# GBTClassificationModel (uid=...)...with 5 trees...
gbtc_path = temp_path + "gbtc"
gbt.save(gbtc_path)
gbt2 = GBTClassifier.load(gbtc_path)
gbt2.getMaxDepth()
# 2
model_path = temp_path + "gbtc_model"
model.save(model_path)
model2 = GBTClassificationModel.load(model_path)
model.featureImportances == model2.featureImportances
# True
model.treeWeights == model2.treeWeights
# True
model.trees
# [DecisionTreeRegressionModel (uid=...) of depth..., DecisionTreeRegressionModel...]

Tags:

Css Example