【发布时间】:2020-03-12 02:43:30
【问题描述】:
我正在学习预测房价的教程。该代码有效,但我试图对一个新的未知数组进行预测,但我不断收到错误。
import pandas as pd
import numpy as np
from sklearn import linear_model
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_boston
boston = load_boston()
reg = linear_model.LinearRegression()
x_train, x_test, y_train, y_test = train_test_split(df_x, df_y, test_size=0.33, random_state=42)
reg.fit(x_train, y_train)
代码有效,但我想测试一个新示例:
X_new = [['15.7','20.5','18.9', '21.7', '20.4', '18.2', '19.9', '23.1', '17.5', '20.2', '18.2',
'13.6', '19.6']]
reg.predict(X_new)
我收到以下错误消息:“UFuncTypeError: ufunc 'matmul' 不包含签名匹配类型的循环 (dtype('dtype('
我不确定我做错了什么。我是否必须将 X_new 更改为字符串列表,或者将它们保留为 numpy 数组?
【问题讨论】:
-
值得将您的
x_test与您的x_new在数据类型和形状方面进行比较。您能否在您的问题中提供一行x_test进行比较? -
x_test.shape (167, 13) X_new [['15.7', '20.5', '18.9', '21.7', '20.4', '18.2', '19.9', '23.1' , '17.5', '20.2', '18.2', '13.6', '19.6']]
-
请根据发布指南提供预期的minimal, reproducible example。
标签: python machine-learning scikit-learn