为什么我会得到这个值错误?ValueError: 发现输入变量的样本数量不一致:[6, 4]

我收到了这个错误:

ValueError: Found input variables with inconsistent numbers of samples: [6, 4]

我的代码:

from sklearn.datasets import load_bostonfrom sklearn.linear_model import LinearRegressionfrom sklearn.model_selection import train_test_splitimport pandas as pdimport matplotlib.pyplot as pltimport numpy as npfrom sklearn.metrics import mean_squared_error , r2_scoredata = load_boston()boston = pd.DataFrame(data.data , columns=data.feature_names)boston.columns = boston.columns.str.lower()boston['medv'] = data['target']x = boston.lstaty = boston.medvx_train, x_test, y_train, y_test = train_test_split(x,y,test_size=0.3,random_state=42)model = LinearRegression()model.fit(x_train,y_train)pred = model.predict(x_test)mean_squared_error('y_test','pred')

回答:

mean_squared_error('y_test','pred')

改为

mean_squared_error(y_test,pred)

您比较的是字符串而不是预测值和标签。此外,您没有分配这个计算出的MSE值,也没有打印它等,您可能需要对这个计算值做些什么。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注