Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
F# 从scikit为F编写多项式特征函数_F#_Scikit Learn_Mathnet Numerics - Fatal编程技术网

F# 从scikit为F编写多项式特征函数

F# 从scikit为F编写多项式特征函数,f#,scikit-learn,mathnet-numerics,F#,Scikit Learn,Mathnet Numerics,我最近开始学习F,我已经了解了fslab for data science,但是我似乎找不到任何类似于Scikit learn中多项式特征的函数 此函数的一个简单示例是 f [x;y] 2 -> [1;x;y;x**2;x*y;y**2] 我想知道是否有人为F编写过类似多项式函数的通用函数,谢谢。我想现在没有多少人使用F。今天,我通过查看scikit learn中的多项式函数源代码找到了答案 然而,F没有Python中的组合或任何等价物,我随后查看了rosetta代码,幸运的是它们的OC

我最近开始学习F,我已经了解了fslab for data science,但是我似乎找不到任何类似于Scikit learn中多项式特征的函数

此函数的一个简单示例是

f [x;y] 2 -> [1;x;y;x**2;x*y;y**2]

我想知道是否有人为F编写过类似多项式函数的通用函数,谢谢。

我想现在没有多少人使用F。今天,我通过查看scikit learn中的多项式函数源代码找到了答案

然而,F没有Python中的组合或任何等价物,我随后查看了rosetta代码,幸运的是它们的OCAML代码与F完全相同,我将它们组合到下面的代码中

let PolyFeature ndgree (x:float list) = 
  let rec combsWithRep xxs k =
    match k, xxs with
    | 0,  _ -> [[]]
    | _, [] -> []
    | k, x::xs ->
        List.map (fun ys -> x::ys) (combsWithRep xxs (k-1))
        @ combsWithRep xs k
  let rec genCombtill n xlen =
      match n with
      | 0 -> List.empty
      | n -> (genCombtill (n-1) xlen) @ combsWithRep [0..(xlen-1)] n
  let rec mulList list1 =
     match list1 with
     | head :: tail -> head * (mulList tail)
     | [] -> 1.0
  let mul2List (b:float list) (a:int list) = [for i in a -> b.[i]] |>   mulList    
  1.0 :: ((genCombtill ndgree x.Length) |> List.map (mul2List x))
试验


代码按预期工作,但是我相信我的代码没有经过优化,并且可能会因为大列表和高阶多项式而变得很慢。

我想现在没有多少人使用F saday,我通过查看scikit learn中的多项式特性源代码找到了答案

然而,F没有Python中的组合或任何等价物,我随后查看了rosetta代码,幸运的是它们的OCAML代码与F完全相同,我将它们组合到下面的代码中

let PolyFeature ndgree (x:float list) = 
  let rec combsWithRep xxs k =
    match k, xxs with
    | 0,  _ -> [[]]
    | _, [] -> []
    | k, x::xs ->
        List.map (fun ys -> x::ys) (combsWithRep xxs (k-1))
        @ combsWithRep xs k
  let rec genCombtill n xlen =
      match n with
      | 0 -> List.empty
      | n -> (genCombtill (n-1) xlen) @ combsWithRep [0..(xlen-1)] n
  let rec mulList list1 =
     match list1 with
     | head :: tail -> head * (mulList tail)
     | [] -> 1.0
  let mul2List (b:float list) (a:int list) = [for i in a -> b.[i]] |>   mulList    
  1.0 :: ((genCombtill ndgree x.Length) |> List.map (mul2List x))
试验

代码工作如预期,但我相信我的代码没有优化,可能会与大列表和高阶多项式缓慢