The usage of the least angle regression LARS algorithm package and the selection of model parameters (R language)

question

  When using echart to create a chart, I found that the chart only occupies one corner of the container, as shown in the figure, and it does not fill the container.

  The first reaction is that there is a problem with the style of the container element, so I changed the width and height of the container to px (previously it was set in percentage, and the query data found that the width and height of the echart container should be clearly specified). After modification, it is still the same as The same display as above, still has problems.

position

  So I wonder if there is a problem with the height of the container element obtained when rendering the chart. In the code, I render the chart in the ngAfterViewInit() life cycle, first print out the height of the element to see

  ngAfterViewInit() {
    console.log(document.getElementById('usertotal').clientHeight);
    this.initChart('usertotal');
  }

  It is found that the height of the element is 27 at this time, and there is a problem

  So print out the height of the elements obtained in each life cycle, and get the correct height after the second ContentChecked, but ContentChecked will be called after each content change detection, it is definitely not suitable to initialize the map

solve

  After delaying the initialization of the map in ngAfterViewInit, after adding the delay, it was found that the expected height was obtained.

  In fact, the delay set by setTimeOut is 0, but the height obtained is placed in the event queue. After the task of the main thread is completed, the height is obtained. At this time, the correct height is obtained, and the map can be correctly initialized.

cv.lars(x, y, K = 10, index, trace = FALSE, plot.it = TRUE, se = TRUE,type = c("lasso", "lar", "forward.stagewise", "stepwise"), mode=c("fraction", "step"), ...)

K ----- means that when performing cross-validation, the data is randomly divided into K parts, K-1 of them are used as training data each time, and the remaining one is used for verification, and finally the average value of the K verifications is calculated. square error;

mode ----- Indicates the parameter indicators used, step is to select the required parameters according to the number of steps, fraction is to select the required variables according to the abscissa |beta|/max|beta| in the path, fraction defaults 0:100:1 is index=seq(from=0,to=1,length=100).

Other parameters such as type have the same meanings as in lars(). Let us take the case of type="lar" as an example and use x2 as the independent variable to demonstrate the method of determining the regression parameters. 

First of all, for the convenience of description, we first draw the solution path obtained by this method separately.


Then use lars.cv to determine its parameters, first use the index as mode="step"

[html]  view plain copy  
  1. data(diabetes)  
  2. attach(diabetes www.365soke.cn)  
  3. cvsol1<-cv.lars(www.huayi1.cn x2,y,type="lar",mode="step")  
  4. detach www.yibaoyule1.com/ (diabetes)  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324819271&siteId=291194637