How to find out the accuracy of each class for BertForSequenceClassification model - bert-language-model

I would like to know if there are methods in BERT that can show the accuracy for each individual class (car brand).
I use the BertForSequenceClassification model, which classifies cars by brand based on a short description. I managed to train the model itself and get the overall accuracy for all classes.

Related

R: What is the difference between the "baseline model" and "unrestricted model" in lavaan model summaries?

Usingsummary(fit.measures = TRUE) I am able to access extensive information about the fit of models stored in lavaan model objects. In this output (exemplified in the accompanying image), several lines compare the user's specified model to two alternative models:
"Baseline Model"
"Unrestricted Model"
I am looking for a somewhat precise explanation of the models implied by each of these terms, since they can mean different things within the structural equation modeling community. Ideally, I would be able to extract the model itself that implied by this term after e.g. using lavaan::cfa().
Currently, the tutorial does not provide any explanation, while the package documentation states the baseline model is "the independence model, assuming all variables are uncorrelated." However, it is not clear what is meant by "all variables" and the example it provides of an independence model on p.79 assumes exogenous various are correlated due to the default settings in lavaan.
Similarly, p.34 of the documentation does not explain what is meant by a "variable" when it notes:
"...the model is defined as the unrestricted model. The following free
parameters are included: all covariances/correlations among the
variables, variances for continuous variables, means for continuous
variables, thresholds for ordered variables, and if exogenous
variables are included (ov.names.x is not empty) while some variables
are ordered, also the regression slopes enter the model"
Not sure this is an appropriate post because it is not about programming. The answers can be found in introductory SEM textbooks.
the independence model, assuming all variables are uncorrelated." However, it is not clear what is meant by "all variables"
All endogenous (or modeled, explained) variables are uncorrelated in the independence model. Exogenous variables are not explained by the model, but instead are taken as given (like in OLS regression). The independence model is used to calculate incremental fit indices (e.g., CFI and TLI; see Bentler & Bonett, 1980, regarding their basic structure). The default baseline.model is independence, but you can fit whatever custom model you want to use (Widamin & Thompson, 2003), which should be nested within your target model(s), and pass it to fitMeasures().
The unrestricted model is on the opposite end of the continuum. Your target model(s) are nested within it because it is saturated, which reproduces your observed means and covariance matrix better than any restricted model could. Thus, it serves as the reference model for the likelihood ratio test of exact model fit (the chi-squared test statistic under Model Test User Model:).
References
Bentler, P. M., & Bonett, D. G. (1980). Significance tests and goodness of fit in the analysis of covariance structures. Psychological Bulletin, 88(3), 588–606. https://doi.org/10.1037/0033-2909.88.3.588
Widaman, K. F., & Thompson, J. S. (2003). On specifying the null model for incremental fit indices in structural equation modeling. Psychological Methods, 8(1), 16–37. https://doi.org/10.1037/1082-989X.8.1.16

It's normal to test model on independent data after cross validation

I want to perform a random forest model, so I split my data into 70% for the train and 30% for the test. I applied a cross validation procedure on my train data (70%) and obtained a precision for the cross validation. After that, I test my model on the test data (30%), then I have another clarification.
So, I want to know if this is a good approach to test the robustness of my model, and what is the interpretation of these two precision.
Thanks in advance.
You do not need to perform Cross-Validation when building a RF model, as RF calculates its own CV score knows as OOB score. In fact, the results that you get from the model (the confusion matrix at model_name$confusion) is based on the OOB scores.
You can use the OOB scores (and the various metrics derived from them, such as Precision, Recall, etc.) to select a model from a list of models (for ex. models with different parameters / arguments) and then use the test data to check if the selected model generalises well.

What is it saved in the model of sklearn bayesian classifier

I believe that a Bayesian classifier is based on statistical model. But after training a Bayesian model, I can save it and do not need the training dataset to predict the test data. For example, if I build a bayesian model by
y - labels,X-samples
Can I take the model as a equation like this?
If so, how can I extract the weights and bias? and what is the new formula looks like?If not, what is the new equation like?
Yes, from the docs, a trained classifier has two attributes, intercept_ and coef_ which are useful if you want to interpret the NBC as a linear model.

identifying key columns/features used by decision tree regression

In Azure ML, I have a predictive regression model using boosted decision tree regression and it is reasonably accurate.
The input dataset has over 450 columns and the model has done a good job of predicting against test data sets, without over-fitting.
To report on the result i need to know what features/columns the model mainly used to make predictions but i cant find this information easily when looking at the trained model data.
How do i identify this information? Im happy to import the result dataset into R to help find this but I just need pointers on what direction to start working in.
Mostly, in using Microsoft Azure Machine Learning, when looking at the features that is mainly used to make predictions, it is found on the output of the Train Model module.
But on using Decision Trees as your algorithm, the output of your Train Model module would be the constructed 'trees' of the algorithm, and it looks like this:
To know the features that made impact on predictions while using Decision Trees algorithms, you can use the Permutation Feature Importance module. Look at the sample experiment below:
The parameters of Permutation Feature Importance are Random Seed and Metric for Measuring Performance (in this case, Regression - Coefficient of Determination)
The left input of Permutation Feature Importance is your trained model, and the right input is your test data.
The output of Permutation Feature Importance looks like this:
You can add Execute R Script to extract the Features and Scores from Permutation Feature Importance module.

Build GBM classification model with customer post-stratification weights

I am attempting to produce a classification model based on the work of qualitative survey data. About 10K of our customers were researched and as a result a segmentation model was built and subsequently each customer categorised into 1 of 8 customer segments. The challenge is to now classify the TOTAL customer base into those segments. As only certain customers responded the researcher used overall demographics to apply post-stratification weights (or frequency weights).
My task is to now use our customer data as explanatory variables on this 10K in order to build a classification model for the whole base.
In order to handle the customer weights I simply duplicated each customer record by each respective frequency weight and the data set exploded to about 72K. I then split this data into train and test and used the R caret package to train a GBM and using the final chosen model classified my hold-out test set.
I was getting 82% accuracy and thought the results were too good to be true. After thinking about it I think the issue is that the model is inadvertently seeing records in train that are exactly the same in test (some records might be exactly duplicated up to 10 times).
I know that the GLM model function allows you to use the weight parameter to refer to a vector of weights but my question is how to utilise other machine learning algorithms, such as GBM or Random Forests, in R?
Thanks
You can use case weights with gbm and train. In general, the list of models in caret that can use case weights is here.

Resources