Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 名称错误:名称';x#U列车';没有定义_Python_Numpy_Matplotlib_Machine Learning_Scikit Learn - Fatal编程技术网

Python 名称错误:名称';x#U列车';没有定义

Python 名称错误:名称';x#U列车';没有定义,python,numpy,matplotlib,machine-learning,scikit-learn,Python,Numpy,Matplotlib,Machine Learning,Scikit Learn,我是新手,但谁能告诉我怎么了?实际上,我正试图根据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.a

我是新手,但谁能告诉我怎么了?实际上,我正试图根据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\u train
两次。您需要先定义它,然后再使用它

  x_train = np.array(x_train).reshape(len(x_train), -1)
# ^^^^^^^            ^^^^^^^              ^^^^^^^
#    |                  |                    |
#    |    +------------------------------------------------+
#    |    | You use x_train twice before it's ever defined |
#    |    +------------------------------------------------+
#  +------------------------------------------+
#  | Your first definition of x_train is here |
#  +------------------------------------------+

在定义变量之前,您使用变量
x\u train
两次。您需要先定义它,然后再使用它

  x_train = np.array(x_train).reshape(len(x_train), -1)
# ^^^^^^^            ^^^^^^^              ^^^^^^^
#    |                  |                    |
#    |    +------------------------------------------------+
#    |    | You use x_train twice before it's ever defined |
#    |    +------------------------------------------------+
#  +------------------------------------------+
#  | Your first definition of x_train is here |
#  +------------------------------------------+

显然,这里
x\u-train=np.数组(x\u-train).重塑(len(x\u-train),-1)
您试图使用
x\u-train
分配中尚未声明的
x\u-train
。在将x_列用作参数之前,不允许丢失x_列声明:
x_列=np.数组(x_列)。重塑(len(x_列),-1)
您错过了第六行和第七行之间的一条线,该线将df拆分为x_列和x_测试。类似于
x\u-train,x\u-test=…
显然,这里
x\u-train=np.array(x\u-train)。重塑(len(x\u-train),-1)
您试图使用
x\u-train
分配中尚未声明的
x\u-train
。在将x_列用作参数之前,不允许丢失x_列声明:
x_列=np.数组(x_列)。重塑(len(x_列),-1)
您错过了第六行和第七行之间的一条线,该线将df拆分为x_列和x_测试。类似于
x\u火车,x\u测试=…