额,老师,我想把正确率显示出来,结果报错
来源:2-5 多因子线性回归实战
Xmaxdev
2021-11-17
源码
#set up the linear regression model
from sklearn.linear_model import LinearRegression
LR1 = LinearRegression()
#train the model
LR1.fit(X,y)
#calculate the price vs size
y_predict_1 = LR1.predict(X)
print(y_predict_1)
#evaluate the model
from sklearn.metrics import mean_squared_error,r2_score,accuracy_score
mean_squared_error_1 = mean_squared_error(y,y_predict_1)
r2_score_1 = r2_score(y,y_predict_1)
accuracy_score_1 = accuracy_score(y,y_predict_1)
accuracy_score_1
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/var/folders/t0/ql_4wyl17tg2m1qmgf7k62fm0000gn/T/ipykernel_98298/1665350966.py in <module>
3 mean_squared_error_1 = mean_squared_error(y,y_predict_1)
4 r2_score_1 = r2_score(y,y_predict_1)
----> 5 accuracy_score_1 = accuracy_score(y,y_predict_1)
6 # print(y,type(y_predict_1[0]))
7 print(mean_squared_error_1,r2_score_1)
~/opt/miniconda3/lib/python3.8/site-packages/sklearn/metrics/_classification.py in accuracy_score(y_true, y_pred, normalize, sample_weight)
203
204 # Compute accuracy for each possible representation
--> 205 y_type, y_true, y_pred = _check_targets(y_true, y_pred)
206 check_consistent_length(y_true, y_pred, sample_weight)
207 if y_type.startswith("multilabel"):
~/opt/miniconda3/lib/python3.8/site-packages/sklearn/metrics/_classification.py in _check_targets(y_true, y_pred)
102 # No metrics support "multiclass-multioutput" format
103 if y_type not in ["binary", "multiclass", "multilabel-indicator"]:
--> 104 raise ValueError("{0} is not supported".format(y_type))
105
106 if y_type in ["binary", "multiclass"]:
ValueError: continuous is not supported
想看看正确分数,不知道这个问题怎么造成的,类型一样,shape一样,可能我犯了一个低级错误,但是检查不出来,请老师帮忙看一下,谢谢🙏
写回答
1回答
-
flare_zhao
2021-11-17
回归任务没有准确率,准确率是用来衡量分类任务的
022021-11-17