dongou2019 2019-07-27 02:56
浏览 241
已采纳

如何通过内部软件包使用统计功能(MannWhitneyUTest)

I am trying to run Mann-Whiteney-U test with following code:

package main
import (
    "fmt"
    "stats" 
)
func main() {
    e, _ = MannWhitneyUTest([]float64{1, 2, 3, 4, 5}, 
                            []float64{1, 2, 3, 5, 6}, 
                            0) 
    fmt.Println("Mann-WhitneyUTest: ", e)
}

However, this gives me this error:

$ go run mainstats2.go 
mainstats2.go:5:2: cannot find package "stats" in any of:
        /usr/local/go/src/stats (from $GOROOT)
        /home/iuser/go/src/stats (from $GOPATH)

I have following stats packages installed:

$ go list all | grep stats
github.com/montanaflynn/stats
github.com/montanaflynn/stats/examples
golang.org/x/perf/internal/stats
golang.org/x/perf/vendor/github.com/aclements/go-moremath/stats
golang.org/x/perf/vendor/google.golang.org/grpc/stats

I need stats package golang.org/x/perf/ which I had installed by command: go get golang.org/x/perf/internal/stats

I believe this package is already there in go installation and was not needed to be installed separately.

How do I solve this problem? Thanks for your help.

  • 写回答

1条回答 默认 最新

  • doubao6464 2019-07-27 03:55
    关注

    The error occurs because your import path is incorrect, it should be:

    import (
        "fmt"
        "golang.org/x/perf/internal/stats" 
    )
    

    But even though import path issue is fixed, you'll get another error for trying to use internal package.

    stats.go:4:5: use of internal package golang.org/x/perf/internal/stats not allowed

    I suggest try to find another alternative library.


    EDIT #1:

    If you insist, there is a workaround. Try to copy the $GOPATH/src/golang.org/x/perf/internal/stats folder directly into your project, then import it. It worked, please see screenshot below.

    enter image description here


    EDIT 2:

    I have copied the folder to ~/go/src/stats. It is still not working. What should I put for import. Currently it is just "stats"

    I think you are doing it wrong. First, you need to create what-so-called project, it's a folder placed inside $GOPATH/src.

    For example in image below I created a project called my-example-app, placed under $GOPATH/src. So the full path of the project will be $GOPATH/src/my-example-app.

    enter image description here

    Inside my project, I created main.go file. This file contains the code (I copied from yours).

    Also, I copied the $GOPATH/src/golang.org/x/perf/internal/stats folder into my project, so the stats folder will be on the same level with my main.go.

    The import of stats folder need to be happen relative to the project name, so the correct import path would be:

    import "my-example-app/stats"
    

    enter image description here

    Here is content of my main.go (copied from yours with some syntax error fix addition).

    package main
    
    import (
        "fmt"
        "my-example-app/stats"
    )
    
    func main() {
        e, _ := stats.MannWhitneyUTest([]float64{1, 2, 3, 4, 5},
            []float64{1, 2, 3, 5, 6},
            0)
        fmt.Println("Mann-WhitneyUTest: ", e)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作