【问题标题】:K-means fails with R in PowerBI NA/NaN/Inf in foreign function call (arg 1)K-means 在外部函数调用中的 PowerBI NA/NaN/Inf 中出现 R 失败(参数 1)
【发布时间】:2016-06-28 18:27:01
【问题描述】:

我正在使用 Iris 数据集并尝试使用基于 k-means 聚类的颜色编码聚类创建 R Script Visual。该脚本在 R-Studio 中运行良好,但在 PowerBI Desktop 中失败。

这是我所做的:

  • 将 Iris 数据集导入为 csv 文件。
  • 创建新的 R 脚本视觉对象
  • 选择特征列(1-4。排除第5列有标签)
  • 使用代码创建 k-means 聚类并绘制颜色

样本数据

5.1, 3.5, 1.4, 0.2, Iris-setosa
4.9, 3,   1.4, 0.2, Iris-setosa
4.7, 3.2, 1.3, 0.2, Iris-setosa
4.6, 3.1, 1.5, 0.2, Iris-setosa
5,   3.6, 1.4, 0.2, Iris-setosa
5.4, 3.9, 1.7, 0.4, Iris-setosa
4.6, 3.4, 1.4, 0.3, Iris-setosa
5,   3.4, 1.5, 0.2, Iris-setosa
4.4, 2.9, 1.4, 0.2, Iris-setosa
...
7,   3.2, 4.7, 1.4, Iris-versicolor
6.4, 3.2, 4.5, 1.5, Iris-versicolor
6.9, 3.1, 4.9, 1.5, Iris-versicolor
5.5, 2.3, 4,   1.3, Iris-versicolor
6.5, 2.8, 4.6, 1.5, Iris-versicolor
...
6.7, 3.3, 5.7, 2.1, Iris-virginica
7.2, 3.2, 6,   1.8, Iris-virginica
6.2, 2.8, 4.8, 1.8, Iris-virginica
6.1, 3,   4.9, 1.8, Iris-virginica
6.4, 2.8, 5.6, 2.1, Iris-virginica
....

代码

# Create dataframe
# dataset <- data.frame(Column1, Column2, Column3, Column4)
# Remove duplicated rows
# dataset <- unique(dataset)

 dataset <- scale(dataset)
 results <- kmeans(dataset, 3)
 plot(dataset[,3:4],  col = results$cluster)

错误:

Error Message:

R script error.
Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)
Calls: kmeans -> do_one
Execution halted


Stack Trace:



Invocation Stack Trace:



Error details
R script error.
Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)
Calls: kmeans -> do_one
Execution halted


Stack trace
Microsoft.PowerBI.ExploreServiceCommon.ScriptHandlerException: R script error.
Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)
Calls: kmeans -> do_one
Execution halted
 ---> Microsoft.PowerBI.Radio.RScriptRuntimeException: R script error.
Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)
Calls: kmeans -> do_one
Execution halted

   at Microsoft.PowerBI.Radio.RScriptWrapper.RunScript(String originalScript, Int32 timeoutMs)
   at Microsoft.PowerBI.Client.Windows.R.RScriptHandler.GenerateVisual(String script, String inputVariableName, IDataReader dataReader, Nullable`1 viewportWidthPx, Nullable`1 viewportHeightPx)
   --- End of inner exception stack trace ---
   at Microsoft.PowerBI.Client.Windows.R.RScriptHandler.GenerateVisual(String script, String inputVariableName, IDataReader dataReader, Nullable`1 viewportWidthPx, Nullable`1 viewportHeightPx)
   at Microsoft.PowerBI.ExploreServiceCommon.ScriptVisualCommandFlow.RunInternal(Stream dataShapeResultStream, QueryBindingDescriptor& bindingDescriptor)
   at Microsoft.PowerBI.ExploreServiceCommon.ScriptVisualCommandFlow.Run(Stream dataShapeResultStream, QueryBindingDescriptor& bindingDescriptor)
   at Microsoft.PowerBI.ExploreHost.SemanticQuery.ExecuteSemanticQueryFlow.TransformDataShapeResult(QueryCommand transformCommand, String dataShapeId, SemanticQueryDataShapeCommand command, Stream dataShapeResultStream, QueryBindingDescriptor& bindingDescriptor)
   at Microsoft.PowerBI.ExploreHost.SemanticQuery.ExecuteSemanticQueryFlow.ProcessAndWriteDataQuery(IQueryResultDataWriter queryResultDataWriter, DataShapeGenerationContext dsqGenContext, DataQuery query, ServiceErrorStatusCode& serviceErrorStatusCode)
   at Microsoft.PowerBI.ExploreHost.SemanticQuery.ExecuteSemanticQueryFlow.ProcessAndWriteSemanticQueryCommands(IQueryResultsWriter queryResultsWriter, ExecuteSemanticQueryRequest request, IConceptualSchema conceptualSchema)

Activity ID
7608d0ca-3ae2-2f75-4cf6-13c4557d903b

Time
Tue Jun 28 2016 10:46:26 GMT-0700 (US Mountain Standard Time)

Version
2.34.4372.501 (PBIDesktop)

注意

如果我过滤第 5 列(标签)上的数据,则 k-means 有效。事实上,我可以过滤每个标签。我只在完整的、未过滤的数据集上得到错误

这是未过滤时的错误

这适用于过滤

【问题讨论】:

    标签: r k-means powerbi


    【解决方案1】:

    原来数据集的最后一行是空行。它没有显示在使用条形图进行过滤的选项中,但是,当我使用切片器时它确实显示了。

    缺失选项

    使用数据

    修复

    我所要做的就是删除空行,它按预期工作

    【讨论】:

      猜你喜欢
      • 2012-09-05
      • 2014-03-28
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-24
      • 1970-01-01
      • 2016-07-27
      相关资源
      最近更新 更多