Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.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 Sklearn线性回归与交叉验证返回NA精度分数_Python_Scikit Learn_Linear Regression_Cross Validation - Fatal编程技术网

Python Sklearn线性回归与交叉验证返回NA精度分数

Python Sklearn线性回归与交叉验证返回NA精度分数,python,scikit-learn,linear-regression,cross-validation,Python,Scikit Learn,Linear Regression,Cross Validation,我正在运行一个非常简单的初始线性回归模型,带有基本输入。我有一个小数据集,并已删除了所有空值。我使用交叉验证和通过评分方法,以便能够检索评分以判断拟合不足/过度 然而,我得到了一个零精度:有人知道为什么会发生这种情况吗 X_train, X_test, y_train, y_test = train_test_split(X,y, random_state=42) #Linear Regression lr = linear_model.LinearRegression(fit_interc

我正在运行一个非常简单的初始线性回归模型,带有基本输入。我有一个小数据集,并已删除了所有空值。我使用交叉验证和通过评分方法,以便能够检索评分以判断拟合不足/过度

然而,我得到了一个零精度:有人知道为什么会发生这种情况吗

X_train, X_test, y_train, y_test = train_test_split(X,y, random_state=42)

#Linear Regression

lr = linear_model.LinearRegression(fit_intercept=True)

scores_lr = cross_validate(lr, X_train, y_train, return_train_score = True, scoring = ('r2', 'neg_mean_squared_error'), cv=10)

print 'Training Accuracy: ', np.sqrt(-scores_lr['train_r2'].mean())
print 'Training RMSE: ', np.sqrt(-scores_lr['train_neg_mean_squared_error'].mean())
print 'Validation Accuracy: ', np.sqrt(-scores_lr['test_r2'].mean())
print 'Validation RMSE: ', np.sqrt(-scores_lr['test_neg_mean_squared_error'].mean()) 

Training Accuracy:  nan
Training RMSE:  1.0170113520623867
Validation Accuracy:  nan
Validation RMSE:  1.0230034705533613

您似乎采用了负数的sqrt,结果是一个nan。你想计算什么尺度?准确度通常用于分类问题。它被定义为正确预测的类别占观察总数的比例。由于您使用的是线性回归模型,并且还计算均方根误差,因此您的应用领域似乎是回归(使用连续值)。您尝试采用的sqrt的R2度量是当前模型能够解释的方差分数(一般来说)。它不需要进一步处理