Skip to content

Commit fe44c2e

Browse files
committed
Merge branch 'main' of github.com:dimwit-dev/dimwit into cicd
2 parents 44551c1 + 5c05ab2 commit fe44c2e

3 files changed

Lines changed: 31 additions & 9 deletions

File tree

build.sbt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ lazy val examples = (project in file("examples"))
4545
libraryDependencies ++= Seq(
4646
"org.scala-lang" %% "toolkit" % "0.1.7",
4747
"dev.scalapy" %% "scalapy-core" % "0.5.3",
48-
"io.github.quafadas" %% "scautable" % "0.0.28",
4948
),
5049
fork := true,
5150
// Don't publish examples

examples/src/main/scala/basic/LogisticRegression.scala

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ object LogisticRegression:
2323
def logits(input: Tensor1[Feature, Float]): Tensor0[Float] = linear(input)
2424
def probits(input: Tensor1[Feature, Float]): Tensor0[Float] = sigmoid(logits(input))
2525
def apply(input: Tensor1[Feature, Float]): Tensor0[Boolean] = logits(input) >= Tensor0(0f)
26-
def main(args: Array[String]): Unit =
2726

28-
import io.github.quafadas.table.*
29-
val df = CSV
30-
.resource("penguins.csv", TypeInferrer.FromAllRows)
31-
.filter(row => !(row.species == 2))
32-
.toSeq
27+
def main(args: Array[String]): Unit =
28+
29+
val df = PenguinCSV.parse("./data/penguins.csv")
30+
.filter(row => row.species != 2)
3331

3432
val dfShuffled = scala.util.Random.shuffle(df)
3533

@@ -41,7 +39,7 @@ object LogisticRegression:
4139
row.body_mass_g.toFloat
4240
)
4341
}.toArray
44-
val labelData = dfShuffled.column["species"].toArray.map {
42+
val labelData = dfShuffled.map(_.species).toArray.map {
4543
case 1 => true
4644
case 0 => false
4745
}
@@ -114,4 +112,29 @@ object LogisticRegression:
114112
println(predictions)
115113
val predictionClasses = trainingData.vmap(Axis[Sample])(x => finalModel(x))
116114

117-
println("\nTraining complete. Optimized parameters:" + finalParams)
115+
println("\nTraining complete. Optimized parameters:" + finalParams)
116+
117+
object PenguinCSV:
118+
case class Row(
119+
species: Int,
120+
bill_length_mm: Double,
121+
bill_depth_mm: Double,
122+
flipper_length_mm: Double,
123+
body_mass_g: Double
124+
)
125+
126+
def parse(path: String): Seq[Row] =
127+
val source = scala.io.Source.fromFile(path)
128+
try
129+
val lines = source.getLines().toSeq
130+
lines.drop(1).map { line =>
131+
val parts = line.split(",")
132+
Row(
133+
species = parts(1).toInt,
134+
bill_length_mm = parts(2).toDouble,
135+
bill_depth_mm = parts(3).toDouble,
136+
flipper_length_mm = parts(4).toDouble,
137+
body_mass_g = parts(5).toDouble
138+
)
139+
}.toSeq
140+
finally source.close()

0 commit comments

Comments
 (0)