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)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度