dotnet / dotnet/machinelearning-samples

Fsx script not working

Open
#985 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
PowerShell
Stars
4.7k
Forks
2.7k
Avg merge
2d 22h
Merged PRs (30d)
1

Description

Is .fsx not supported ?

I can't reproduce the simple demo in F# script , this doesnt seem to work

```fsharp
#r "nuget: Microsoft.ML"

open Microsoft.ML
open Microsoft.ML.Data

[]
type HouseData =
{ [] Size: float32
[] Price: float32 option }

[]
type Prediction =
{ [] Price: float32 }

let mlContext = new MLContext()

// 1. Import or create training data
let houseData = [| { Size = 1.1F; Price = Some(1.2F) };
{ Size = 1.9F; Price = Some(2.3F) };
{ Size = 2.8F; Price = Some(3.0F) };
{ Size = 3.4F; Price = Some(3.7F) } |]
let trainingData = mlContext.Data.LoadFromEnumerable(houseData)

// 2. Specify data preparation and model training pipeline
let pipeline =
EstimatorChain()
.Append(
mlContext.Transforms.Concatenate("Features", [| "Size" |])
)
.Append(
mlContext.Regression.Trainers
.Sdca(labelColumnName = "Price", maximumNumberOfIterations = 100)
)

// 3. Train model
let model = pipeline.Fit(trainingData)

// 4. Make a prediction
let size = { Size = 2.5F ; Price = None }

let predictionFunc =
mlContext.Model.CreatePredictionEngine(model)

let price = predictionFunc.Predict(size)

printfn "Predicted price for size: %f sq ft= %f" (size.Size * 1000.0F) (price.Price * 100.0F)
// Predicted price for size: 2500.0 sq ft= 261.979980

```

here is the error

```
/Users/admin/.packagemanagement/nuget/Projects/54657--8671ee2c-1953-4d65-be3f-818b53cc0f76/Project.fsproj : warning NU1701: Package 'System.Xml.Linq 3.5.21022.801' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework 'net7.0'. This package may not be fully compatible with your project.
/Users/admin/.packagemanagement/nuget/Projects/54657--8671ee2c-1953-4d65-be3f-818b53cc0f76/Project.fsproj : warning NU1701: Package 'System.Xml.Linq 3.5.21022.801' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework 'net7.0'. This package may not be fully compatible with your project.
[Loading /Users/admin/.packagemanagement/nuget/Projects/54657--8671ee2c-1953-4d65-be3f-818b53cc0f76/Project.fsproj.fsx]
module FSI_0015.Project.fsproj

System.ArgumentOutOfRangeException: Could not determine an IDataView type and registered custom types for member Price@ (Parameter 'rawType')
at Microsoft.ML.Data.InternalSchemaDefinition.GetVectorAndItemType(String name, Type rawType, IEnumerable`1 attributes, Boolean& isVector, Type& itemType)
at Microsoft.ML.Data.InternalSchemaDefinition.GetVectorAndItemType(MemberInfo memberInfo, Boolean& isVector, Type& itemType)
at Microsoft.ML.Data.SchemaDefinition.Create(Type userType, Direction direction)
at Microsoft.ML.Data.InternalSchemaDefinition.Create(Type userType, Direction direction)
at Microsoft.ML.Data.DataViewConstructionUtils.CreateFromEnumerable[TRow](IHostEnvironment env, IEnumerable`1 data, SchemaDefinition schemaDefinition)
at Microsoft.ML.DataOperationsCatalog.LoadFromEnumerable[TRow](IEnumerable`1 data, SchemaDefinition schemaDefinition)
at .$FSI_0016.main@() in /Users/admin/Repositories/scripts/mlanonimizer.fsx:line 380
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
Stopped due to error
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.