我是新来的,但有人能告诉我怎么了吗?实际上,我正在尝试根据excel中的数据进行预测分析(线性回归图)。然而,我的图表没有绘制出来,我也面临着这个错误。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import scipy
from sklearn import linear_model
df = pd.read_csv("C:\MongoDB\MongoData.csv")
x_train = np.array(x_train).reshape(len(x_train), -1)
x_train.shape
y_train= [1,2,3,4,5]
x_test = x_test.reshape(-1, 1)
x_test.shape
linear = linear_model.LinearRegression()
linear.fit(x_train, y_train)
linear.score(x_train, y_train)
print('Coefficient: \n', linear.coef_)
print('Intercept: \n', linear.intercept_)
predicted= linear.predict(x_test)
在定义变量之前,需要使用变量
x_train
两次。你需要先定义它,然后再使用它。相关问题 更多 >
编程相关推荐