如何测试线性回归模型中的预测值是否与实际值匹配?
我尝试使用 - 混淆矩阵,但出现此错误 -
#==============================================================================
# Create confusion matrix to evaluate performance of data
#==============================================================================
from sklearn.metrics import confusion_matrix
confusionMatrix = confusion_matrix (dv_test, y_pred)
print(confusionMatrix)
ValueError: Can't handle mix of multiclass and continuous
当我执行以下代码时 -
##Performing Linear Regression
from sklearn.linear_model import LinearRegression
from sklearn import model_selection
regressor=LinearRegression()
##Fit train
regressor.fit(iv_train,dv_train)
y_pred=regressor.predict(iv_test)
print('Accuracy of LR',mean_squared_error(y_pred,dv_test))
结果 - LR 7837176694.18 的准确性
这是不正确的。
以下是我的示例数据集 -
longitude latitude housing_median_age total_rooms total_bedrooms population households median_income ocean_proximity median_house_value
-122.23 37.88 41 880 129 322 126 8.3252 NEAR BAY 452600
-122.22 37.86 21 7099 1106 2401 1138 8.3014 NEAR BAY 358500
-122.24 37.85 52 1467 190 496 177 7.2574 NEAR BAY 352100
-122.25 37.85 52 1274 235 558 219 5.6431 NEAR BAY 341300
-122.25 37.85 52 1627 280 565 259 3.8462 NEAR BAY 342200
-122.25 37.85 52 919 213 413 193 4.0368 NEAR BAY 269700
-122.25 37.84 52 2535 489 1094 514 3.6591 NEAR BAY 299200