How to plot the tree of a Light GBM .joblib model? - python

I'm very new to Machine Learning! My problem concern a model created with LighGBM. I'm not the creator of this model, so I want to see the tree that this model generates. The model is in the format .joblib, and I want to know as much information as possible of it. On the LighGBMclassifier Documentation i don't find anything that can solve my problem. Thanks to the code below, I only know the number of classes.
model = joblib.load("*.joblib.dat")
model.classes_
Output:
array([0, 1])
I want to know the number of rows, the rules and if it's possible, even the plot of the tree. Thank you all!

When you can not find something in the LightGBM documentation, look for it at XGBoost documentation. LightGBM documentation has loss of missing features that the framework has actually in it.

Related

[flwr][sklearn] Trying to use Gradient Boosted Trees

for some day's now I try to implement gradient boosted tree's with flwr.
I tried the example given by flwr.
They use a LogisticRegression Model for the classification of MNIST, which works in my setup.
This is where my problem arise:
Simply replacing the sklear.linear_model.LogisticRegression model with the sklearn.ensemble.GradientBoostingClassifier does not work because:
I don't know which values I have to initalize, which are equivalent to the LogistiRegression.coef_. Does anyone has an idea?
If I could make a working version I would try to add it to flwr as reference for anybody.
Thanks in advance

How to get CatBoost model's coefficients?

I need to get the parameters to use the model in another program.
I tried cat_model.coef_, cat_model.intercept_ or what I think. is that possible to catch the params ?
I totally solved this problem, what i was tryna do is named 'saving model'.
cat_model.save_model('cat_model.cbm')
Attributes .coef_ and .intercept_ only exist in sklearn applications of linear regression and logistic regression and will give you the slopes and the intercept (if fitted). You can use .feature_importances_ instead.
For catboost, your model has something called feature importances, given that it's a gradient boosting tree model what you get back is how heavy certain features are in splitting the tree up.
cat_model.feature_importances_
will tell you that. Though you should do more research into how the model works and what it will give you back because interpreting these features can be somewhat deceptive.

Election winning Prediction of 5 Candidates using Linear Regression in python

I got one project in which I need to build a prediction model using linear regression in build. The case study is, need to predict winning of 5 candidates in an election. In this, I don't have any data and need to build data on my own but I am not able to visualize parameters. Can anybody help me in data building, it would be highly helpful.
you can start by get previous years election winner as your'e train data, if you don't have any train data , you have a problem in using linear regression (or supervised learning) after that if you want to use python try this step's :
use some code from this tutorial : https://machinelearningmastery.com/machine-learning-in-python-step-by-step/ or any other good beginner tutorial , you can join some comunity like https://www.kaggle.com/ and get some ideas from their kernel regarding to some processing of the data and tuning parameters
As I understand this question, you need to create a model based on data you don't have yet. Presumably you will get the data later on, by which time the model should already be implemented. You can create a fake data set using the numpy.random library. We's need more details on what exactly you're trying to do, though.

Tensorflow (Contrib.learn) KeyError when fitting model

I'm somewhat new to coding and very new to Tensorflow, but I've taken an online machine learning course, so I have some background and an example under my belt.
I am using the Contrib.learn module(?), which puts Tensorflow in a scikit-learn style experience for the user. Anyway, my data set is 20 columns of float64 values, and just over 2000 rows long. Each column is named. I setup my feature_columns with,
feature_columns = []
for i in X_train.columns:
feature_columns.append(tf.contrib.layers.real_valued_column(i, dtype=type(X_train[i][0])))
And then I instantiate my deep neural network model with,
classifier = learn.DNNClassifier(hidden_units=[10,10,10],
feature_columns=feature_columns,
n_classes=2)
So far, so good. Then I try to fit my model with,
classifier.fit(X_train, y_train, steps=100, batch_size=32)
And I get a really deep Trackback that ultimately ends in,
KeyError: 'IQR'
which is the name of my 6th data column.
There isn't a lot of examples of people using Contrib.learn, and I'm guessing the few people who are using it aren't as clueless as I am. If anyone happens to know what it might be referring to, I could really use the help, since I'm basically out of ideas. If you need any more information from me, or if you want me to paste the whole Traceback, just let me know.
Thanks for your time!
edit: Link to Traceback (via Pastebin)
I ended up ditching Contrib.learn and doing it "the hard way" using Tensorflow's core functionality to build a multilayer perceptron.
Pretty cool stuff!
Function throws as it looks for a feature IQR (which is defined in your feature_columns).
In order to use predict you need to do something like:
predicted_values = list(m.predict(input_fn=lambda: input_fn(df_test), as_iterable=False))
Where input_fn is the input function and df_test is Panda's DataFrame with required features
Hope this helps.

Text summarization using deep learning techniques

I am trying to summarize text documents that belong to legal domain.
I am referring to the site deeplearning.net on how to implement the deep learning architectures. I have read quite a few research papers on document summarization (both single document and multidocument) but I am unable to figure to how exactly the summary is generated for each document.
Once the training is done, the network stabilizes during testing phase. So even if I know the set of features (which I have figured out) that are learnt during the training phase, it would be difficult to find out the importance of each feature (because the weight vector of the network is stabilized) during the testing phase where I will be trying to generate summary for each document.
I tried to figure this out for a long time but it's in vain.
If anybody has worked on it or have any idea regarding the same, please give me some pointers. I really appreciate your help. Thank you.
I think you need to be a little more specific. When you say "I am unable to figure to how exactly the summary is generated for each document", do you mean that you don't know how to interpret the learned features, or don't you understand the algorithm? Also, "deep learning techniques" covers a very broad range of models - which one are you actually trying to use?
In the general case, deep learning models do not learn features that are humanly intepretable (albeit, you can of course try to look for correlations between the given inputs and the corresponding activations in the model). So, if that's what you're asking, there really is no good answer. If you're having difficulties understanding the model you're using, I can probably help you :-) Let me know.
this is a blog series that talks in much detail from the very beginning of how text summarization works, recent research uses seq2seq deep learning based models, this blog series begins by explaining this architecture till reaching the newest research approaches
Also this repo collects multiple implementations on building a text summarization model, it runs these models on google colab, and hosts the data on google drive, so no matter how powerful your computer is, you can use google colab which is a free system to train your deep models on
If you like to see the text summarization in action, you can use this free api.
I truly hope this helps

Categories