如何使用自定义Lambda分析器保存n元语法模型?

问题描述

我有一个n-gram模型,该模型使用由lambda函数定义的自定义分析器。

#Import of path and target-path
$path = "\\network-path\subfolder\subfolder\subfolder\subfolder\subfolder1\"
$target_path =  "\\network-path\subfolder\subfolder\subfolder\subfolder\subfolder2\"


#endless loop
$a=$true
while($a -eq $true){
    $Files = gci $path
    $TargetFiles = gci $target_path
    
    #wait 5 minutes if path is empty
    if(($Files).Count -eq 0){
        sleep -Seconds 300
    }

    #if path is filled with one or more files
    else {
        #if file in target-path is processed (from another program)
        if(($TargetFiles).count -eq 0){
            #rename and move the latest file
            get-childitem -path $path -Filter "import_*.csv"|
                where-object { -not $_.PSIsContainer } | 
                sort-object -Property $_.CreationTime | 
                select-object -last 1 |
                Rename-Item -NewName {($_.Name.Substring(0,($_.Name.Length)-22))+".csv"} |
                Move-Item -Destination $target_path +"$($_.Name).csv"
        }
         sleep -Seconds 20
    }
}

我尝试使用泡菜保存此模型,但出现以下错误

n=3
vect = CountVectorizer(analyzer=lambda x: (x[-i-1:] for i in range(0,min(n,len(x)))))
vect.fit(df.firstname)

有人可以帮我怎么做吗?除了酸洗以外,还有其他方法可以保存模型吗?

解决方法

Python无法腌制lambda函数,这已经在in this post中进行了解释

一个简单的解决方案是使适当的功能执行相同的操作。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...