分類メトリックは、連続ターゲットとマルチクラスターゲットの組み合わせを処理できません



Classification Metrics Cant Handle Mix Continuous



新しく作成したリストを使用して、正確性を個別に比較する項目を保存します。

#Evaluate model def evaluate_model(lin_reg,feature,real_label): ''' This function calculate the accuracy and MSE Error If the (pred year - real year), we suppose it is right. Variables Describe: lin_reg:linear regression model feature: training feature real_lable:ture labels ''' y_pred=list(lin_reg.predict(feature)) y_real=list(real_label) #To avoid 'Classification metrics can't handle a mix of continuous and multiclass targets' Error for_class_pred=list() for_class_real=list() for i in range(len(y_pred)-1): #If the (pred year - real year), we suppose it is right. y_pred[i]=(y_real[i] if abs(y_pred[i]-y_real[i])<=5 else y_pred[i]) for_class_pred.append(int(y_pred[i])) for_class_real.append(int(y_real[i])) acc_score=sklearn.metrics.accuracy_score(for_class_pred,for_class_real) mse_err=sklearn.metrics.mean_squared_error(for_class_pred,for_class_real) return acc_score, mse_err

奇妙な場所で多くの時間が無駄になりました... sklearnのソースコードはそれほど読みやすくありません。