简体   繁体   English

均方根误差与精度线性回归

[英]Root Mean Squared Error vs Accuracy Linear Regression

I built a simple linear regression model to predict students' final grade using this dataset https://archive.ics.uci.edu/ml/datasets/Student+Performance .我使用此数据集https://archive.ics.uci.edu/ml/datasets/Student+Performance构建了一个简单的线性回归 model 来预测学生的最终成绩。

While my accuracy is very good, the errors seem to be big.虽然我的准确性非常好,但错误似乎很大。

在此处输入图像描述

I'm not sure if I'm just not understanding the meaning of the errors correctly or if I made some errors in my code.我不确定我是否只是没有正确理解错误的含义,或者我是否在代码中犯了一些错误。 I thought for the accuracy of 92, the errors should be way smaller and closer to 0.我认为对于 92 的准确度,误差应该更小,更接近于 0。

Here's my code:这是我的代码:

data = pd.read_csv("/Users/.../student/student-por.csv", sep=";")

X = np.array(data.drop([predict], 1))
y = np.array(data[predict]) 

x_train, x_test, y_train, y_test = sklearn.model_selection.train_test_split(X, y, test_size = 0.1, random_state=42)

linear = linear_model.LinearRegression()

linear.fit(x_train, y_train)

linear_accuracy = round(linear.score(x_test, y_test) , 5)

linear_mean_abs_error = metrics.mean_absolute_error(y_test, linear_prediction)
linear_mean_sq_error = metrics.mean_squared_error(y_test, linear_prediction)
linear_root_mean_sq_error = np.sqrt(metrics.mean_squared_error(y_test, linear_prediction))

Did I make any errors in the code or errors do make sense in this case?我是否在代码中犯了任何错误,或者在这种情况下错误是否有意义?

The accuracy metric in sklearn linear regression is the R^2 metric. sklearn 线性回归中的准确度指标是 R^2 指标。 It essentially tells you the percent of the variation in the dependent variable explained by the model predictors.它基本上告诉您 model 预测变量解释的因变量的变化百分比。 0.92 is a very good score, but it does not mean that your errors will be 0. I looked your work and it seems that you used all the numeric variables as your predictors and your target was G3 . 0.92 是一个很好的分数,但这并不意味着您的错误将为 0。我查看了您的工作,似乎您使用了所有数字变量作为您的预测变量,而您的目标是G3 The code seems fine and the results seem accurate too.代码看起来很好,结果也很准确。 In regression tasks it is really hard to get 0 errors.在回归任务中,很难得到 0 个错误。 Please let me know if you have any questions.请让我知道,如果你有任何问题。 Cheers干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM