小编M W*_*Waz的帖子

RuntimeError:重置参数为False,但没有n_features_in_属性。这个估计器安装了吗?

我正在使用 pickle 保存 sklearn.impute.SimpleImputer 对象。该输入器适合

imputer = SimpleImputer(missing_values = np.nan, strategy = 'mean')
imputer = imputer.fit(train)
Run Code Online (Sandbox Code Playgroud)

然后我保存输入器

pickle.dump(imputer,open('imputer.pkl','wb'))
Run Code Online (Sandbox Code Playgroud)

并使用以下命令将模型加载到烧瓶应用程序中

imputer = pickle.load(open('imputer.pkl','rb'))
Run Code Online (Sandbox Code Playgroud)

如果我检查 imputer.statistics_ ,我可以成功看到应该估算的值。然而,当我跑步时

imputer.transform(test)
Run Code Online (Sandbox Code Playgroud)

在我的烧瓶应用程序中,使用加载了 pickle 的输入器,出现以下错误:

“重置参数为 False,但没有” RuntimeError:重置参数为 False,但没有 n_features_in_ 属性。这个估计器安装了吗?

我正在使用 sklearn 版本 0.23.1 来适应输入器并转换数据。有人对此有任何见解吗?请让我知道我还可以提供哪些其他信息。

python pickle flask scikit-learn

6
推荐指数
1
解决办法
3316
查看次数

如何将本地 .JPG 文件转换为 Base64 以与 Boto3 和 Detect_Text 一起使用?

相关代码:

import boto3
from PIL import Image
import base64

client = boto3.client('rekognition')

filename = r'C:\Users\H-63\Pictures\scantests\Rekognition test.JPG'

with open(filename, 'rb') as image_file:
    image = image_file.read()

image = base64.b64encode(image).decode('UTF-8')

response = client.detect_text(
    Image={'Bytes': image
        })
Run Code Online (Sandbox Code Playgroud)

但是,当我运行它时,出现错误:

An error occurred (InvalidImageFormatException) when calling the DetectText operation: Request has Invalid image format
Run Code Online (Sandbox Code Playgroud)

如何让我的图像成为检测文本的正确格式?文档说它必须是 base64 编码。

python amazon-web-services boto3 amazon-rekognition

5
推荐指数
1
解决办法
2195
查看次数

numpy.polyfit 的额外结果意味着什么?

使用numpy的polyfit创建最佳拟合线时,可以指定参数full为True。除了系数之外,这还会返回 4 个额外值。这些值的含义是什么?它们告诉我该函数与我的数据的拟合程度如何?

https://docs.scipy.org/doc/numpy/reference/ generated/numpy.polyfit.html

我正在做的是:

bestFit = np.polyfit(x_data, y_data, deg=1, full=True)
Run Code Online (Sandbox Code Playgroud)

我得到结果:

(array([ 0.00062008,  0.00328837]), array([ 0.00323329]), 2, array([ 
1.30236506,  0.55122159]), 1.1102230246251565e-15)
Run Code Online (Sandbox Code Playgroud)

文档说这四个额外的信息是:residuals、rank、singular_values 和 rcond。

编辑:我正在寻找有关 rcond 和 Single_values 如何描述拟合优度的进一步解释。

谢谢你!

python numpy scipy linear-regression

2
推荐指数
1
解决办法
2834
查看次数

熊猫写到Excel根据字母顺序重新排列列

我有一个具有格式的python字典

dict = {
        D:""
        B:""
        A:""
        C:""
}
Run Code Online (Sandbox Code Playgroud)

但是,当我将此字典写入excel中的csv文件时,列重新排列为

A B C D
Run Code Online (Sandbox Code Playgroud)

写入Excel时,如何在python中保持字典的顺序?

    writer = pd.ExcelWriter('list_of_detected_words.xlsx', engine='xlsxwriter')
    list_of_detected_words = pd.DataFrame.from_records(form_info)
    list_of_detected_words.to_excel(writer, "Sheet1",startrow=1)
Run Code Online (Sandbox Code Playgroud)

上面是写到excel的代码。

python excel pandas

1
推荐指数
1
解决办法
4464
查看次数