category
stringclasses
107 values
title
stringlengths
15
179
question_link
stringlengths
59
147
question_body
stringlengths
53
33.8k
answer_html
stringlengths
0
28.8k
__index_level_0__
int64
0
1.58k
imbalanced datasets
Improving accuracy on highly imbalanced dataset
https://datascience.stackexchange.com/questions/49668/improving-accuracy-on-highly-imbalanced-dataset
<p>I need some suggestions to improve my model accuracy.</p> <p>The training data shape is : (166573, 14)</p> <p><a href="https://i.sstatic.net/fFpjX.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/fFpjX.png" alt="train data"></a></p> <p>It has all int and float columns. I have dropped <em>claims_days...
<p>I'm not very sure what you mean by "<em>60% accuracy using AUC</em>". Accuracy and AUC are two different metrics... I'm going to answer as if you're referring to classification accuracy, since that's in your title and the first sentence of your post.</p> <p>First of all, <strong>don't use accuracy to evaluate perfo...
162
imbalanced datasets
Interpretation of evaluation metrics for an imbalanced dataset
https://datascience.stackexchange.com/questions/120685/interpretation-of-evaluation-metrics-for-an-imbalanced-dataset
<p>I am currently dealing with a classification problem for a massively imbalanced dataset. More specifically, it is a fraud detection dataset with around 290k rows of data, with distribution of 99.8% for class 0 (non-frauds) and 0.17% for class 1 (frauds).</p> <p>I have been using XGBoost, Random Forest and LightBGM a...
<p>I am also facing the same issue in the Intrusion Detection System. I found the following suggestions that can be useful:</p> <ul> <li>Reduce the number of datapoints with 0s to reduce the imbalance in dataset - Downsampling.</li> <li>Obtain more data for the minor class (might not be possible, but is one solution)</...
163
imbalanced datasets
Imbalanced dataset in MLP classifier in python
https://datascience.stackexchange.com/questions/19801/imbalanced-dataset-in-mlp-classifier-in-python
<p>I am dealing with imbalanced dataset and I try to make a predictive model using MLP classifier. Unfortunately the algorithm classifies all the observations from test set to class "1" and hence the f1 score and recall values in classification report are 0. Does anyone know how to deal with it?</p> <pre><code>model= ...
<p>You can try using <strong>data re-sampling</strong> techniques. They can be divided in four categories: undersampling the majority class, oversampling the minority class, combining over and under sampling, and creating an ensemble of balanced datasets.</p> <p>The above methods and more are implemented in the <a hre...
164
imbalanced datasets
ROC curve shows strange results for imbalanced dataset
https://datascience.stackexchange.com/questions/24315/roc-curve-shows-strange-results-for-imbalanced-dataset
<p>I have a classifier with a heavily imbalanced dataset (1000 of each negative label for each positive.)</p> <p>I'm running a GradientBoostingClassifier with moderate success (AUC .75) but the curve has this strange look:</p> <p><a href="https://i.sstatic.net/8E0y9.png" rel="nofollow noreferrer"><img src="https://i....
<p>Davis and Goadrich have explained the relationship between ROC and PR Curves in their <a href="http://machinelearning.wustl.edu/mlpapers/paper_files/icml2006_DavisG06.pdf" rel="nofollow noreferrer">paper</a>. It is always recommended to use PR curve over the ROC curve in the presence of highly imbalanced data. </p> ...
165
imbalanced datasets
Imbalanced dataset with 3 classes xgboost scale_pos_weight parameter
https://datascience.stackexchange.com/questions/43376/imbalanced-dataset-with-3-classes-xgboost-scale-pos-weight-parameter
<p>The xgboost classifier states the use of parameter <code>scale_pos_weight</code> for 2-class problems.</p> <p>I have a highly imbalanced dataset with 3 classes. Classes '1' and '-1' are very rare (~1% of dataset) and class '0' is very common. </p> <p>How do I set this <code>scale_pos_weight</code> parameter in the...
<p>For my multiclass classification problem with similar unbalanced data I used the output from sklearn <code>compute_class_weight</code> function:</p> <p><a href="https://scikit-learn.org/stable/modules/generated/sklearn.utils.class_weight.compute_class_weight.html" rel="nofollow noreferrer">https://scikit-learn.org/...
166
imbalanced datasets
If a dataset is imbalanced in real life, should I train on my machine learning model on an imbalanced dataset
https://datascience.stackexchange.com/questions/66839/if-a-dataset-is-imbalanced-in-real-life-should-i-train-on-my-machine-learning-m
<p>I have a dataset where around 20% of the data is the positive class and 80% of the data is the negative class. When I undersample and train my classifier on a balanced dataset and test on a balanced dataset, the results are pretty ok. However, if I train on the balanced dataset and test on an imbalanced dataset that...
<blockquote> <p>When I undersample and train my classifier on a balanced dataset and test on a balanced dataset, the results are pretty ok</p> </blockquote> <p>It's not surprising that the results are good since the job is easier in this case. It's actually a mistake to test on the artificially balanced dataset, sin...
167
imbalanced datasets
How to calculate accuracy of an imbalanced dataset
https://datascience.stackexchange.com/questions/114297/how-to-calculate-accuracy-of-an-imbalanced-dataset
<p>I like to understand what is the accuracy of an imbalanced dataset.</p> <p>Let's suppose we have a medical dataset and we want to predict the disease among the patients. Say, in an existing dataset 95% of patients do not have a disease, and 5% patients have disease. So clearly, it is an imbalanced dataset. Now, assu...
<p>Accuracy is the number of correct predictions out of the number of possible predictions. In many regards, it is like an exam score: you had an opportunity to get <span class="math-container">$100\%$</span> of the points and got <span class="math-container">$97\%$</span> or <span class="math-container">$79\%$</span> ...
168
imbalanced datasets
Imbalanced dataset: how to deal with test data?
https://datascience.stackexchange.com/questions/17873/imbalanced-dataset-how-to-deal-with-test-data
<p>I plan to use many methods to solve the imbalanced dataset problem on the training set. But I couldn't find any paper that describes how they dealt with the test dataset? I assume that they just tested on the original dataset without any adjustments? Will I need to adjust the threshold on the test set with original ...
<p>You should use the testing set without any change, as answered by others. But it is very important to understand the difference between average accuracy and overall accuracy. In overall accuracy you find ( number of samples predicted correctly/ total number of samples) in average accuracy, you find the overall accu...
169
imbalanced datasets
Should I use &quot;sample_weights&quot; on a calibrator if I already used them while training the model (imbalanced dataset)?
https://datascience.stackexchange.com/questions/108427/should-i-use-sample-weights-on-a-calibrator-if-i-already-used-them-while-train
<p>I was wondering what is the right way to proceed when you are dealing with an imbalanced dataset and you want to use a calibrator. When I work with a single model and imbalanced datasets I usually pass &quot;sample_weights&quot; to the model, but I don't know if &quot;sample_weights&quot; should be passed to the cal...
170
imbalanced datasets
Highly Imbalanced dataset fro classes more than 200
https://datascience.stackexchange.com/questions/60936/highly-imbalanced-dataset-fro-classes-more-than-200
<p>I have a <strong>text datase</strong>t where I need to train a classifier to classify the titles into categories. The dataset shape is more than 575000. There are 256 target classes here. The problem is the dataset is highly imbalanced. For target <strong>X1 it has 171793 records, X2 has 101575,........Xn-1 has 2, X...
<p>The situation you describe is a <a href="https://data4thought.com/fewshot_learning_nlp.html#fewshot_learning_nlp" rel="nofollow noreferrer">few-shot learning problem</a>: you have a lot of classes and only a few examples for some of them.</p> <p>Similarity metric learning with siamese neural networks is well suited...
171
imbalanced datasets
Imbalanced dataset - Undersampling &amp; multiple classifiers
https://datascience.stackexchange.com/questions/61814/imbalanced-dataset-undersampling-multiple-classifiers
<p>Let's suppose that my dataset in a classification problem looks like that:</p> <ol> <li>class A: 50000 observations</li> <li>class B: 2000 observations</li> <li>class C: 800 observations</li> <li>class D: 200 observations</li> </ol> <p>These are some ways which I considered to deal with this imbalanced dataset:</p...
<p>Maybe your (3) can be complemented to an oversampling of the other classes. I don't think every oversampling generates overfitting. I agree with you, it will make you lose information. But the only way to know if it's that bad is by checking it.</p> <p>Regarding (4), I don't see how you'll manage the predictions of...
172
imbalanced datasets
ZeroR as baseline for balanced / imbalanced datasets
https://datascience.stackexchange.com/questions/24787/zeror-as-baseline-for-balanced-imbalanced-datasets
<p>I have a dataset containing thousands of text posts. I am building a binary classifier that will classify posts as <strong>safe (0)</strong> or <strong>risky (1)</strong>. I randomly picked some of them and manually labeled. Label 1 is minority.</p> <p>Imbalanced data results in skewed performance. To overcome thi...
<p>You should only undersample the data that is used for training. Test data should represent the true distribution.</p> <p>Then you have at least two possible baselines. One is ZeroR (your second point), which always predicts the majority class. Given a true distribution of (0) 10% and (1) 90%, this would give you a ...
173
imbalanced datasets
imbalanced target dataset(multi class)
https://datascience.stackexchange.com/questions/67312/imbalanced-target-datasetmulti-class
<p>I have a multi-class prediction problem<br/> but the 300classes is imbalanced <br/> should I make it balance all 300 class will predict the better result? <br/> is there an easier method to do this job?<br/> if I'm using the random-forest imbalance dataset is matter?</p>
<p>Nothing better if you could get more data and make classes (at least close to) balanced!</p> <p>Choice of algorithm (I believe you using only RFC) entirely depends upon problem statement and as we all know, there is no free lunch in statistics, so you might've to try other algorithms (or just create a pipeline tryi...
174
imbalanced datasets
GridSearch on imbalanced datasets
https://datascience.stackexchange.com/questions/89428/gridsearch-on-imbalanced-datasets
<p>Im trying to use gridsearch to find the best parameter for my model. Knowing that I have to implement nearmiss undersampling method while doing cross validation, should I fit my gridsearch on my undersampled dataset (no matter which under sampling techniques) or on my entire training data (whole dataset) before usin...
<p><strong>Do grid search on the same Level of &quot;imbalancedeness&quot; that you plan/are able to do your Training and Evaluation on.</strong></p> <p>So that means that if you saw that imbalanced data set does not skew your model predictions or results in other unwanted Outcomes, done use the maximal dataset possibl...
175
imbalanced datasets
Improving classifier performances in R for imbalanced dataset
https://datascience.stackexchange.com/questions/18295/improving-classifier-performances-in-r-for-imbalanced-dataset
<p>I have used an "adabag"(boosting + bagging) model on an imbalanced dataset (6% positive), I have tried to maximized the sensitivity while keeping the accuracy above 70% and the best results I got were: </p> <ul> <li>ROC= 0.711 </li> <li>SENS=0.94 </li> <li>SPEC=0.21</li> </ul> <p>The results aren't Inhofe, especia...
<p>You should try compensating for the imbalanced data and then can you try a lot of different classifiers. Either balance it out, use SMOTE to interpolate (this always struck me as too magical), or assign weights.</p> <p>Here's a nice article walking through it with caret, which is what it appears you're using:</p> ...
176
imbalanced datasets
Will oversampling help with generalization (small imbalanced dataset)?
https://datascience.stackexchange.com/questions/66779/will-oversampling-help-with-generalization-small-imbalanced-dataset
<p>I have an imbalanced dataset (2:1 ratio) with about 60 patients and 80 features.</p> <p>I performed Recursive Feature Elimination (RFE) and stratified cross validation to reduce the features to 15 and I get an AUC of 0.9 with Logistic regression and/or SVM. I don't fully trust the AUC I got because I think it will n...
<p>The bigger issue might be the small <code>n</code>. With 60 samples and 2:1 ratio, you only have 20 samples in the minority class. Generalization, no matter what machine learning technique is used, will be limited with just 20 samples.</p>
177
imbalanced datasets
Training model on a Balanced vs Imbalanced dataset?
https://datascience.stackexchange.com/questions/64706/training-model-on-a-balanced-vs-imbalanced-dataset
<p>Let's say that I have a 2-class classification problem where classes <code>A &amp; B</code> have <code>10*N</code> and <code>N</code> observations respectively.</p> <p>I am pretty sure that the answer to my question depends on the specific classification problem and on the features of my dataset etc.. Still there a...
<p>It's an interesting problem, but I think the answer might be disappointing:</p> <p>Usually problems about maximizing recall are considered in the context of a trade-off with precision, i.e. the goal is to sacrifice some precision by predicting more positives, whether true (TP) or false (FP). Usually in a binary pro...
178
imbalanced datasets
How to increase the accuracy of an imbalanced dataset (not precision)?
https://datascience.stackexchange.com/questions/98213/how-to-increase-the-accuracy-of-an-imbalanced-dataset-not-precision
<p>There's an imbalanced dataset in a Kaggle competition I'm trying. The target variable of the dataset is binary and it is biased towards 0. 0 - 70% 1 - 30% I tried several machine learning algorithms like Logistic Regression, Random Forest, Decision Trees etc. But all of them give an accuracy around 70%. It seems tha...
<p>Following your comment, I'll detail here (too long for comments basically)</p> <p>Acuracy may not be a good way to measure your model's performance. Imagine a problem with 99 '0' and 1 '1'. A model always gessing '0' will have 99% accuracy, and is useless, since you want to detect the '1'. A model giving you 10 '1' ...
179
imbalanced datasets
Text classification of an imbalanced dataset
https://datascience.stackexchange.com/questions/78400/text-classification-of-an-imbalanced-dataset
<p><a href="https://i.sstatic.net/5yOLt.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/5yOLt.png" alt="class distribution looks like this" /></a><a href="https://i.sstatic.net/4VseP.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4VseP.png" alt="this is how the dataset looks like" /></a>I...
180
imbalanced datasets
How much data augmentation is required on an imbalanced dataset?
https://datascience.stackexchange.com/questions/102181/how-much-data-augmentation-is-required-on-an-imbalanced-dataset
<p>Imagine I have a dataset with positive and negative sentences, and I need to train a transformer (Like BERT) to do the binary classification. The problem is that there are 100 negative sentences and 2000 positive sentences. There are libraries for NLP data augmentation like this one: <a href="https://github.com/makc...
<p>There is nothing wrong with an imbalanced training dataset. It's possible that no changes are required.</p> <p>When your training set is highly imbalanced like this, models in early training stages will predict everything to be the most prevalent class (positive in this case). After a longer training period, usually...
181
imbalanced datasets
Binary classification with imbalanced dataset, about lightgbm output probability distribution
https://datascience.stackexchange.com/questions/102129/binary-classification-with-imbalanced-dataset-about-lightgbm-output-probability
<p>I trained a binary classifier for an imbalanced dataset. I did two experiments:</p> <ol> <li><strong>lightgbm classifier, boosting_type='gbdt', objective='cross_entropy', SMOTE upsample</strong></li> </ol> <p>After training the lgbm model, I made predictions on validation dataset. I plotted the probability distribut...
182
imbalanced datasets
imbalanced dataset in text classififaction
https://datascience.stackexchange.com/questions/45163/imbalanced-dataset-in-text-classififaction
<p>I have a data set collected from Facebook consists of 10 class, each class have 2500 posts, but when count number of unique words in each class, they has different count as shown in the figure <a href="https://i.sstatic.net/eUIMX.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/eUIMX.png" alt="word cou...
<p>Thank you for your message Ahmed. There are things to point out:</p> <ol> <li><em>Is this an imbalanced problem?</em> Which problem? <strong>THIS</strong> is not a problem. This is data.</li> <li>What analysis is going to be done? In some cases you need posts and in some you need these keywords. </li> <li>What meth...
183
imbalanced datasets
class weights formula for imbalanced dataset
https://datascience.stackexchange.com/questions/93873/class-weights-formula-for-imbalanced-dataset
<p>I am trying to make some semantic segmentation. I have 7 imbalanced classes in my case. I found several methods for handling Class Imbalance in a dataset is to perform Undersampling for the Majority Classes or Oversampling for the minority classes. but the most used one is introducing weights in the Loss Function. A...
<p>I really don't suggest Under/Oversampling as it would change the distribution of dataset. we should consider distribution as a useful feature of dataset. so I think the weighted loss would have better performance in most cases. if you're using TF/Keras, <a href="https://www.tensorflow.org/tutorials/structured_data/i...
184
imbalanced datasets
Handling Imbalanced Datasets in Orange
https://datascience.stackexchange.com/questions/89726/handling-imbalanced-datasets-in-orange
<p>I work in the medical domain, so class imbalance is the rule and not the exception. While I know Python has packages for class imbalance, I don't see an option in Orange for e.g. a SMOTE widget. I have read other threads in Stack Exchange regarding this, but I have not found an answer to how to tackle class imbalanc...
<p>You can add <code>class_weights</code> with dictionary containing class weights, e.g.:</p> <pre><code>class_weight = {0: 1., 1: 20.} </code></pre> <p>While <code>SMOTE</code> can be used to synthesize new examples for the minority class (the process is called oversampling) in order to get equal weights.</p> <p>For ...
185
imbalanced datasets
Imbalanced class in my dataset
https://datascience.stackexchange.com/questions/130596/imbalanced-class-in-my-dataset
<p>I’m working with an imbalanced dataset to predict strokes, where the positive class (stroke occurrence) is significantly underrepresented. Initially, I used logistic regression, but due to the class imbalance, I switched to a Random Forest model. After applying techniques such as random oversampling and adjusting th...
<p>You can generally try:</p> <ul> <li>using a metric that takes the imbalance into account</li> <li>class weights</li> <li>better algorithms (gbdts)</li> <li>tunning the prediction threshold or using continuous prediction directly</li> </ul>
186
imbalanced datasets
Understanding the `model.fit` function in keras and imbalanced datasets
https://datascience.stackexchange.com/questions/130193/understanding-the-model-fit-function-in-keras-and-imbalanced-datasets
<p>As an exercise, I'm trying to translate a model written in Keras (<a href="https://github.com/CVxTz/ECG_Heartbeat_Classification/blob/master/code/baseline_mitbih.py" rel="nofollow noreferrer">https://github.com/CVxTz/ECG_Heartbeat_Classification/blob/master/code/baseline_mitbih.py</a>) into Pytorch code. I realize i...
187
imbalanced datasets
Around how much difference between two classes can be accounted as an imbalanced dataset?
https://datascience.stackexchange.com/questions/53923/around-how-much-difference-between-two-classes-can-be-accounted-as-an-imbalanced
<p>I am building a binary classification model which has 17K values as class A and 10K values as class B. I want to know when a dataset can face the issues of "IMBALANCED Dataset" ?</p>
<p>In general there will be not a hard rule about this, but this dataset seems to be like balanced. The point about disbalanced is that you have to keep in mind that the accuracy of your model will have a different starting point. For this python has the function to run a baseline with dummy classification. <a href="ht...
188
imbalanced datasets
F1 maximization with convolutional neural net. for an imbalanced dataset
https://datascience.stackexchange.com/questions/15795/f1-maximization-with-convolutional-neural-net-for-an-imbalanced-dataset
<p>I'm dealing with an imbalanced dataset for binary classification (about 70% to 30%). I was wondering what is the best way to optimize the F1 score for such a task when using a convolutional neural net.</p> <p>As of now, I'm sampling the dataset in order to create a balanced training set and am using the mean of sof...
<p>I have <a href="http://pong.inescporto.pt/~rpcruz/ijcnn2016/imbalance.pdf" rel="nofollow noreferrer">a paper</a> where we try to maximize F1 score by using different techniques. We hoped that a ranking algorithm like RankNet would be able to get better F1 score than the others. But as you can see looking at our tabl...
189
imbalanced datasets
In which situation should we consider a dataset as imbalanced?
https://datascience.stackexchange.com/questions/87933/in-which-situation-should-we-consider-a-dataset-as-imbalanced
<p>I'm facing a problem about making a classification on a dataset. The target variable is binary (with 2 classes, 0 and 1). I have 8,161 samples in the training dataset. And for each class, I have:</p> <ul> <li>class 0: 6,008 samples, 73.6% of total numbers.</li> <li>class 1: 2,153 samples, 26.4%</li> </ul> <p>My ques...
<p>Intuitively, it seems like an imbalanced dataset to have ~75/25 ratio of class labels.</p> <p>If you want to take a look at it theoretically, you can do a hypothesis test. For a sample size of 8161, you can assume that the dataset is 50/50 as null hypothesis and then compute the probability that a number extreme as ...
190
imbalanced datasets
Choice of f1 score for highly imbalanced dataset?
https://datascience.stackexchange.com/questions/58008/choice-of-f1-score-for-highly-imbalanced-dataset
<p>I am confused whether to use f1 score with 'micro' average or 'macro' average for better evaluation. Given my dataset is highly imbalanced(600:100000)</p>
<p>To summarise this <a href="https://datascience.stackexchange.com/questions/15989/micro-average-vs-macro-average-performance-in-a-multiclass-classification-settin">answer</a>,</p> <p>Macro calculates and F1 score for each class then averages them.</p> <p>Micro calculates the recall/precision for each class, average...
191
imbalanced datasets
Binary classification problem with imbalanced dataset, how to compare to random classifier
https://datascience.stackexchange.com/questions/70155/binary-classification-problem-with-imbalanced-dataset-how-to-compare-to-random
<p>We have a very imbalanced dataset (2% of class 1). To the best of our knowledge, there is no baseline in the literature to the problem we want to solve - so we thought of comparing our performance to a random classifier. We evaluate our model as a combination of precision and recall - we vary the threshold at which ...
<p>You have <span class="math-container">$98\%$</span> in one class, right? This means that, knowing nothing about the data, you should be able to get <span class="math-container">$98\%$</span> of them right by guessing that majority class. If you get <span class="math-container">$97\%$</span> of them right, that sound...
192
imbalanced datasets
Problem: Logistic Regression vs. Tree-based Model Performance on Small Imbalanced Dataset
https://datascience.stackexchange.com/questions/130738/problem-logistic-regression-vs-tree-based-model-performance-on-small-imbalance
<p>I have a small dataset with 300 rows and an imbalanced class distribution (35% positives). When I fit a logistic regression model, it consistently performs worse than random chance. I’m using stratified cross-validation to evaluate performance, but I’ve noticed a significant variance in results depending on the data...
<p>Tree-based models tends to overfit on any data which is accessible. LR can generalise better. It's not always possible to achive good model score in real life (not Kaggle competition). Sometimes it's better to have worse score, but more consistent across different parts of data.</p> <p>You can use regularisation. Or...
193
imbalanced datasets
Data Augmentation techniques for classification of imbalanced time series datasets
https://datascience.stackexchange.com/questions/62838/data-augmentation-techniques-for-classification-of-imbalanced-time-series-datase
<p>Now I have a task to classify the imbalanced time series datasets using ML classifiers, such as Logistic Regression, Decision Tree, SVM, and KNN. I am not allowed to use the Deep Learning tools, such as CNN and RNN. The time series data is measurements of the Force-Displacement Curve from a production line. The data...
194
imbalanced datasets
Low F1-Score due to Imbalanced Dataset even after resampling
https://datascience.stackexchange.com/questions/112720/low-f1-score-due-to-imbalanced-dataset-even-after-resampling
<p>I am performing a Binary Classification over an <strong>imbalanced dataset</strong>:<br /> 0: 16,263<br /> 1: 214</p> <p>I have used multiple oversampling, undersampling, and combination techniques, below are the results that I have obtained: I obtained this plots thanks to this piece of code:</p> <pre><code>def plo...
195
imbalanced datasets
How to find whether a dataset is blanced or imbalanced?
https://datascience.stackexchange.com/questions/61657/how-to-find-whether-a-dataset-is-blanced-or-imbalanced
<p>I have few dataset to experiment classification(Multi-class). These datasets are about 400GB. I wanted to know whether the dataset is balanced or imbalanced. How to know that dataset is balance or imbalanced using any scientific way?</p>
<p>Typically, the representation of each class in a multi-classification problem should be equal. Say if there are 4 classes, then the ratio of count of samples in each class should ideally be n:n:n:n, most classification data sets do not have exactly same number of sample count in each class, which is fine and a lit b...
196
imbalanced datasets
Explaining the logic behind the pipe_line method for cross-validation of imbalance datasets
https://datascience.stackexchange.com/questions/106613/explaining-the-logic-behind-the-pipe-line-method-for-cross-validation-of-imbalan
<p>Reading the following article: <a href="https://kiwidamien.github.io/how-to-do-cross-validation-when-upsampling-data.html" rel="nofollow noreferrer">https://kiwidamien.github.io/how-to-do-cross-validation-when-upsampling-data.html</a></p> <p>There is an explanation of how to use <code>from imblearn.pipeline import m...
<p>The page linked already gives a really good explanation:</p> <blockquote> <p>To see why this is an issue, consider the simplest method of over-sampling (namely, copying the data point). Let's say every data point from the minority class is copied 6 times before making the splits. If we did a 3-fold validation, each ...
197
imbalanced datasets
Hypertune xgboost to dealing with imbalanced dataset
https://datascience.stackexchange.com/questions/90015/hypertune-xgboost-to-dealing-with-imbalanced-dataset
<p>My training data has extremely <strong>class imbalanced</strong> {0:872525,1:3335} with 100 features. I use xgboost to build classification model with bayessian optimisation to hypertune the model in range <code>{learning rate:(0.001,0.1), min_split_loss:(0.10), max_depth:(3,70), min_child_weight:(1:20), max_delta_s...
<p>Given an imbalanced dataset and focusing on <strong>increasing your true positive rate</strong>, it is quite relevant to use the right <strong>evaluation metric</strong> (the one used to validate the model being trained on each evaluation round).</p> <p>In this case, I recommend you use <strong>Precision-Recall AUC ...
198
imbalanced datasets
Features selection in imbalanced dataset
https://datascience.stackexchange.com/questions/89073/features-selection-in-imbalanced-dataset
<p>I have some doubts regarding an analysis. I have a dataset with class imbalance. I am trying to investigate some information from that data, e.g., how many urls contain http or https protocols. My results are as follows:</p> <pre><code>http in dataset with class 1: 10 http in dataset with class 0: 109 https in datas...
<p>What this shows is that the protocol is not a very discriminative feature:</p> <ul> <li>the probability of class 1 given http is 10/(109+10)=0.084</li> <li>the probability of class 1 given https is 180/(180+1560)=0.103</li> </ul> <p>If these conditional probabilities were very different this feature would be more he...
199
cross validation
nested CV feature selection
https://datascience.stackexchange.com/questions/85994/nested-cv-feature-selection
<p>I have a small dataset of 150 records with 25 features (too small to do train/test). I'm using nested cv for both hyperparameter tuning and feature selection. 10cv in the outer loop, 5 cv in the inner loop. Eventually i'm getting 10 sets of hyperparameters and 10 sets of selected features. If i'm publishing my resul...
<p>Assuming the feature selection method is always the same, on an external data (or final training set), you would simply apply the exact same method. The actual set of selected features does not matter.</p> <p>If there was any difference in the selection method, for instance if you are selecting different number of f...
200
cross validation
Which observation to use when doing k-fold validation or boostrap?
https://datascience.stackexchange.com/questions/11316/which-observation-to-use-when-doing-k-fold-validation-or-boostrap
<p>I have to perform predictive model over the dataset $D$ (with 1000 obs). From $D$, I extract 700 obs for training $(T)$ and 300 obs for validation $( V )$.</p> <p>I need to perform bootstrap or 10-fold cross validation sampling.</p> <p>The question is which of these sets should I use?</p> <ul> <li><p>Divide $D$ i...
<p>I recommend using the second option you presented. I would use $T$ with 10-fold CV to select my modeling technique and optimal tuning parameters. Take a look at what performed the best ("best" being the model that gives us the best error, but also doesn't have the error fluctuate too much from fold to fold). Afte...
201
cross validation
80-20 better than full dataset for LightGBM
https://datascience.stackexchange.com/questions/46430/80-20-better-than-full-dataset-for-lightgbm
<p>Recently I have been using LightGBM as regressor in order to predict, on a dataset of 20 thousand observations and 40 variables.</p> <p>I have two modes, <strong>1)</strong> Production and <strong>2)</strong> Testing. The first one just trains a model with the whole dataset. The second does the same with an 80% of ...
<p>I cannot think about any theoretical reason. However:</p> <ul> <li>It may be the case that the neg_mean_squared_error is not correctly implemented. Try another metric, like Median or Mean Percentage Error and see if that continues to happen.</li> <li>It may be related to how the data is distributed, but still that'...
202
cross validation
choosing classifiers
https://datascience.stackexchange.com/questions/56847/choosing-classifiers
<p>For what I read the 5x2cv t test is</p> <p>"a procedure for comparing the performance of two models (classifiers or regressors) that was proposed by Dietterich to address shortcomings in other methods such as the resampled paired t test and the k-fold cross-validated paired t test"</p> <p>.</p> <p>I am currently ...
<p>See, your conclusions appear to be correct, your statistical results explain your conclusions , i would say statistically speaking even with a P-value of 0.055 you still have an error rate of 15 to 25% that you may be accepting a wrong null hypothesis and maybe your alternate hypothesis is right , so combining knowl...
203
cross validation
Cross validation while preserving a column (not the target ) distribution
https://datascience.stackexchange.com/questions/58557/cross-validation-while-preserving-a-column-not-the-target-distribution
<p>So i'm doing <em>cross validation</em> and then i'm predicting using all the data on a test set ( a hold-out set ). My hold-out set has the <strong>same ratio</strong> on a column than the train ( seems thats how the test set was generated, a function that sampled it and tried to preserve the ratio for the <strong>t...
<p>One idea would be to combine the two columns (one predictor and the target) and then stratify using the combined column.</p> <p>Example: say for some observations, the target and the column take the following values: <code>target = [0,1,0]</code> and <code>column = [A,A,B]</code>. Then the combined column could loo...
204
cross validation
Publish without validation score?
https://datascience.stackexchange.com/questions/60821/publish-without-validation-score
<p>My mentor wants me to write and submit an academic paper reporting a predictive model, but without any validation score.</p> <p>Everything I have read in textbooks or the Internet says that this is wrong, but is there any case where only reporting a train score makes sense?</p> <h3>Background</h3> <p>The model wa...
<p>The most likely issue here is to do with </p> <blockquote> <p>fifty features, but those features were extracted from thousands</p> </blockquote> <p>If those features were selected according to a pre-data-analysis theory, and other selections were not considered, then a linear model that fit the data might be str...
205
cross validation
Increasing samples increases variance
https://datascience.stackexchange.com/questions/68182/increasing-samples-increases-variance
<p>I've been running kfold cross validation with 10 folds and comparing it against a test set. Logging the score and the stdev along the way. </p> <p>Once I wad happy with my model I then run the estimator through the cross validation with the full data (including the test set) but ... The standard deviation of the sc...
<p>The score decreasing and the standard deviation of the scores increases, as sample size increases, indicates overfitting to the smaller sample size. </p>
206
cross validation
Cross Validation how to determine when to Early Stop?
https://datascience.stackexchange.com/questions/28542/cross-validation-how-to-determine-when-to-early-stop
<p>When using "K-Fold Cross Validtion" for Neural Net, do we:</p> <ol> <li>Pick <strong>and save</strong> initial weights of the network randomly (let's call it $W_0$)</li> <li>Split data into $N$ equal chunks</li> <li>Train model on $N-1$ chunks, validating against the left-out chunk (the $K$'th chunk)</li> <li><stro...
<p>First, I would like to emphasize, that cross-validation on itself does not give you any insights about overfitting. This would require comparing training and validation errors over the epochs. Typically you make such comparison with your eye and you can start with one train/validation split.</p> <p><strong>Question...
207
cross validation
Why is n-fold cross validation not expensive for K-nearest-neighbours?
https://datascience.stackexchange.com/questions/109729/why-is-n-fold-cross-validation-not-expensive-for-k-nearest-neighbours
<p>I have on my uni lecture notes that one of the n-fold cross-validation disadvantages is that it is very expensive to train this because this could take a long time if the dataset is very large. But they say that this is not the case if we use k-nearest neighbors classifier. I know to some extend what a k-nearest nei...
<p>Your understanding is correct, but for the point of interest what matters is that k-NN is a &quot;lazy learner&quot; (see explanations for example <a href="https://sebastianraschka.com/faq/docs/lazy-knn.html" rel="nofollow noreferrer">here</a> or <a href="https://datascienceguide.github.io/k-nearest-neighbor" rel="n...
208
cross validation
How does k fold cross validation work?
https://datascience.stackexchange.com/questions/26669/how-does-k-fold-cross-validation-work
<p>You split the data in k subsamples. Train it on k-1 subsamples, test it on kth subsample, record the performance with some error merric.</p> <p>Do it k times for each of the k subsamples, record the error each time. Then choose the model with the lowest error? Is it the same as ensemble technique?</p>
<p>Imagine you have 1500 labeled data points, and you want to estimate how well some classifier will work on new data. One (naive) method would be to train a model with all 1500 of your data points, and then check how many of the 1500 data points were classified correctly. This is not likely to give a good estimate of ...
209
cross validation
Cross-validation of a cross-validated stacking ensemble?
https://datascience.stackexchange.com/questions/17317/cross-validation-of-a-cross-validated-stacking-ensemble
<p>let me begin by saying that I understand how to build a stacked ensemble by using cross-validation to generate out-of-fold predictions for the base learners to generate meta-features. My question is about the methodology when cross-validating the entire stacked ensemble to check generalization error.</p> <p>To elim...
<p>I posted this same question on Reddit and someone was kind enough to answer</p> <p>By <a href="https://www.reddit.com/user/patrickSwayzeNU" rel="nofollow noreferrer">https://www.reddit.com/user/patrickSwayzeNU</a></p> <blockquote> <p>This</p> <blockquote> <p>When I do CV B, is it valid to do CV A just o...
210
cross validation
Should I use GridSearch CV for hyper-parameter tuning in a data-rich context?
https://datascience.stackexchange.com/questions/108474/should-i-use-gridsearch-cv-for-hyper-parameter-tuning-in-a-data-rich-context
<p>My textbook states that k-fold cross-validation is a resampling technique that is useful for estimating generalization error in a data-poor setting.</p> <blockquote> <p>Ideally, if we had enough data, we would set aside a validation set and use it to assess the performance of our prediction model. Since data are oft...
<p>When you are doing hyperparameter tuning on Testing data , it puts you at risk of introducing Bias as training data should act as unseen data and no optimisation should be done on that. So to avoid this scenario completly you can follow two approach:</p> <ol> <li>Divide your training data into train and validation. ...
211
cross validation
how and why do training and cross validations sets wear out in time?
https://datascience.stackexchange.com/questions/118122/how-and-why-do-training-and-cross-validations-sets-wear-out-in-time
<p>In google's crash course on <a href="https://developers.google.com/machine-learning/crash-course/validation/another-partition" rel="nofollow noreferrer">ML</a>, I have read an interesting tip on train&amp;validation sets. they say</p> <blockquote> <p>'Test sets and validation sets &quot;wear out&quot; with repeated ...
<p>The purpose of splitting our data into training, validation, and test sets is to evaluate our models with data that they have not seen before and to directly compare them (and to choose the best model based on that comparison).</p> <p>However, the more we use the test and validation sets to compare models or choose ...
212
cross validation
Can we use k fold Cross Validation without any extra (excluded) Test Set?
https://datascience.stackexchange.com/questions/49571/can-we-use-k-fold-cross-validation-without-any-extra-excluded-test-set
<p>I have seen this in two Papers:</p> <p>The authors use 10 fold cross validation, and then present the results from this validation or even odder the results from the best Fold as their modelling Result. </p> <p>there has been no testing data put aside to validate the final model. These are peer reviewed papers i a...
<p>The key question is</p> <blockquote> <p>Is K-fold cross validation is used to select the final model (or algorithm)?</p> </blockquote> <ol> <li><p>If yes, as you said, then the final model should be tested on an extra set that has no overlap with the data used in K-fold CV (i.e. a test set).</p></li> <li><p>If n...
213
cross validation
Does double cross-validation make sense?
https://datascience.stackexchange.com/questions/120428/does-double-cross-validation-make-sense
<p>We do the following:</p> <ol> <li>split <code>data_all</code> into K folds, each consisting of <code>data_train_k</code> and <code>data_test_k</code> where k = 0, ... K-1.</li> <li>for each k in 0, ... K-1, split <code>data_train_k</code> into M folds each consisting of <code>data_train_k,m</code> and <code>data_eva...
<p>Yes, nested cross-validation will produce an unbiased estimate of the model building process. That is the point of it.</p> <p>The whole point of this is that the inner cross-validation could be biased because you are performing a hyperparameter search on the same data you are pulling repeated validation sets from. T...
214
cross validation
scikit-learn cross_val_score randomness
https://datascience.stackexchange.com/questions/121673/scikit-learn-cross-val-score-randomness
<p>Does cross_val_score in scikit-learn split the data consistently or randomly? I noticed that cross_val_score lacks a random_state parameter, but the documentation mentions stratified k-fold cross-validation, which is implemented in the StratifiedKFold class that does have a random_state parameter for shuffling. So, ...
<p><code>cross_val_score</code> is a convenience function which relies on <code>KFold</code> or <code>StratifiedKFold</code> (see <a href="https://scikit-learn.org/stable/modules/cross_validation.html#cross-validation" rel="nofollow noreferrer">documentation</a>):</p> <blockquote> <p>When the cv argument is an integer,...
215
cross validation
Best practice with cross validation
https://datascience.stackexchange.com/questions/56108/best-practice-with-cross-validation
<p>I have done a 10 fold Cross Validation on my data and have selected the best model from the results. With cross validation, I will have 10 models trained from different folds of the data. For the final model to use, should I take the average of the models or just fit a model for the entire training set?</p>
<p>Typically you would use the best model parameters and then re-run the model with the portion of the data set aside for training to come up with a new 'best' that you can run against your test set.</p>
216
cross validation
Cross-validation for model comparison: use the same folds?
https://datascience.stackexchange.com/questions/51703/cross-validation-for-model-comparison-use-the-same-folds
<p>Let's say we have model M1 and model M2 that we want to compare. When we do 5-fold (say) cross validation, would the correct method to be to partition the data into F1, F2, F3, F4, and F5 and then run both models through those folds? Then would the way to assess if M2 outperforms M1 be to do a paired t-test?</p> <p...
<p>There seem to be a few elements of confusion here. I'll try to answer clearly, but would definitely appreciate input from others.</p> <p><strong>1. What is cross-validation for?</strong></p> <p><em>Cross-validation</em> is generally used as a mechanism for figuring out which of several models might be a better fit...
217
cross validation
Cross Validation and bias relation
https://datascience.stackexchange.com/questions/92902/cross-validation-and-bias-relation
<p>I found a question (Question 7) <a href="https://www.sanfoundry.com/data-science-questions-answers-cross-validation/" rel="nofollow noreferrer">here</a>:</p> <blockquote> <p>Question: For k cross-validation, larger k value implies more bias <br> Options: True or False</p> </blockquote> <p>My answer is: <strong>True...
<p>Why should bias increase as the training set size increases?</p> <p>My intuition is that as you increase K, your test sets get smaller, increasing the variance of your evaluation metric. At the same time, you're fitting your model to more and more similar training data (since the training set in each fold is approac...
218
cross validation
Cross validation
https://datascience.stackexchange.com/questions/128741/cross-validation
<p>I do not get why in <a href="https://datascience.stackexchange.com/questions/123130/for-cross-validation-should-i-use-training-set-or-whole-dataset">For cross validation should I use training set, or whole dataset?</a> the responses say that cross validation must be done exclusively on training set. Doesn't the meth...
<p>Cross-validation can be used on two levels.</p> <ol> <li><p>When you want to evaluate an estimator <span class="math-container">$h$</span> by estimating its risk <span class="math-container">$\mathbb{E}[L(h(x),y)]$</span> based on some loss function <span class="math-container">$L$</span>, you need independent sampl...
219
cross validation
What might explain a dramatic vertical jump in sensitivity
https://datascience.stackexchange.com/questions/18174/what-might-explain-a-dramatic-vertical-jump-in-sensitivity
<p>Context: I'm training an RNN with LSTM layers using the keras api. I have sequences of 20 timesteps, but just a binary response. For example: X=[[[1,2,3], [2,3,1]], [[4,1,2], [2,1,3]]], and y = [[1.0], [0.0]]. The binary variable y explains the action of the <strong>next</strong> timestep, because that is all I'm in...
220
cross validation
K-fold crossvalidation: how do MSE average and variance vary with K?
https://datascience.stackexchange.com/questions/37150/k-fold-crossvalidation-how-do-mse-average-and-variance-vary-with-k
<p>I'd like to get an intuition about how varying <em>k</em> impacts k-fold validation. Is the following right?</p> <p><strong>Average of the OOS MSEs should generally <em>decrease</em> with k</strong> Because, a bigger "k" means the training sets are larger, so we have more data to fit the model (assuming we are us...
<p><strong>Average of the OOS MSEs should generally <em>decrease</em> as k increases.</strong> This is right but the difference is much less then on your chart. Suppose we have a dataset where the error will halve if we increase the data 10 times (approximately true for the paper <a href="http://www.aclweb.org/antholog...
221
cross validation
Cross-Validation: Repeated K-Fold/Group K-Fold
https://datascience.stackexchange.com/questions/63901/cross-validation-repeated-k-fold-group-k-fold
<h3>Repeated K-Fold vs Group K-Fold</h3> <p>As per my understanding from sklearn docs</p> <p><strong>Repeated K-Fold:</strong></p> <p>RepeatedKFold repeats K-Fold n times. It can be used when one requires to run KFold n times, producing different splits in each repetition.</p> <p><strong>Repeated Stratified K-Fold ...
<p>Group k-fold is sufficiently specialized that the comparisons you ask for don't really make sense. "Repeated" really does just mean to remake the splits multiple times; you could easily make a "repeated group k-fold" splitter.</p> <p>You use group k-fold when you have groups you don't want split across the trainin...
222
cross validation
Does adding a model complexity penalty to the loss function allow you to skip cross-validation?
https://datascience.stackexchange.com/questions/92571/does-adding-a-model-complexity-penalty-to-the-loss-function-allow-you-to-skip-cr
<p>It's my understanding that selecting for small models, i.e. having a multi-objective function where you're optimizing for both model accuracy and simplicity, automatically takes care of the danger of overfitting the data.</p> <p>Do I have this right?</p> <p>It would be very convenient for my use case to be able to s...
<p>There is no free beer in such matters so &quot;automatically takes care of the danger of overfitting the data&quot; is not true. When you optimize for a loss error function and also for simplicity the immediate question is how do you trade off simplicity on loss error. There is no answer to that, other than in very ...
223
cross validation
k-fold cross-validation: model selection or variation in models when using k-fold cross validation
https://datascience.stackexchange.com/questions/28420/k-fold-cross-validation-model-selection-or-variation-in-models-when-using-k-fol
<p>I am new to machine learning, though I have a background in statistics. But I had a question about $k$-fold cross-validation. So I understand the basic idea that we divide the dataset into $k$ partitions and then train a model on $k-1$ partitions while testing on the $k$th partition that was left out. So we don't wa...
<p>There are two main (set of) things your model needs to learn from training: <strong>Parameters</strong> and <strong>Hyperparameters</strong>.</p> <p>Parameters are those that can be inferred (learnt) from data. These are internal to the model and will be calculated in the training phase during. The hyperparameters ...
224
cross validation
Trying to understand Nested k-fold CV in a paper
https://datascience.stackexchange.com/questions/123711/trying-to-understand-nested-k-fold-cv-in-a-paper
<p>I fully understand the data partition in a nested k-fold CV. But reading this:</p> <blockquote> <p>Within each outer fold, the best performing model was selected based on mean root mean squared error (RMSE) over the inner folds. The model was then retrained on all training and validation data from the inner folds an...
<blockquote> <p>The model was then retrained on all training and validation data from the inner folds</p> </blockquote> <p>My understanding is that the inner fold already contains some training and also validation data, so retraining is done with the latter as validation data.</p> <p>There is another reason not to use ...
225
cross validation
Why does cross validation have a pessimistic bias?
https://datascience.stackexchange.com/questions/84754/why-does-cross-validation-have-a-pessimistic-bias
<p>My course notes list two reasons why cross-validation has a pessimistic bias. The first one is that the accuracy is measured for models that are trained on less data, which I understand. However, the second reason I don't understand. Supposedly, when we do cross validation and divide our data D into training sets D_...
226
cross validation
leave one pair out cross validation
https://datascience.stackexchange.com/questions/101754/leave-one-pair-out-cross-validation
<p>I am trying to train and validate my datasets which contains 17 datasets. I have divided them as 15 for training and 2 for validation. In the process, I train on 15 datasets and use the generated model to predict the results on the remaining 2 datasets. This process is called leave out validation in my understandin...
<p>[edited after clarification by OP]</p> <blockquote> <p>I can not understand if they are doing so good in the training why the validation results are so bad.?</p> </blockquote> <p>This is certainly due to major differences between the datasets. Supervised learning relies on the assumption that both the training set a...
227
cross validation
How can I do nested cross validation for multivariate Time series forecsting
https://datascience.stackexchange.com/questions/78122/how-can-i-do-nested-cross-validation-for-multivariate-time-series-forecsting
<p>I'm trying to do nested CV for my multivariate time series but I'm really confused how to do it. I have 7 Time series which are the inputs of my CNN model and one time series as target.Always when I read about it I found they talk about univariate.Any advices</p>
228
cross validation
Cross-validated average: metrics mean or ensembling probabilities?
https://datascience.stackexchange.com/questions/87290/cross-validated-average-metrics-mean-or-ensembling-probabilities
<p>Let's say I have 5 models cross-validated via leave-one-out strategy. I have the predictions and scores of each model.</p> <p>Now, it's time to calculate the average for the set of 5 models - am I supposed to:</p> <ul> <li>add up the 5 losses and divide them by 5?</li> <li>Or average their probabilities for each pre...
<p>A standard way to provide the performance of each model would be:</p> <ul> <li><p>providing, for each split, the value of the chosen metric (accuracy, roc_auc, etc) on the train and test sets (on your case, your one-out sample), something like this (in this case with 2 models): <a href="https://i.sstatic.net/jS2ks.p...
229
cross validation
Kfold or cross_val_score
https://datascience.stackexchange.com/questions/87709/kfold-or-cross-val-score
<p>I am all new with ML. I try to understand what is Kfold and cross_val_score.<br /> I made this model:</p> <pre><code>RandomForestRegressor(max_depth=17,n_estimators=93,criterion='mse') modelfinal.fit(xtrain1, ytrain1) mrse_test = np.sqrt(mean_squared_error(y_pred=modelfinal.predict(xtest1), y_true=ytest1)) </code></...
<p>Overfitting is visible when the performance on the training set is much higher than the test set, so you clearly had overfitting with your first experiment already.</p> <p>Cross-validation is not a way to see overfitting by itself, it's a way to obtain a more reliable performance value by using several splits (remov...
230
cross validation
Why use mean revenue in a split test?
https://datascience.stackexchange.com/questions/748/why-use-mean-revenue-in-a-split-test
<p>I asked a data science question regarding how to decide on the best variation of a split test on the Statistics section of StackExchange. I hope I will have better luck here. The question is basically, "Why is mean revenue per user the best metric to make your decision on in a split test?"</p> <p>The original quest...
<p>If you've got prior information then you should certainly not use simple mean in a split test. I assume you're trying to just predict which group will produce the greatest amount of revenue overall, by trying to emulate the underlying distribution.</p> <p>Firstly, it's worth noting that any metrics you choose will ...
231
cross validation
How is cross validation used to prune a decision tree
https://datascience.stackexchange.com/questions/8598/how-is-cross-validation-used-to-prune-a-decision-tree
<p>As I understand it one can use cross validation to help find the optimal pruning of a classification or regression tree, for example, implemented here in <a href="http://au.mathworks.com/help/stats/classificationtree.cvloss.html#bunpajd-1" rel="noreferrer">Matlab</a>. </p> <p>I do not understand the following about...
<p>I don't know how this is implemented in matlab. I know that some packages use cross validation to decide whether to grow the tree or not. Quite simply, they decide whether to grow based on that evaluation.</p> <p>(Notice what a lot of packages call pruning is: during training, they mark branches with some score cri...
232
cross validation
Convert Out-of-bag (OOB) estimate to quad weighted kappa score
https://datascience.stackexchange.com/questions/9923/convert-out-of-bag-oob-estimate-to-quad-weighted-kappa-score
<p>Is there a way to directly calculate an approximate quad weighted kappa measure from an OOB estimate, obtained from a gradient boosting model with subsampling without going through cross validation?</p>
233
cross validation
Is it possible to create feature groups in Orange?
https://datascience.stackexchange.com/questions/10824/is-it-possible-to-create-feature-groups-in-orange
<p><strong>Background:</strong> I am trying to use Orange as to classify if a patient has TB based on their coughing sounds.</p> <p>In the dataset, there are say 100 patients and for each patient we have 10 coughs. For each cough, we have a full feature vector (170 features). </p> <p>Giving Orange this dataset and tr...
<p>This is not Orange-specific, but IIUC, you could preprocess your data (e.g. in Python or <a href="https://www.libreoffice.org/discover/calc/" rel="nofollow">Excel</a>) to have each of the 10 coughs pertaining to a patient on the same patients line. Thus you would have: 100 rows of patients with each row (10*170 + ot...
234
cross validation
Cross-validation strategy
https://datascience.stackexchange.com/questions/13411/cross-validation-strategy
<p>I have a regression problem and I am in doubt about how I can calculate RMSE in my life-cycle.</p> <p>I deal with time-series and for every prediction, I want to look N points in the future. It is apparent how to calculate RMSE for a single iteration. My question is how to calculate RMSE for N predictions of N poin...
<p>The natural choice would be the total squared error across the N predicted values, averaged across all examples. This is the simple extension of mean squared error from the univariate case. If you're using multivariate linear regression, this is in fact what you want to optimize in order to get the maximum likelihoo...
235
cross validation
Significant difference in testing vs cross validation accuracy
https://datascience.stackexchange.com/questions/13753/significant-difference-in-testing-vs-cross-validation-accuracy
<p>What could be the possible reasons for a significant difference in cross validation and testing f1_scores? I am performing 3 fold Stratified cross validation and the testing f1_score is almost 0.15 less than cross validation score. How can I come up with a more effective cross validation strategy so that the two sco...
<p>Significant differences between the calculated classification performance in cross-validation and in the final test set appear obviously, when the model is overfitted. </p> <p>A good indicator for bad (i.e., overfitted) models is a high variance in the F1-results of single iterations in the cross-validation. </p> ...
236
cross validation
R - Function for 10 fold crossvalidation
https://datascience.stackexchange.com/questions/22247/r-function-for-10-fold-crossvalidation
<p>I have written a function for 10 fold crossvalidation that I want to use for different models, e.g PPR, MARS. However, I get an error when running it and I cannot figure out why it does not work? My CV function:</p> <pre><code> cv10 &lt;- function(reg.fn, formula, dataset, ...) { set.seed(201) ### Number of...
<p>Because your data has 30 rows and your loop is from 1 to 10 so when it gets to <code>i=10</code> then <code>end &lt;- (i+1)*M</code> which is 11 * 3 which is 33 and then you do <code>Ind[beg:end]</code> but <code>Ind</code> is only 30 long so you get:</p> <pre><code>[1] 21 NA NA NA </code></pre> <p>and then its NA...
237
cross validation
Cross-Validation model selection
https://datascience.stackexchange.com/questions/23277/cross-validation-model-selection
<p>I have done 10-Fold CV on my data and I have selected my model complexity from the result. Now for my best complexity, I will be having 10 different models. Should I take the average of these models for my testing or should I just fit a model of our selected complexity on our CV data and then test?</p>
<p>You re-train the model based on your best complexity (or parameters) on the complete training data. Then you can test the model on un-touched test dataset and report your error measure.</p>
238
cross validation
How to decide to use K-fold validation or not?
https://datascience.stackexchange.com/questions/29607/how-to-decide-to-use-k-fold-validation-or-not
<p>When K-fold validation should be used and how to decide the value of the K. I see most of the text books suggesting implementation of algorithms using 2/3 of data as train and 1/3 of data as test</p>
<p>The main criterion is that you need enough data in your training set to get a good model fit - which is both a function of the data quantity and the model complexity.</p> <p>When you don't have much training data, you want as much data in your training set as possible - in this case, you can do "leave one out" cros...
239
cross validation
Why can&#39;t I choose my hyper-parameter in the training set?
https://datascience.stackexchange.com/questions/31662/why-cant-i-choose-my-hyper-parameter-in-the-training-set
<p>Say I've divided the data into 3 parts: training, validation and test. I know for example, that in Neural Networks, the number of hidden layers is a hyper parameter. Why can't I train numerous NN architectures in the training set and then test their accuracy in the test set; thereby allowing me to choose one final m...
<p>I wouldn't say you can not tune the hyper-parameters in the trainig dataset, but the purpose of doing so is different than in the validation set.</p> <p>In general, what it is intended with a ML algorithm is how to optimally classify or perform regression given some training data. Once the model is trained, it will...
240
cross validation
How can one use a validation set to reduce overfitting Naive Bayes?
https://datascience.stackexchange.com/questions/40860/how-can-one-use-a-validation-set-to-reduce-overfitting-naive-bayes
<p>What is the correct procedure for using a validation set to reduce overfitting? </p> <p>Say I split the data 80:10:10 (training: validation:test). I train on the training set then get 90% accuracy. I apply this model to the validation set then get 20%. What do I do then? </p> <p>How can the validation set be used ...
<p>It is not much about the algorithm you use. It is about the fact that you learned so much details from your training set so just tune the parameter inside a loop in which training and validation errors are calculated each time. In NB case, you do not have many parameters in that sense. Probably the features can be i...
241
cross validation
Change rate of cross validation data, after training
https://datascience.stackexchange.com/questions/46700/change-rate-of-cross-validation-data-after-training
<p>Say we have N of labeled data, and we need to take some part for the <code>cross validation</code> (we will skip <code>test</code> part for this case). We chose, 0.6 part for the training and 0.4 for validation. </p> <p>After training neural Network with <code>early stop</code>, we have found 8 epochs, as optimal t...
<p>Due to stochastic nature of NN training, the best epoch may vary upon each restart. In other words, at epoch 8, each of (the best, under-fitted, over-fitted) cases may happen. However, if you train multiple times and the best model is consistently found at (or around) 8th epoch, it is safe to say 8th epoch gives the...
242
cross validation
Applying Hold-out and CV technique
https://datascience.stackexchange.com/questions/51984/applying-hold-out-and-cv-technique
<p>I have a methodology question: are hold-out and CV generalization-optimization techniques mutually exclusive? It gets really confusing to me at times, because in the most recent project I have been doing something as follows:</p> <ul> <li>I have split the dataset into TRAIN and TEST sets (with stratified distributi...
<p>You are correct in the sense that when tuning your model via. grid search you are technically not leaking any data. But, recall that tuning your model (via. a specific procedure such as grid search) is one of only many steps you probably took in fitting your model pipeline. In particular, areas such as pre-processin...
243
cross validation
Training Deep learning and validation loss
https://datascience.stackexchange.com/questions/55093/training-deep-learning-and-validation-loss
<p>I'm trying to replicate result of a paper. The paper is a U-net for De-noising of some images. So basically I have a simple U-net that I give noisy data as input and have denoised data as the wanted output (use l2/MSE loss) . So, in the paper and generally in most papers like this (deep learning applied to medical i...
<p>Using validation loss to determine when to stop iterating is a good strategy when you have a lot of labeled training data. However, in medical contexts, it's often the case that labeled data is expensive and/or difficult to come by. You mention that you only have 1000 samples -- this is a pretty small amount of data...
244
cross validation
Is it okay to use training data for validifying the trained model?
https://datascience.stackexchange.com/questions/56109/is-it-okay-to-use-training-data-for-validifying-the-trained-model
<p>Currently, I have trained my model through 5-fold cross validation with very small amount of the sample (n=100).</p> <p>I used whole data set to train and got quite low performance in terms of accuracy, which is bit higher than 70%.</p> <p>However, if I put my data which was used for training back to trained model...
<p>Scoring your model using the training data is not a best practice. The reason is that you have already used this data to develop the "guess" at an accurate model.</p> <p>This is akin to saying - 'Pick a random number between 1 and 10 (20 times)', here's a list of the last 10 numbers I picked to get you started. Y...
245
cross validation
Value Error: MSLE &amp; CrossVal
https://datascience.stackexchange.com/questions/61595/value-error-msle-crossval
<p>I'm trying to run cross validation with mean squared log error with sklearn and getting the following error message:</p> <pre class="lang-py prettyprint-override"><code>ValueError: Mean Squared Logarithmic Error cannot be used when targets contain negative values. </code></pre> <p>This would suggest that I have ne...
246
cross validation
Acceptable variation in accuracy of each k fold when using K-Fold Cross Validation?
https://datascience.stackexchange.com/questions/64092/acceptable-variation-in-accuracy-of-each-k-fold-when-using-k-fold-cross-validati
<p>I have a relatively small dataset consisting of 1432 samples.</p> <p>I have trained a Random Forest Classifier and performed KFold CV. The results of running 10 Fold CV are as follows:</p> <pre><code>=== 10 Fold Cross Validation Scores === CVFold 1 = 90.2% CVFold 2 = 87.6% CVFold 3 = 86.7% CVFold 4 = 86.7% CVFold...
<p>It's indeed a quite large variation, but nothing alarming since 9 out of 10 folds are within the range 0.8 to 0.9. </p> <p>There are many possible factors: yes a fold can be easier than another one by chance, but it also indicates that the training process is a bit unstable. Increasing the number of instances and/o...
247
cross validation
Cross validation vs leave one out
https://datascience.stackexchange.com/questions/64094/cross-validation-vs-leave-one-out
<p>I have found the following definitions, but I don't really see the difference.</p> <p><strong>cross validation</strong> Method for testing classification and prediction models. The data are randomly split into N partitions (typically N=10) and then N times a model is created from N-1 partitions and tested on the "h...
<p>Assuming your dataset includes <span class="math-container">$k$</span> samples:</p> <p>In cross-validation, there are <span class="math-container">$N$</span> partitions, and the test split for each partition will have size <span class="math-container">$\frac{k}{N}$</span>.</p> <p>Leave-one-out validation is a spec...
248
cross validation
Multiple Linear Regression with k-fold Cross Validation
https://datascience.stackexchange.com/questions/64436/multiple-linear-regression-with-k-fold-cross-validation
<p>I would first like to create few multiple regression models based on if the models violate any multiple regression assumptions and how well it fits the training data. Then I would like to compare how well these models predict new observations by using 5-fold Cross Validation. From my understanding 5-fold Cross Valid...
<p>As Peter said, you need to split your dataset into two subsets: Training, and Test sets. Generally, 80% of data is allocated for Training set (20% for the Test set). Thereafter, depending on the language/package you use (caret in your case), you use 5- or 10-fold cross-validation to train your model, and finally, yo...
249
clustering algorithms
Clustering algorithms
https://datascience.stackexchange.com/questions/20120/clustering-algorithms
<p>I have sparse vectors and found that cosine similarity is very efficient to to measure the similarity. Now I want to cluster these vectors based on similarity. Hence, can someone please suggest/recommend clustering algorithms that make use of cosine similarity?</p> <p>P.S.: I do not have a predefined number of clus...
<p>You can see your affinity matrix as a <a href="https://en.wikipedia.org/wiki/Glossary_of_graph_theory_terms#weight" rel="nofollow noreferrer">weighted adjacency matrix</a> of a <a href="https://en.wikipedia.org/wiki/Graph_(discrete_mathematics)" rel="nofollow noreferrer">graph</a> and apply <a href="https://en.wikip...
250
clustering algorithms
clustering algorithms&#39; evaluation
https://datascience.stackexchange.com/questions/106304/clustering-algorithms-evaluation
<p>How can I show clustering performance of various clustering algorithms on various datasets using adjusted mutual information and adjusted rand index. for instance, the plot below</p> <p>.<a href="https://i.sstatic.net/LNGbe.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/LNGbe.png" alt="enter image d...
251
clustering algorithms
Incremental clustering algorithm
https://datascience.stackexchange.com/questions/116664/incremental-clustering-algorithm
<p>I am looking for an <strong><em>incremental</em></strong> clustering algorithm. By <strong><em>incremental</em></strong> I mean an algorithm that builds clusters starting from an initial dataset and that is able to progressively ingest new items/observations adding them to existing or new clusters.</p> <p>The maximu...
<p>One option is incremental hierarchical clustering.</p> <p><a href="https://en.wikipedia.org/wiki/Hierarchical_clustering" rel="nofollow noreferrer">Hierarchical clustering</a> either uses agglomerative or divisive approaches to divide the data into stratified groups. In hierarchical clustering, the number of cluster...
252
clustering algorithms
Clustering algorithms for high dimensional binary sparse data
https://datascience.stackexchange.com/questions/23591/clustering-algorithms-for-high-dimensional-binary-sparse-data
<p>I have a dataset with 10,000 genes like below</p> <pre><code>person gene1 gene2 ... gene10000 ethnic 1 0 1 1 asian 2 1 0 1 European </code></pre> <p>Each row means, whether a person has a gene in their DNA or not. We are trying to classify different ethnic gro...
<p>How many ethnic groups did you identify?</p> <p>If I had to visualize your problem, I'd determine the key influencers for each of the ethnic groups in a Naive Bayes like approach. These genes (gene combinations?!) (including their values) may strongly correlate to some ethnic group, while not (or inverse) correlate...
253
clustering algorithms
how to handle outliers for clustering algorithms?
https://datascience.stackexchange.com/questions/63695/how-to-handle-outliers-for-clustering-algorithms
<p>I am wondering what's the best way to handle outliers when using non-supervised clustering algorithms?</p>
<p>If you have outliers, the best way is to <strong>use a clustering algorithm that can handle them</strong>.</p> <p>For example DBSCAN clustering is robust against outliers when you choose minpts large enough. Don't use k-means: the squared error approach is sensitive to outliers. But there are variants such as k-mea...
254
clustering algorithms
Stationary time series for clustering algorithms
https://datascience.stackexchange.com/questions/54041/stationary-time-series-for-clustering-algorithms
<p>I have a set of time series data that I would like to feed into a clustering algorithm (like k-means, using dynamic time warping as the distance function). After standardizing the data with mean 0 and variance 1, the k-means classifier generated a batch of centroids that seemed to fit the data pretty well.</p> <p>T...
<p>Have you tried replacing the entire timeseries with some meta data of it - clustering on each point of a series seems to be a bit exzessive. Especially as then if your timeseries are not synchronized they might not be considered similar - eventhough they might be for the purpose of this exercise (Imagine two sinus c...
255
clustering algorithms
What are the drawbacks of traditional clustering algorithms?
https://datascience.stackexchange.com/questions/28361/what-are-the-drawbacks-of-traditional-clustering-algorithms
<p>As a newbie, I am interested what the major drawbacks of traditional clustering algorithms are. The purpose is to understand for which class of data or in which scenarios I shouldn't use traditional clustering methods (e.g. K-means)</p>
<p>Check out this great answer for K-means in particular:</p> <p><a href="https://stats.stackexchange.com/questions/133656/how-to-understand-the-drawbacks-of-k-means">How to understand the drawbacks of K-means</a></p> <p>My favorite resource for comparing the strengths and weaknesses of clustering algos is from sklearn...
256
clustering algorithms
Do Clustering algorithms need feature scaling in the pre-processing stage?
https://datascience.stackexchange.com/questions/22795/do-clustering-algorithms-need-feature-scaling-in-the-pre-processing-stage
<p>Is feature scaling useful for <a href="https://en.wikipedia.org/wiki/Cluster_analysis" rel="noreferrer">clustering algorithms</a>? What type of features, I mean numeric, categorical etc., are most efficient for clustering?</p>
<p>Clustering algorithms are certainly effected by the feature scaling. </p> <p>Example: </p> <p>Let's say that you have two features:</p> <ol> <li>weight (in Lbs)</li> <li>height (in Feet)</li> </ol> <p>... and we are using these to predict whether a person needs a 'S' or 'L' size shirt.</p> <p>We are using weigh...
257
clustering algorithms
Using Classification Algorithms to Interpret Clustering Reuslts
https://datascience.stackexchange.com/questions/26235/using-classification-algorithms-to-interpret-clustering-reuslts
<p>Often clustering algorithms only output a bunch of class labels, and do not provide any sort of interpretation of the classes formed by the algorithm. It seems to me not entirely unreasonable to attempt to get some sort of interpretation by using the class labels provided by the clustering algorithm as the target in...
<p>There's nothing wrong with this idea and although I don't have literature on hand, I'm fairly confident I've seen this sort of thing done. I disagree that clustering algorithms often don't provide interpretation though. There are definitely plenty that don't, but I'm not sure k-means is one of them. The centroids of...
258
clustering algorithms
Find most important and least important features for clustering algorithm
https://datascience.stackexchange.com/questions/103200/find-most-important-and-least-important-features-for-clustering-algorithm
<p>I am experimenting with clustering algorithms, like K-Means. Right now, I use all variables as input for the clustering algorithm. I am wondering if it is appropriate to do feature selection for clustering algorithms. That is, how can I find those variables that are most important or least important for clustering.<...
<p>It is not straightforward to feature selection for k-menas clustering since it unsupervised.</p> <p>One option is to loop through the features, leaving one out at a time. Select a criterion for better and worse clusterings, one example could be silhouette score. Then see which feature contributes the most or least t...
259
clustering algorithms
How to preprocess/encode categorical data, to use in dimensionality reduction and clustering algorithms?
https://datascience.stackexchange.com/questions/129530/how-to-preprocess-encode-categorical-data-to-use-in-dimensionality-reduction-an
<p>I am working on a project witht the goal of clustering participants of in a survey according to their answers. The dataset is a set of 63 questions, some nominal and some ordinal. How should I encode the data before using dimensionality reduction algorithms like tsne amd then clustering algorithms like kmeans and hi...
<p>Although you question is quite broad, I mean you can read a whole lot of chapters out there. Still I'd mention my approach.</p> <ol> <li>I try to understand nature of Data i.e. look for categorical variables and cardinality. High cardinality can pose challenges for some encoding techniques.</li> <li>Next step is to ...
260
clustering algorithms
How to use Cosine Distance matrix for Clustering algorithms like mean-shift, DBSCAN, and optics?
https://datascience.stackexchange.com/questions/69183/how-to-use-cosine-distance-matrix-for-clustering-algorithms-like-mean-shift-dbs
<p>I am trying to compare different clustering algorithms for my text data. I first calculated the tf-idf matrix and used it for the cosine distance matrix (cosine similarity). Then I used this distance matrix for K-means and Hierarchical clustering (ward and dendrogram). I want to use the distance matrix for mean-shif...
<p>Several scikit-learn clustering algorithms can be fit using cosine distances:</p> <pre class="lang-py prettyprint-override"><code>from collections import defaultdict from sklearn.datasets import load_iris from sklearn.cluster import DBSCAN, OPTICS # Define sample data iris = load_iris() X = iris.data # List ...
261