下面这段代码什么意思:for i in range(1,backward+1): df['avgDiff'+str(i)] = df['avgVehicleSpeed'].shift(i-1)/ df['avgVehicleSpeed'].shift(i) - 1 df['avgDiff'+str(i)].replace([np.inf, -np.inf], np.nan,inplace=True) df['avgDiff'+str(i)].fillna(method='bfill') df['flowDiff'+str(i)] = df['vehicleFlowRate'].shift(i-1)/ df['vehicleFlowRate'].shift(i) - 1 df['flowDiff'+str(i)].replace([np.inf, -np.inf], np.nan,inplace=True) df['flowDiff'+str(i)].fillna(method='bfill') df['flowTraffic'+str(i)] = df['trafficConcentration'].shift(i-1)/ df['trafficConcentration'].shift(i) - 1 df['flowTraffic'+str(i)].replace([np.inf, -np.inf], np.nan,inplace=True) df['flowTraffic'+str(i)].fillna(method='bfill') # EWL df['EWMavg']=df['avgVehicleSpeed'].ewm(span=3, adjust=False).mean() df['EWMflow']=df['vehicleFlowRate'].ewm(span=3, adjust=False).mean() df['EWMtraffic']=df['trafficConcentration'].ewm(span=3, adjust=False).mean() return df def generateXYspeed20(df): df['ydiff'] = df['avgVehicleSpeed'].shift(forward)/df['avgVehicleSpeed'] - 1 df['y'] = 0 df.loc[df['ydiff']<-0.2,['y']]=1 df.dropna(inplace=True) y = df['y'] X = df.drop(['y','ydiff'], axis=1) return X , y def generateXYspeedUnder(df): mean = df['avgVehicleSpeed'].mean() df['ydiff'] = df['avgVehicleSpeed'].shift(forward) df['y'] = 0 df.loc[df['ydiff']<mean*0.6,['y']]=1 df.dropna(inplace=True) y = df['y'] X = df.drop(['y','ydiff'], axis=1) return X , y def generateXYspeedAndFlowUnder(df): means = df['avgVehicleSpeed'].mean() meanf = df['vehicleFlowRate'].mean() df['ydiffSpeed'] = df['avgVehicleSpeed'].shift(forward) df['ydiffFlow'] = df['vehicleFlowRate'].shift(forward) df['y'] = 0 df.loc[(df['ydiffSpeed']<means*0.6) &(df['ydiffFlow']<meanf*0.6),['y']]=1 df.dropna(inplace=True) y = df['y'] X = df.drop(['y','ydiffSpeed','ydiffFlow'], axis=1) return X , y def print_metrics(y_true,y_pred): conf_mx = confusion_matrix(y_true,y_pred) print(conf_mx) print (" Accuracy : ", accuracy_score(y_true,y_pred)) print (" Precision : ", precision_score(y_true,y_pred)) print (" Sensitivity : ", recall_score(y_true,y_pred))
时间: 2023-06-04 20:03:42 浏览: 150
Stability in uncertain distribution for backward uncertain differential equations
这段代码是一个循环,它遍历了一个数列,数列的起点是1,终点是backward减1。在循环中,代码对数据框df的不同列进行了操作。首先,代码计算了df['avgVehicleSpeed']列按照向后位移i-1后与向后位移i后的比率的差值,并将其存储到df['avgDiff' str(i)]中。然后,代码将df['avgDiff' str(i)]中的无穷大值和负无穷大值替换成了NaN,并用后一个非NaN值填充缺失的NaN值。接下来,代码对df['vehicleFlowRate']列和df['trafficConcentration']列做了类似的操作。最终,代码将计算得到的结果存储到不同的列中,并返回修改后的数据框df。
阅读全文