Shap interaction plots - shap

I am applying SHAP on XGBoost regressor. I am trying to plot the interaction effects. But the summary plot is displaying only few variables. What to do in case of more than 10 variables?
I tried using "shap.summary_plot(shap_interaction_values, X)" but this is showing only 6 variables whereas I want it to show all the variables in the model which is 16.

Have you tried using the max_display parameter yet?
Documentation: https://shap-lrjball.readthedocs.io/en/latest/generated/shap.summary_plot.html
For example:
shap.summary_plot(shap_interaction_values, X, max_display=20)

Related

Plotting two variables and grouping by classes using 3 different colors and symbols in matlab

I am having a hard time grasping plotting in matlab, when I run this line:
gscatter(wine1.Alcohol,wine1.Ash,wine1.Class,'br','xo')
It shows:
But I obviouly want the third class to be a different color, how can I do that?
So I solved it with this:
gscatter(wine1.Alcohol,wine1.Ash,wine1.Class,'rgb','osd')
which gives me:
Awesome it works!

MATLAB - EEGLAB: surpress GUI for pop_eegfiltnew()

I am working on some scripts for which I use several functions from the EEGLAB package for matlab. Most of these functions make it possible to surpress the GUI from showing, for example using f( ... 'gui','off'), or by using a different version of the same function. However, I can not figure out how to do this for the function pop_eegfiltnew(). Two similar functions are eegfilt(), which seems to be an outdated version of the function, and firfilt() however, pop_eegfiltnew() has more arguments than these other two, so they are certainly not the same in functional terms.
Anyone knows how to get around this?
If you supply enough arguments to pop_eegfiltnew it does not pop up a GUI.
For example if you wanted to filter your signal 1 Hz highpass you would:
EEG = pop_eegfiltnew(EEG, 1, 0);
This is because the first argument of pop_eegfilt is EEG structure, the second is locutoff (lower edge of the passband) and the third is hicutoff (higher edge of the passband).

Control modelica model in dymola, using matlab and command importInitial(dsName="dsfinal.txt")

I want to control from matlab a modelica model implemented in Dymola. At each x-seconds, matlab reads the states values and it calculates the new parameters values of the model and calls dymola to simulate the model with these new parameters values.
I try to initialize the states using the final values of the previous simulation using importInitial(dsName="dsfinal"); and then simulating.
This works if I give the command straight in the simulation log but it doesn't work when I call it from matlab, eventhought exactly the same command appear in the dymola simulation log.
Could any one help?
Thx!
The problem was due to the change of the parameters values.
Using following code solved it:
1) use simulateModel() with all simulation parameters you want for the first simulation
2) use importInitial('dsfinal.txt') to import the final state values
3) use modelName.parameterName = newValue to change parameter value
4) use simulate() to simulate further with the same settings as first simulation.
See also: http://www.claytex.com/how-to-restart-a-simulation/

Generating synthetic data of mixed type (numerical/categorical) in Matlab (or any other)

I'm trying to generate some synthetic data for experiments. When it comes to data sets with numerical features this is rather easy, I just use a Gaussian mixture (using Netlab, a package for Matlab) and that's done.
Noooww, I also need to generate some data sets with numerical and categorical features. The numerical part I can easily do using the above method, what about the categorical?
I was thinking to generate a categorical feature with (say) 3 categories with probabilities of 68.2% (+/- 1 sigma), 27.2% (between +/- 1 sigma and +/- 2 sigma), and 4.6% (the rest) within the objects with the same label.
And perhaps another categorical feature with 5 categories, with probabilities of 34.1%, 34.1%, 13.6%, 13.6%, 4.6% - again, within the objects with the same label.
Does that make sense to you guys? any thoughts?
I can easily write the code for the above, but if you know of any function that does it for me - please let me know.
Thanks!
It's easy to do in Python using numpy:
import numpy as np
np.random.multinomial(n=1, pvals=[.3,.3,.4], size=10)

Modelica: use of der() in a custom class/model

I'm trying to learn Modelica and I have constructed a very simple model using the multibody library. the model consists of a world object and a body (mass) connected to to beams which are then connected to 2 extended PartialOneFrame_a classes (see below) which I modified to create a constant force in one axis. essentially all this group of objects does is fall under gravity and spin around due to the two forces acting at a longituidnal offset from the body center creating a couple about the cg.
model Constant_Force
extends Modelica.Mechanics.MultiBody.Interfaces.PartialOneFrame_a;
parameter Real force = 1.0;
equation
frame_a.f = {0.0,0.0,force};
frame_a.t = {0.0,0.0,0.0};
end Constant_Force;
I next wanted see if I could create a very simple aerodynamic force component which I would connect to the end of one the rotating 'arms'. My idea was to follow the example of the Constant_force model above and for my first simple cut generate forces based on the local frame velocities. This where my problem arose - I tried to compute the velocity using der(frame_a.r_0) which I was then going to transform to local frame using resolve2 function but adding the der(...) line caused the model to not work properly - it would 'successfully' simulate (using OpenModelica) but the v11b vector (see below) would be all zeros, so would der(frame_a.r_0) that appeared for plot plotting - not only that, all the other component behaviors were now also just zero constantly - (frame_a.r_0, w_a etc of the body).
model Aerosurf
extends Modelica.Mechanics.MultiBody.Interfaces.PartialOneFrame_a;
import Modelica.Mechanics.MultiBody.Frames;
import Modelica.SIunits;
//Real[3] v11b;
SIunits.Velocity v11b[3];
//initial equation
// v11b={0.0,0.0,0.0};
algorithm
//v11b:=der(frame_a.r_0);
equation
v11b=der(frame_a.r_0);
frame_a.f = {0.0,0.0,0.0};
frame_a.t = {0.0,0.0,0.0};
end Aerosurf;
I tried a number of ways just to simply compute the velocities (you will see from the commented lines) so i could plot to check correct behavior but to no avail. I used algorithm or equation approach - I did acheive some different (but also incorrect behaviours) with the different approaches.
Any tips? I must be missing something fundamental here, it seems the frame component does not inherently carry the velocity vector so I must have to compute it??
The simplest way is to use the Modelica.Mechanics.MultiBody.Sensors.AbsoluteVelocity block from MSL and connect it to your MB frame, then just use the variable of the output connector in your equation.