请问,如何修复Python代码中的“ValueError:x和y的大小必须相同”?在
代码的思想是从不同的温度传感器和没有数据的情况下应用多元线性回归模型。对模型进行训练,并观察它们之间的相关结果,以及作为一个整体的预测。在
我不确定代码是否能很好地工作,因为我正在学习,对此我知之甚少。如果有人对如何改进代码有任何建议,请也告诉我。在
非常感谢from sklearn import linear_model
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
import pandas as pd
import matplotlib.pyplot as plt
# Name of de file
filename = 'NORM_AC_HAE.csv'
file = 'NORM_NABEL_HAE_lev1.csv'
# Read the data
data=pd.read_csv(filename)
data_other=pd.read_csv(file)
col = ['Aircube.009.0.no.we.aux.ch6', 'Aircube.009.0.sht.temperature.ch1']
X = data.loc[:, col]
Y = data_other.loc[:,'NO.ppb']
# Fitting the Liner Regression to training set
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size = 0.3, train_size = 0.6, random_state = np.random.seed(0))
mlr = LinearRegression()
mlr.fit(X_train, y_train)
# Visualization of the test set results
plt.figure(2)
plt.scatter(y_test, X_test) #The VALUE ERROR appears here
错误代码是:
^{pr2}$