df = pd.read_csv("..\\dataset\\ecommerce_sample.csv") df[time_axis] = pd.to_datetime(df[time_axis],format = '%d/%m/%Y') #get kpi_axis kpi_axis = 'kpi' time_axis = 'time' y_before = df[df[time_axis] <= '2019-09-11'][kpi_axis] y_after = df[df[time_axis] > '2019-09-11'][kpi_axis] #one-hot encoding categorical features df = binarize(df,df.columns,kpi_axis,time_axis,3) X_before = df[df[time_axis] <= '2019-09-11'].drop([kpi_axis,time_axis],axis = 1).to_numpy() X_after = df[df[time_axis] > '2019-09-11'].drop([kpi_axis,time_axis],axis = 1).to_numpy() #training left and right regression_model_before = LassoCV(cv = 10) regression_model_after = LassoCV(cv = 10) regression_model_before.fit(X_before,y_before) regression_model_after.fit(X_after,y_after) #plotting results features = df.columns dweights =regression_model_after - regression_model_before index = np.argsort(-abs(dweights)) x_axis = features[index[0:3]].to_list() p = figure(x_range=x_axis,title = "Feature weights difference",plot_width=1000) p.vbar(x=x_axis, top=(abs(dweights[index[0:3]])),width = 0.8) show(p)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter