regression
8 TopicsRegression Anlysis
Please assist. I want to display a regression analysis for: What proportion of staff are over-utilised (submitting more than their capacity) vs under-utilised (not using their full capacity)? https://drive.google.com/file/d/1w_-i4JvdcYApxtI3QD3MUOE52NYYvcxx/view?usp=sharing487Views0likes1CommentDAX Polynomial Regression Calculation Issue
I am attempting to implement a 2nd order polynomial regression to fit some data. It appears that I can calculate the coefficients for the regression equation correctly, but I just cannot figure out how to correctly return the correct result of the equation to use in a table/chart. Starting from this solution, I ended up with the following measure: values (poly fit) = // Reference: https://www.thedatascientists.com/polynomial-regression/ // https://metric.ma.ic.ac.uk/metric_public/matrices/inverses/inverses2.html // Because our Xs (dates) and Ys (measures) are in different tables, we have to temporarily create a new table (Known) with both of those values so we can perform SUMX operations easily. // To get the same polynomial fit as excel, the x values in the calculation are masked over with 1 thru n. Thus x-values in the calc are n+1-min(n) var countItems = COUNTX(VALUES(Table1[date]),Table1[date]) var Known = SELECTCOLUMNS ( ALLSELECTED(Table1[date]), "KnownX", [zSequence1ToN], "KnownY", CALCULATE(SUMX(Table1,[values])) ) var sumOfXs = SUMX(Known, [KnownX]) var sumOfYs = SUMX(Known, [KnownY]) var sumOfX2 = SUMX(Known, [KnownX] ^ 2) var sumOfX3 = SUMX(Known, [KnownX] ^ 3) var sumOfX4 = SUMX(Known, [KnownX] ^ 4) var sumOfXY = SUMX(Known, [KnownX] * [KnownY]) var sumOfX2Y = SUMX(Known, [KnownX] ^ 2 * [KnownY]) var determinant = countItems*((sumOfX2*sumOfX4)-(sumOfX3*sumOfX3))-sumOfXs*((sumOfXs*sumOfX4)-(sumOfX2*sumOfX3))+sumOfX2*((sumOfXs*sumOfX3)-(sumOfX2*sumOfX2)) //Calculate the inverse matrix (combining a few steps together) var M11 = ((sumOfX2*sumOfX4)-(sumOfX3*sumOfX3))/determinant var M12 = -((sumOfXs*sumOfX4)-(sumOfX3*sumOfX2))/determinant var M13 = -((sumOfX2*sumOfX2)-(sumOfXs*sumOfX3))/determinant //there was an error on this line i had to add a negative to fix. no idea why. EVERY other var evaluates correctly. var M21 = -((sumOfXs*sumOfX4)-(sumOfX2*sumOfX3))/determinant var M22 = ((countItems*sumOfX4)-(sumOfX2*sumOfX2))/determinant var M23 = -((countItems*sumOfX3)-(sumOfXs*sumOfX2))/determinant var M31 = ((sumOfXs*sumOfX3)-(sumOfX2*sumOfX2))/determinant var M32 = -((countItems*sumOfX3)-(sumOfX2*sumOfXs))/determinant var M33 = ((countItems*sumOfX2)-(sumOfXs*sumOfXs))/determinant //Assuming equation of: a*x^2 + b*x + c var c = M11*sumOfYs+M12*sumOfXY+M13*sumOfX2Y var b = M21*sumOfYs+M22*sumOfXY+M23*sumOfX2Y var a = M31*sumOfYs+M32*sumOfXY+M33*sumOfX2Y RETURN // SUMX( // DISTINCT(Table1[date]), // a * [zSequence1ToN] ^ 2 + b * [zSequence1ToN] + c // ) [a]*[zSequence1ToN]^2+[b]*[zSequence1ToN]+[c] Where [zSequence1ToN] is a RANKX of the date values zSequence1ToN = RANKX(ALLSELECTED(Table1[date]),CALCULATE(SUM(Table1[date])),,ASC) My issue is I cannot figure out how to correctly calculate this for each row in the table. The screenshot below is what I am getting (compared to what I should be getting - at least according to excel. I suspect my issue may be where I am returning the values, but at this point I am out of ideas and need advice. I have attached a sample pbix file and the excel file I was using for validation. What am I doing wrong? https://1drv.ms/u/s!Ah3VDq5HnODQgcArelYadi0cXQQZzA?e=8YdvQKSolved6.6KViews0likes8CommentsRegresion lineal multiple R studio Power Bi
Hola, ejecuté un script de r para calcular una regresión lineal multiple. Pude obtener el intercepto y slope y traspasarlos a una tabla utilizando library broom tidy(model). library(broom) model <- lm(Energía_electrica~ Grados + Transacciones,dataset) model <- tidy(model) esta es la base de datos Mes Energía_electrica Grados Transacciones Tienda ene-22 93.471 337 58.567 CD feb-22 82.053 319 51.095 CD mar-22 79.777 295 55.652 CD abr-22 67.907 204 49.633 CD may-22 71.634 185 49.520 CD jun-22 68.864 164 49.280 CD jul-22 69.559 159 50.992 CD ago-22 67.204 161 49.913 CD sept-22 63.007 172 43.913 CD oct-22 65.902 204 48.704 CD nov-22 66.469 256 46.081 CD dic-22 73.164 326 50.385 CD ene-22 132.321 354 66.405 hc feb-22 108.787 313 61.665 hc mar-22 114.572 304 65.195 hc abr-22 94.501 207 56.435 hc may-22 98.740 170 55.612 hc jun-22 87.222 151 52.630 hc jul-22 81.592 123 54.133 hc ago-22 74.998 142 50.118 hc sept-22 67.039 188 43.383 hc oct-22 77.155 212 49.618 hc nov-22 108.387 260 48.931 hc yo necesito calcular la regresión para cada tienda y que la tabla con slope e intercepto me haga una distinción de cual es para cada tienda o que con los filtros los números se actualicen (debo tener slope e intercepto en una tabla porque luego necesito ocupar esos numeros para formulas). Se puede hacer algo como un ciclo for o alguna distinción en esta nueva tabla para filtrar por tienda?1.3KViews0likes3CommentsDynamically select column based on slicer for regression/correlation calculation
Hi, I have approx 400 columns & thousand of rows. All column have numerical value. My Requirement is that, Two slicers which select dynamically two different column that will represent as x & y-axis in regression equation. Basically I need relation between any of two column out of 400 based on slicer selection. Unpivot option has challenge for big data. Also aggregation issue during unpivot. Kindly help to fix it. Thanks in advance.2.7KViews0likes15CommentsPrediction Line
I need to create a prediction line for how the progress bar should look like. (I am using a line and stacked column chart) In my data table I have begin dates and end dates. I need a measure to choose the earliest and latest dates and create a linear line between it. The yellow line is a new column, but it gives back the correct line in overall view. But as I use slicer or filter it doesn't change (as expected). Here is the code for it: Regression = VAR mind = MIN(Data_Table[Begin Date]) VAR maxd = MAX(Data_Table[End Date]) VAR dat = 'Calendar'[Date] VAR dated = DATEDIFF(mind,maxd,DAY) VAR todated = DATEDIFF(dat,maxd,DAY) VAR fromdated = DATEDIFF(mind,dat,DAY) RETURN IF(AND(fromdated>=0,todated>=0),(DIVIDE(todated,dated)-1)*(-1),IF(fromdated<0,0,1)) After this I tried to create the measure for it, but it doesn't work like it. Here is the code: Regression 2 = VAR mind = MIN(Data_Table[Begin Date]) VAR maxd = MAX(Data_Table[End Date]) VAR dat = SELECTEDVALUE('Calendar'[Date]) VAR dated = DATEDIFF(mind,maxd,DAY) VAR todated = DATEDIFF(dat,maxd,DAY) VAR fromdated = DATEDIFF(mind,dat,DAY) RETURN IF(AND(fromdated>=0,todated>=0),(DIVIDE(todated,dated)-1)*(-1),IF(fromdated<0,0,IF(todated<0,1,0))) I don't mind the spikes on the dates where there is no date (missing column), but the slope start later and before that the value is 1 rather 0. Any help with other approaches as well is much appricated it and have a lovely day.750Views0likes3CommentsDynamic Polynomial Regression
Hi, I'm wondering if I can have dynamic polynomial regression within Power BI. Regression would be as such: y = a + bx^3, where y and x are my columns. I would like to plot this regression but have the plot change based on the filter context. This is a time-stamped data, so when I filter for different date ranges, I would like to see the plot change.4.4KViews0likes3CommentsNonlinear Regression
Please would like to draw a nonlinear curve as in the figure below on a scatter plot with a curve that returns the curve's parameters to me. https://www.researchgate.net/figure/Figura-424-Curva-chave-do-posto-fluviomtrico-Monjolo-Fonte-autor-2013_fig5_3271897274.9KViews0likes3CommentsBuilding a Regression Model with zero code in PowerBI
I love using PowerBI for analysis! Recently PowerBI added support for AutoML (Supervised Automated machine Learning) and I wanted to demonstrate the new ML capabilities with an end to end example. In this article, I use AutoML to create and apply a regression model. Regression is a machine learning technique used for understanding the relationship between input and output variables (input is what is known in your data and output is generally the effect of input data and is sometimes unknown). Regression technique gives us more insight into data by making it easier to see relation between dependent and independent variables. These are the five steps I followed in this article to create the Regression model: Refer this tutorial for a detailed walk through of each of these steps, and this tutorial for ones specific to regression models. Creating a dataflow with the input data I created a dataflow using the House Sales prediction dataset from Kaggle. It is also available, at the following link: house sales prediction for purposes of this article. It contains sale prices, number of bedrooms, square footage, number of floors, latitude, longitude etc. of houses in King County (which includes Seattle) sold between May 2014 and May 2015. The Price attribute indicating the price of the house is the numeric field used as label for the Regression model. The dataset was split into two entities HousePrices2014 and HousePrices2015 based on the year attribute. Note that though most of the attribute data types in this dataset are numeric, these may be interpreted as strings by Power Query. So, most of these fields, including the label, were converted to numeric. Training a machine learning model I chose the HousePrices2014 as the entity to apply ML models. Power BI analyzed the Price field and suggested Regression as the type of machine learning model that can be created to predict that field. It took around an impressive 7 minutes to train 12 algorithms on 14 thousand data points. Model validation report After the training refresh completed, I checked out the training report. Key Influencers shows that Latitude, Sqft_living, Grade are the top predictors for the model. To verify this, I plotted a ft_living (square footage of the home) and price. The plot does indeed show a relationship indicating that that higher square feet living indicates higher prices. As shown in the sqft_living breakdown above, 2.7k to 2.9k sqfeet houses has the highest share of range 1 priced houses (72k to 1M). Likewise, a scatterplot between grade (overall grade given to the housing unit, based on King County grading system) and price shows houses with higher grades does have higher prices. The model is 88% performant, which is a pretty great value for this dataset. As you can see in the chart below, most of the test samples lie in the diagonal showing the low error in prediction. The Training Details page shows the performance of the 25 different models, how features were extracted from the inputs, and the hyperparameters for the final model used. AutoML chose an ensemble, Pre fitted Soft Voting Regressor as the best model for this dataset. Applying the model As I was satisfied with the training results, I proceeded to apply the model to the HousePrices2015 entity. A HousePrices2015 enriched RegressionModel was created, which includes the predicted output from the model. Overall, it took only around 2 minutes to score nearly 7 thousand rows! Applying a Regression model added two columns with the Regression outcome, and the top record-specific influencers for each prediction. The HousePrices2015 enriched Regression entity with explanation, predicted prices is shown below along with the actual prices in PowerBI Desktop. The local explanations contains break down of how much each feature moved the specific instance away from the average price of houses. For categorical features, it shows how much price would have changed for different values of the categories. In the highlighted example, you can see that the house price was predicted to be $554174. The explanation says that, "condition", caused the price to increase by 44k from the average price of houses, and that the "latitude" caused the price to fall down by 26k. I established a connection to the dataflow from PBI Desktop, to incorporate these predictions from the model in PBI reports so that I can visualize these results. I plotted a heat map of predicted prices using latitude, longitude. Prices were represented by a red (100% gradient stop) through green (50% gradient stop), to yellow(0% gradient stop) gradient. We can see that, for example, Downtown Seattle and Downtown Bellevue have red regions as expected, owing to high prices. I tried a scikit-learn Random Forest on this same dataset. It took 1 min using 3-fold cross validation, searching across 30 different combinations, using all available cores to give an R2 score of 0.85. Summary Even though AutoML took longer, I am impressed to have gotten a better R2 score of 0.88 by trying not just Random Forest but 25 different models, in addition to getting instance-level explanations. Moreover, AutoML automatically does preprocessing like dropping features like ID with no useful information and generating additional features for datetime like month, year etc. On the other hand, in scikit-learn one must encode string or date-time like features or drop it. Overall, I’m very excited about AutoML, because I did not have to learn the intricacies of the ML models nor worry about the implementation and still get the same results. I have done these in Python and R and it took me considerably longer to code up and setup the hyperparameters, whereas in AutoML I am just hitting a bunch of buttons and voila I am done! Given how much easier it is to get started with lesser effort, I encourage business analysts and even data scientists/analysts to try out AutoML!44KViews23likes2Comments