我就廢話不多說啦,直接上代碼吧!
網(wǎng)站建設(shè)哪家好,找成都創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、成都微信小程序、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了長洲免費(fèi)建站歡迎大家使用!target = [1.5, 2.1, 3.3, -4.7, -2.3, 0.75] prediction = [0.5, 1.5, 2.1, -2.2, 0.1, -0.5] error = [] for i in range(len(target)): error.append(target[i] - prediction[i]) print("Errors: ", error) print(error) squaredError = [] absError = [] for val in error: squaredError.append(val * val)#target-prediction之差平方 absError.append(abs(val))#誤差絕對(duì)值 print("Square Error: ", squaredError) print("Absolute Value of Error: ", absError) print("MSE = ", sum(squaredError) / len(squaredError))#均方誤差MSE from math import sqrt print("RMSE = ", sqrt(sum(squaredError) / len(squaredError)))#均方根誤差RMSE print("MAE = ", sum(absError) / len(absError))#平均絕對(duì)誤差MAE targetDeviation = [] targetMean = sum(target) / len(target)#target平均值 for val in target: targetDeviation.append((val - targetMean) * (val - targetMean)) print("Target Variance = ", sum(targetDeviation) / len(targetDeviation))#方差 print("Target Standard Deviation = ", sqrt(sum(targetDeviation) / len(targetDeviation)))#標(biāo)準(zhǔn)差