Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
user1462
Frequent Visitor

"AIFunctions" ERROR

Hi everyone,

 

I am trying to build a Machine Learning model in Power BI following this tutorial: 
Tutorial: Build a Machine Learning model in Power BI 


I followed exactly the same steps, however now in the end, I cannot refresh my dataflow and this is the error I got:

user1462_0-1670968399207.png

 

 

I really don't know what does it suppose to mean, could you please help me with it?

Thank you very much in advance!

 

Here is the mashup script if you're interested:

---------- Message ----------
DataSource.Error: An error happened while reading data from the provider: 'Could not find a transform with the specified Key 'AutoML.Online Shoppers Intent.Purchase Intent Prediction_Revenue''

---------- Session ID ----------
71f80d70-2875-4c7c-a94d-f4634e59729a

---------- Request ID ----------
38f16f07-6029-45f5-9c60-d6a950328f98

---------- Mashup script ----------
section Section1;
shared #"Online Visitors" = let
Source = Csv.Document(Web.Contents("https://raw.githubusercontent.com/santoshc1/PowerBI-AI-samples/master/Tutorial_AutomatedML/online_shoppers_intention.csv"), [Delimiter = ",", Columns = 18, QuoteStyle = QuoteStyle.None]),
#"Promoted headers" = Table.PromoteHeaders(Source, [PromoteAllScalars = true]),
#"Changed column type" = Table.TransformColumnTypes(#"Promoted headers", {{"Administrative", Int64.Type}, {"Administrative_Duration", type number}, {"Informational", Int64.Type}, {"Informational_Duration", type number}, {"ProductRelated", Int64.Type}, {"ProductRelated_Duration", type number}, {"BounceRates", type number}, {"ExitRates", type number}, {"PageValues", type number}, {"SpecialDay", type number}, {"Month", type text}, {"OperatingSystems", Int64.Type}, {"Browser", Int64.Type}, {"Region", Int64.Type}, {"TrafficType", Int64.Type}, {"VisitorType", type text}, {"Weekend", type logical}, {"Revenue", type text}}),
#"Invoked Online Shoppers Intent.Purchase Intent Prediction_Revenue" = Table.AddColumn(#"Changed column type", "Online Shoppers Intent.Purchase Intent Prediction_Revenue", each #"Online Shoppers Intent.Purchase Intent Prediction_Revenue"([Administrative], [Administrative_Duration], [Informational], [Informational_Duration], [ProductRelated], [ProductRelated_Duration], [BounceRates], [ExitRates], [PageValues], [SpecialDay], [Month], [OperatingSystems], [Region], [TrafficType], [Weekend])),
#"Post process Online Shoppers Intent.Purchase Intent Prediction_Revenue" = AIFunctions.PostProcess(#"Invoked Online Shoppers Intent.Purchase Intent Prediction_Revenue", "Online Shoppers Intent.Purchase Intent Prediction_Revenue", Record.FieldOrDefault(Value.Metadata(#"Online Shoppers Intent.Purchase Intent Prediction_Revenue"), "PostProcessFunctionName", "AutoML.Online Shoppers Intent.Purchase Intent Prediction_Revenue"))
in
#"Post process Online Shoppers Intent.Purchase Intent Prediction_Revenue";
shared #"Purchase Intent Prediction Training Data" = let
Source = #"Online Visitors",
#"Selected columns" = Table.SelectColumns(Source, {"Administrative", "Administrative_Duration", "Informational", "Informational_Duration", "ProductRelated", "ProductRelated_Duration", "BounceRates", "ExitRates", "PageValues", "SpecialDay", "Month", "OperatingSystems", "Region", "TrafficType", "Weekend", "Revenue"}),
#"Removed nulls" = Table.SelectRows(#"Selected columns", each [Revenue] <> null and [Revenue] <> ""),
#"Add conditional column" = Table.AddColumn(#"Removed nulls", "TRUE", each if [Revenue] = "TRUE" then true else false),
#"Changed Type" = Table.TransformColumnTypes(#"Add conditional column", {{"TRUE", type logical}}),
#"Remove column" = Table.RemoveColumns(#"Changed Type", {"Revenue"}),
#"Sampled input Wrapper" = (table) => AI.SampleStratifiedWithHoldout("TRUE", Table.RowCount(table), table),
#"Sampled input" = #"Sampled input Wrapper"(#"Remove column")
in
#"Sampled input";
shared #"Purchase Intent Prediction" = let
Source = #"Purchase Intent Prediction Training Data",
DataflowPrecalculatedSource = PowerBI.Dataflows(),
Workspace = DataflowPrecalculatedSource{[workspaceId = "f5e3b32e-67bf-475b-84bd-0f76617df3b1"]}[Data],
Dataflow = Workspace{[dataflowId = "bd85ae0e-67ee-4a7f-aec8-971194f2951a"]}[Data],
Preview = Dataflow{[entity = "Purchase Intent Prediction"]}[Data],
#"Invoked TrainPrediction Wrapper" = (arguments) => AIFunctions.Contents(){[Key = "AI.Execute"]}[Data]("AI.TrainPredictionWithTimeout", "Regular", arguments),
#"Invoked TrainPrediction" = #"Invoked TrainPrediction Wrapper"([labelColumnName = "TRUE", data = Source, timeout = 30]),
#"Selected training schema columns" = Table.Buffer(Table.SelectColumns(#"Invoked TrainPrediction", {"TrainingId", "Model", "Stats", "GlobalExplanation", "TrainingSchema", "TrainingAUC", "LabelColumn"})),
ModelEntity = if (Table.First(#"Selected training schema columns")[Model]="Unavailable") = true then #"Preview" else #"Selected training schema columns"
in
ModelEntity;
shared #"Purchase Intent Prediction.Score" = let
ApplyScoringFunction = (inputQuery as table, newColumn as text, decisionThreshold as number) => let
MlModel = #"Purchase Intent Prediction",
MlModelJson = try Text.FromBinary(Json.FromValue(MlModel{0})) otherwise "InvalidModel",
IsDefaultResponse = if MlModelJson = "InvalidModel" then true else false,
Source = inputQuery,
SelectedBaseEntityColumns = {"Administrative", "Administrative_Duration", "Informational", "Informational_Duration", "ProductRelated", "ProductRelated_Duration", "BounceRates", "ExitRates", "PageValues", "SpecialDay", "Month", "OperatingSystems", "Region", "TrafficType", "Weekend"},
InputRowCount = Table.RowCount(Source),
InputTableType = Value.Type(Source),
SelectedColumnsTypes = List.Transform(SelectedBaseEntityColumns, each Type.TableColumn(InputTableType, _)),
DefaultRecord = Record.FromList({0,"Unavailable"}, type[PredictionScore = text,PredictionExplanation = text]),
DefaultTable = Table.FromRecords({DefaultRecord}),
ExpandedDefaultTable = Table.Repeat(DefaultTable, InputRowCount),
ScoringFunction =
let
ScoringFunctionScalarType = type function (row as record) as any,
VectorizedScoringFunction = (input as table) =>
let
ExpandedColumns = Table.ExpandRecordColumn(input, "row", SelectedBaseEntityColumns),
ExpandedColumnsWithTypes = Table.TransformColumnTypes(ExpandedColumns, List.Zip({SelectedBaseEntityColumns, SelectedColumnsTypes})),
ErrorList = List.Repeat({[Output = null]}, InputRowCount),
Result = if MlModelJson <> "InvalidModel" then (try Table.ToRecords(AIFunctions.Contents(){[Key = "AI.Execute"]}[Data]("AI.ScorePrediction", "Vectorized", [data = ExpandedColumns, scoreParameters = MlModelJson])) otherwise ErrorList) else ErrorList
in
Result,
ScalarVectorScoringFunction = Function.ScalarVector(ScoringFunctionScalarType, VectorizedScoringFunction)
in
ScalarVectorScoringFunction,
CombinedTablesDefault = Table.NestedJoin(Source, {}, ExpandedDefaultTable, {}, newColumn, JoinKind.FullOuter),
CombinedTablesAI = Table.AddColumn(Source, newColumn, each ScoringFunction(_)),
AddScoringColumn = if IsDefaultResponse = true then CombinedTablesDefault else CombinedTablesAI,
ExpandResultColumns = if IsDefaultResponse = true then Table.ExpandTableColumn(AddScoringColumn, newColumn, {"PredictionScore", "PredictionExplanation"}, {Text.Combine({newColumn, "PredictionScore"}, "."), Text.Combine({newColumn, "PredictionExplanation"}, ".")}) else Table.ExpandRecordColumn(AddScoringColumn, newColumn, {"PredictionScore", "PredictionExplanation"}, {Text.Combine({newColumn, "PredictionScore"}, "."), Text.Combine({newColumn, "PredictionExplanation"}, ".")}),
LabeledOutput = Table.AddColumn(ExpandResultColumns, Text.Combine({newColumn, "Outcome"}, "."), each Record.Field(_, Text.Combine({newColumn, "PredictionScore"}, ".")) >= decisionThreshold * 100),
ReplacedErrors = Table.ReplaceErrorValues(LabeledOutput, {{Text.Combine({newColumn, "Outcome"}, "."), null}, {Text.Combine({newColumn, "PredictionScore"}, "."), null}, {Text.Combine({newColumn, "PredictionExplanation"}, "."), null}}),
TransformTypes = Table.TransformColumnTypes(ReplacedErrors, {{Text.Combine({newColumn, "Outcome"}, "."), type logical}, {Text.Combine({newColumn, "PredictionScore"}, "."), type text}, {Text.Combine({newColumn, "PredictionExplanation"}, "."), type text}})
in
TransformTypes
in
ApplyScoringFunction;
shared #"Purchase Intent Prediction_PollingQuery" = let
Source = "9979dc32-8de8-481c-bdc6-df63deeb945b"
in
Source;
shared #"Purchase Intent Prediction Testing Data" = let
Source = #"Purchase Intent Prediction Training Data",
DataflowPrecalculatedSource = PowerBI.Dataflows(),
Workspace = DataflowPrecalculatedSource{[workspaceId = "f5e3b32e-67bf-475b-84bd-0f76617df3b1"]}[Data],
Dataflow = Workspace{[dataflowId = "bd85ae0e-67ee-4a7f-aec8-971194f2951a"]}[Data],
TestingPreview = Dataflow{[entity = "Purchase Intent Prediction Testing Data"]}[Data],
#"Filtered rows" = Table.SelectRows(Source, each ([__IsTraining__] = false)),
AddExplanationsIndex = Table.AddIndexColumn(#"Filtered rows", Text.Combine({"Purchase Intent PredictionOutput", "ExplanationIndex"}, "."), 1, 1),
#"Invoked Scoring" = #"Purchase Intent Prediction.Score"(AddExplanationsIndex, "Purchase Intent PredictionOutput", 0.5),
#"Test Result" = if (Table.First(#"Invoked Scoring")[#"Purchase Intent PredictionOutput.PredictionExplanation"]="Unavailable") = true then #"TestingPreview" else #"Invoked Scoring"
in
#"Test Result";
shared #"Online Visitors enriched Purchase Intent Prediction" = let
Source = #"Online Visitors",
AddExplanationsIndex = Table.AddIndexColumn(Source, Text.Combine({"Purchase Intent Prediction", "ExplanationIndex"}, "."), 1, 1),
#"Invoked Purchase Intent Prediction.Score" = #"Purchase Intent Prediction.Score"(AddExplanationsIndex, "Purchase Intent Prediction", 0.75),
DataflowPrecalculatedSource = PowerBI.Dataflows(),
Workspace = DataflowPrecalculatedSource{[workspaceId = "f5e3b32e-67bf-475b-84bd-0f76617df3b1"]}[Data],
Dataflow = Workspace{[dataflowId = "bd85ae0e-67ee-4a7f-aec8-971194f2951a"]}[Data],
EnrichedPreview = Dataflow{[entity = "Online Visitors enriched Purchase Intent Prediction"]}[Data],
#"Enriched results" = if (Table.First(#"Invoked Purchase Intent Prediction.Score")[#"Purchase Intent Prediction.PredictionExplanation"]="Unavailable") = true then #"EnrichedPreview" else #"Invoked Purchase Intent Prediction.Score"
in
#"Enriched results";
shared #"Online Visitors enriched Purchase Intent Prediction explanations" = let
Source = #"Online Visitors enriched Purchase Intent Prediction",
OutputColumnName = "Purchase Intent Prediction.",
SelectExplanationColumns = Table.SelectColumns(Source, {Text.Combine({OutputColumnName, "Outcome"}), Text.Combine({OutputColumnName, "PredictionExplanation"}), Text.Combine({OutputColumnName, "ExplanationIndex"})}, MissingField.UseNull),
ParseCsv = Table.TransformColumns(SelectExplanationColumns, {Text.Combine({OutputColumnName, "PredictionExplanation"}), each try Csv.Document(_, {"Field", "Type", "Contribution", "Value", "ExplanationsDisplayText"}, ",") otherwise null}, null, MissingField.UseNull),
ExpandCsv = Table.ExpandTableColumn(ParseCsv, Text.Combine({OutputColumnName, "PredictionExplanation"}), {"Field", "Type", "Contribution", "Value", "ExplanationsDisplayText"}, {"Field", "Type", "Contribution", "Value", "ExplanationsDisplayText"}),
ChangeTypes = Table.TransformColumnTypes(ExpandCsv, {{"Field", type text}, {"Type", type text}, {"Contribution", type text}, {"Value", type text}, {"ExplanationsDisplayText", type text}}),
RemoveErrors = Table.RemoveRowsWithErrors(ChangeTypes, {"Field", "Type", "Contribution", "Value", "ExplanationsDisplayText"}),
RemoveBlank = Table.SelectRows(RemoveErrors, each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(Record.SelectFields(_, {"Field", "Type", "Contribution", "Value", "ExplanationsDisplayText"})), {"", null})))
in
RemoveBlank;
shared #"Online Shoppers Intent.Purchase Intent Prediction_Revenue" = AIFunctions.Contents(){[Key = "AutoML.Online Shoppers Intent.Purchase Intent Prediction_Revenue"]}[Data];

 

2 REPLIES 2
v-xinruzhu-msft
Community Support
Community Support

Hi @user1462 

Did you make some change on your data source?it seems that your data source has some mistakes, maybe you can the key i marked in the picture

vxinruzhumsft_0-1670995484044.png

Best Regards,

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

No actually I didn't make any changes, it was correctly working until the last step of the tutorial, and lastly when I invoke the AutoML models on the workspace and save it, it gives me this error while refreshing the dataflow.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors