Skip to content

Commit 71ff482

Browse files
authored
Simplify F# demo code (dotnet#760)
* Simplify readme code * Update Program.fs
1 parent 467002a commit 71ff482

File tree

2 files changed

+14
-31
lines changed
  • samples/fsharp/getting-started/BinaryClassification_CreditCardFraudDetection

2 files changed

+14
-31
lines changed

samples/fsharp/getting-started/BinaryClassification_CreditCardFraudDetection/CreditCardFraudDetection/Program.fs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type TransactionFraudPrediction = {
4848
PredictedLabel: bool
4949
Score: float32
5050
Probability: float32
51-
}
51+
}
5252

5353
[<EntryPoint>]
5454
let main _ =
@@ -132,25 +132,17 @@ let main _ =
132132

133133
let pipeline =
134134
EstimatorChain()
135-
|> fun x -> x.Append(mlContext.Transforms.Concatenate("Features", featureColumnNames))
136-
|> fun x -> x.Append(mlContext.Transforms.DropColumns [|"Time"|])
137-
|> fun x ->
138-
x.Append (
139-
mlContext.Transforms.NormalizeMeanVariance (
140-
"FeaturesNormalizedByMeanVar",
141-
"Features"
142-
)
143-
)
144-
|> fun x ->
145-
x.Append (
135+
.Append(mlContext.Transforms.Concatenate("Features", featureColumnNames))
136+
.Append(mlContext.Transforms.DropColumns [|"Time"|])
137+
.Append(mlContext.Transforms.NormalizeMeanVariance("FeaturesNormalizedByMeanVar", "Features"))
138+
.Append (
146139
mlContext.BinaryClassification.Trainers.FastTree(
147140
"Label",
148141
"FeaturesNormalizedByMeanVar",
149142
numberOfLeaves = 20,
150143
numberOfTrees = 100,
151144
minimumExampleCountPerLeaf = 10,
152-
learningRate = 0.2
153-
)
145+
learningRate = 0.2)
154146
)
155147

156148
printfn "Training model"
@@ -179,7 +171,7 @@ let main _ =
179171

180172
printfn "Making predictions"
181173
mlContext.Data.CreateEnumerable<TransactionObservation>(testData, reuseRowObject = false)
182-
|> Seq.filter (fun x -> x.Label = true)
174+
|> Seq.filter (fun x -> x.Label)
183175
// use 5 observations from the test data
184176
|> Seq.take 5
185177
|> Seq.iter (fun testData ->

samples/fsharp/getting-started/BinaryClassification_CreditCardFraudDetection/Readme.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,17 @@ The initial code is similar to the following:
8383
8484
let pipeline =
8585
EstimatorChain()
86-
|> fun x -> x.Append(mlContext.Transforms.Concatenate("Features", featureColumnNames))
87-
|> fun x -> x.Append(mlContext.Transforms.DropColumns [|"Time"|])
88-
|> fun x ->
89-
x.Append (
90-
mlContext.Transforms.NormalizeMeanVariance (
91-
"FeaturesNormalizedByMeanVar",
92-
"Features"
93-
)
94-
)
95-
|> fun x ->
96-
x.Append (
97-
mlContext.BinaryClassification.Trainers.FastTree(
86+
.Append(mlContext.Transforms.Concatenate("Features", featureColumnNames))
87+
.Append(mlContext.Transforms.DropColumns [|"Time"|])
88+
.Append(mlContext.Transforms.NormalizeMeanVariance("FeaturesNormalizedByMeanVar","Features"))
89+
.Append(mlContext.BinaryClassification.Trainers.FastTree(
9890
"Label",
9991
"FeaturesNormalizedByMeanVar",
10092
numberOfLeaves = 20,
10193
numberOfTrees = 100,
10294
minimumExampleCountPerLeaf = 10,
103-
learningRate = 0.2
104-
)
105-
)
95+
learningRate = 0.2)
96+
)
10697
10798
`````
10899

@@ -130,7 +121,7 @@ After the model is trained, you can use the `Predict()` API to predict if a tran
130121
`````fsharp
131122
printfn "Making predictions"
132123
mlContext.Data.CreateEnumerable<TransactionObservation>(testData, reuseRowObject = false)
133-
|> Seq.filter (fun x -> x.Label = true)
124+
|> Seq.filter (fun x -> x.Label)
134125
// use 5 observations from the test data
135126
|> Seq.take 5
136127
|> Seq.iter (fun testData ->

0 commit comments

Comments
 (0)