机器学习的新手,我试图找出accuracy score使用线性模型accuracy_score(y_test,y_pred)的定义。但是出现错误“名称'y_test'未定义”。谁能帮我这个?变量的定义如下:X_train, X_test, y_train, y_test = train_test_split(x, y, random_state=123)y_pred = linreg.predict(X_test)详细的错误消息。NameError Traceback(最近一次通话最后一次)在()1中用于检查准确性和详细信息2从sklearn.metrics导入precision_score ----> 3 precision_score(y_test,y_pred)NameError:名称“ y_test”未定义在这里保存代码...#creating a function for modelsfrom sklearn.model_selection import train_test_splitfrom sklearn import metrics#functiondef train_test_rmse(x,y): x = Iris_data[x] y = Iris_data[y] X_train, X_test, y_train, y_test = train_test_split(x, y, test_size = 0.2,random_state=123) linreg = LinearRegression() linreg.fit(X_train, y_train) y_pred = linreg.predict(X_test) return np.sqrt(metrics.mean_squared_error(y_test, y_pred))print(train_test_rmse(['Sepal.Length'],['Sepal.Width']))print(train_test_rmse(['Petal.Length'],['Sepal.Width']))print(train_test_rmse(['Sepal.Length'],['Petal.Width']))print(train_test_rmse(['Petal.Length'],['Petal.Width'])) #this one has least rmseprint(train_test_rmse(['Sepal.Width'],['Sepal.Length']))print(train_test_rmse(['Petal.Width'],['Sepal.Width']))#for checking the accuracy and detailsfrom sklearn.metrics import accuracy_scoreaccuracy_score(y_test,y_pred)
添加回答
举报
0/150
提交
取消