Tag Info

2

First: I think you want the product functionality, not zip, since you are checking every df with every ref. In zip, you would check df_a with ref_1 and df_b with ref_2 only. Second: Your can look at the equation $(1+2+3+4)−(5+5+5+5)$ as $(1-5) + (2-5) + ...$ which is simply subtracting data frames and sum over columns. With these two consideration, ...

0

You should first normalize the whole dataset then split the data. Though you may split first and then do the separate Normalization. Normalization is only needed when you are using a model which is impacted if the features have different stretch in space e.g. Gradient Descent. It is not needed for Decision tree, Random Forest.

0

There are two popular approaches: Model it with classic supervised binary classification algorithms (e.g., logistic regression or Random Forest) and generate features (e.g., look back 1 steps, look back 2 steps, …) Model it with a Hidden Markov Model (HMM). The hidden state is the machine on or off. The observed state is temperature. Given the observed ...

0

In Machine Learning, you are making the assumption that the training and test sets follow the same distribution. If this assumption does not stand, then your model won't be able to generalize properly. Having said that, there obviously is a chance of a test-set feature having a value slightly larger than the max of that same feature in the training set. If ...

1

The minimum and maximum values are just known limits that are parts of the formula that reshapes the distribution of the data, so if a value is higher than the previously known value the resulting feature scaling (Normaliaztion) will be still appropriate. An alternative is z-scores if you don't feel like using minimum and maximum values. x'= (x-x̄) / σ ...

0

It looks that your PCA is not mapping well the data. I recommend you to look at other dimensionality reductions techniques, such as, UMAP, TSNE, in order to see if you can achieve better representation. If you do not have too much data, you could use also MDS since it will preserve local distances (however, computationally very expensive): https://scikit-...

1

You’ve asked two questions: 1) Do you make decisions about model superiority based on training or testing performance? 2) Which model should you prefer? I’ll answer both. 1) First, come over to Cross Validated (the Stack Exchange site for statistics and similar topics, with some overlap to this site) and check out what Frank Harrell has to say about ...

1

If your target values are just 0 and 1, you should probably be treating it as classification, and use e.g. XGBClassifier instead of XGBRegressor. You brought up (originally in the comments on your SO post, now edited into your questions) a scenario when your true values might be limited to 0.5, 1.5, 2.5. That's unusual enough that I suspect the best answer ...

0

When you compute the ROC, you're varying the decision threshold, while the confusion matrix and those metrics based on it are using a default threshold (probability 0.5 for the logistic regression, and the max-margin boundary of the SVM [which isn't meant to be probabilistic by itself]). So the logistic regression is doing at least something meaningful at ...

0

Those scorings looks strange for me, but beside that you must remember that F1, accuracy, confusion matrix, etc depends on the chosen threshold, while AUC is threshold-independent (it is an integral over all of the thresholds from 0 to 1). Your models return some probabilities of being a member of class 1. If you choose to label by '1' only those, which ...

-1

cross_val_score: calculate score for each CV split cross_validate: calculate one or more scores and timings for each CV split

6

Test accuracy better reflects generalization error, so you want the one with higher test accuracy. In your first setup, the higher train accuracy indicates overfitting, as it's significantly higher than train accuracy. This is also kind of why it generalizes less well than the second one.

0

One approach is to create another matrix that stores this information. Scikit-learn stores text features in a document-by-token matrix. The cells of this matrix would be the token index in a document. This matrix then could be used as features during modeling. It would require writing a custom vectorizer which would be similar to scikit-learn's CountVector ...

1

You can use handle_unknown='ignore' in the OneHotEncoder; levels present in the test set but not the train set will be encoded as all-zeros rather than raising an error. But... that example you provide, I rather doubt it's worth it to keep all the levels. The coefficient learned for such a small level's dummy variable will be overly specialized (overfit). ...

2

(To summarize the comment thread into an answer) Your original scores: Mean Absolute Error: 37216342513.01034 Root Mean Squared Error: 871869805169.7842 are based on the original-scale target variable and are between $10^{10}$ and $10^{12}$, at least significantly smaller than the mean of the features (and the target)? So these aren't automatically bad ...

2

To summarize from the comment thread: there are two "weird" things going on here. 1. The zig-zag. As I addressed in the comments, and @BrianSpiering in an answer, this is probably a parity effect, arising from tied votes among the nearest neighbors when $k$ is even. 2. Training accuracy not decreasing (toward test accuracy) with increasing $k$. This was ...

1

It seems you are using a the standard scaler twice, once in your pipeline and once more in the TransformedTargetRegressor. Next to that, you are only fitting the scaler, never actually scaling the inputs (i.e. transforming the input).

1

The answer to this is simple. When we perform the cleaning of the dataset we'll need to do the whole cleaning process for training data first then we'll do the same data cleaning process for the test dataset too. So to avoid doing the same data cleaning process twice, we merge the training and testing data then we perform the data cleaning process and ...

0

I would suggest the following changes, Try KerasRegressor instead of KerasClassifier. Use other activation functions than relu (Eg: tanh, or just linear) Normalize both target and regressors.

0

That is called an Elbow-Curve! You need to look for the lowest train accuracy, or highest test accuracy, where the curve doesn't bend much more (y-axis), for a given increase in K (x-axis). In your case, it's around 7, but you could make an argument for 10, I suppose. As you increase your 'K' the accuracy improves, but only incrementally, and the cost (...

0

I see a couple great answers here! For something like this, I would lean towards Principal Component Analysis (sample code below) and Feature Selection (sample code below). Let's not confuse Feature Selection with Feature Engineering (Data Cleaning & Preprocessing, One-Hot-Encoding, Scaling, Standardizing, Normalizing, etc.) Principal Component ...

2

The xyzSearchCV classes in sklearn require the estimator to be compatible with the sklearn API; in particular, the estimator('s clones)'s hyperparameters get set using set_params, which needs to be defined as a class method for the estimator. So a Keras Sequential model will not work. Keras does provide an sklearn wrapper: https://keras.io/scikit-learn-api/...

0

I gave a lot of thought about the question. I agree with you. But the slight difference might come if there are any random variable operation happens during the training. What model are you using for training?

1

Clean the data and check how each variable is varying with output. Drop the variables which has less variance among the output variable. sklearn.feature_selection contains multiple methods like SelectKBest, chi2, mutual_info_classif to select the best features. https://scikit-learn.org/stable/modules/feature_selection.html Use either PCA,forward stage ...

0

One common approach is to use Principal Component Analysis (PCA) and drop the directions with less variance. see here for instance: https://stats.stackexchange.com/questions/27300/using-principal-component-analysis-pca-for-feature-selection The latest version of sklearn allows to estimate the feature importance for any estimator using the so-called ...

0

Angular has nothing to do with TF-idf vectorization. Its a web framework, so if you python/java etc code is modularised and has the right workflow it will work. Just google how to structure it in angular, its a HUGE topic to give an answer.

1

Good job looking at the tree and understanding what has happened. There is no problem splitting on the same feature multiple times. A continuous feature has many split points available. The tree continues to subset and refine. The split criteria shows what will be the "best" greedy split at this point. If a feature is income, perhaps the best split is \$100,... 0 I'm not really sure what you're asking, but in general, you need to fit an Estimator to data so it can learn what it has to do, then you transform data with it. fit_transform just does fit and then transform. Here you fit the transformer to Name_clean, and then apply it to both in turn. That's pretty normal. 0 Larger scores do mean farther from the separating hyperplane. The SVM model itself isn't modeling probability, so you can't quite say that farther points are considered more probably in one class or the other by the model. There are ways to estimate a probability (see the scikit implementation) for example and yes it will generally be true if so that ... 1 Your example shows that K-means (and clustering in general) is not a suitable tool to detect anomalies. Anomalies are, by definition, points (observations) deviating from normality, however that normality is defined. Clusters, on the other hand, are collections of points sharing some similarities. In your case, you use distance from cluster centroids as ... 1 I think there's no point in trying to catch all anomalies in one cluster. Anomalies are anomalies because they shouldn't belong to any cluster. In your case, it's better to cluster with n_clusters=1 and interpret outliers as anomalies. Also, k-means is probably not the best algorithm for your data because distance to centroid will still catch the outlier. ... 1 By multiplying the maximum by 10 in a loop, you are repeatedly multiplying by$\sim 10$, so that the final point is$\sim 10^{53}\$ (hrm, the plot actually doesn't go quite that far?). Hence the last added point is so far away from the rest, it becomes too costly to include any other points in that cluster. (Doing so drags the mean of the cluster very far ...

2

Depending on your choice of accuracy metric, you'll find that different balancing ratios give the optimum value of the metric. To see why this is true, consider optimizing precision alone vs. optimizing recall alone. Precision is optimized (=1.0) when there are no false positives. Upweighting negative data reduces the positive rate, and therefore the false ...

0

Instance Weight File XGBoost supports providing each instance an weight to differentiate the importance of instances. For example, if we provide an instance weight file for the "train.txt" file in the example as below: train.txt.weight 1 0.5 0.5 1 0.5 It means that XGBoost will emphasize more on the first and ...

1

The first variant is implemented: $$F1_{macro}= \ \sum_{classes} \frac{F1\text{ }of \text{ }class}{number\text{ }of\text{ }classes}$$ You can find an example calculation in this answer. Sometimes the scikit learn documentation does not include all the details. In these cases it is often helpful to look into the source code which is linked on all help-...

1

There's several ways that you can choose your k value for kNN - You can use the common formula k = sqrt(n) where n is the number of data points in your training set or you can try choosing k where there is a good balance between computation expense vs noise. Consider your what fits your problem: Do you care about runtime? The higher the k, the more ...

0

You need to add the graphviz/bin folder to PATH. See the tutorial here.

1

This is still not implemented and not planned as it seems out of scope of sklearn, as per Github discussion #6773 and #13048. However, the documentation on linear models now mention that (P-value estimation note): It is theoretically possible to get p-values and confidence intervals for coefficients in cases of regression without penalization. The ...

0

Here are the high-level steps: Load the .csv from disk into an array in memory. Threshold the probabilities to convert them to predicted target values. Call sklearn.metrics.matthews_corrcoef.

0

You could try to use the same k, like k=8 and run your cross-validation model 100 times, maybe with some little shift on sampling each run, and plot the outcome of each run, to see if there would be some zigzag between the runs. Maybe your data has a lot of cases where for example the weight of the distance function is the same for two candidates(or even ...

0

Which statistic can show me model predictive power ? For example CV-f1 score Which statistic can show me whether my model better predict event 1 or event 0 ? True negative and true positive rate

0

One interpretation is the model has high accuracy when k is even number. An even number of groups in KNeighborsClassifier can result in a high number of ties (i.e., the model predicts a data point is equally likely to belong to multiple groups). The model has reduced accuracy when k is odd, ties are less likely to happen when k is odd. It might be helpful ...

0

I don't think its possible. First, let's see what's the difference in explicitly modeling separate trees for different tasks versus modeling them in joint manner. Lets suppose we have 2 task with each n classes. In the later case, to be able to jointly model the correlations, one must create new classes which is a subset of all the permutations available ...

0

You should be able to pass class_weights through in the fit_params argument of cross_val_score.

0

The problem you are describing is feature selection. Welcome to a particularly sticky problem. Your method of Pearson correlation certainly can help - simply drop those features with low and or insignificant correlation to your dependant variable. This is univariate selection. Since you are using a logistic regression, you can also inspect the model ...

0

As a complement to the very practical answer of @BrunoGL, I'd like to give a more theoretical answer. I'd like to suggest everyone trying to adjust hyperparameters of a simple Neural Network to read Efficient Backprop, by Lecun and others (http://yann.lecun.com/exdb/publis/pdf/lecun-98b.pdf). Yes it's from 1998, no it's not outdated. It covers the impact ...

1

No, SelectKBest and other *Select* transformers from sklearn.feature_selection do not change order of features, only drop not selected ones. Anyway, generally, machine learning models do not utilize relative order of a feature. If you need to check and reorder features, you can use scores_ and/or pvalues_ attributes of a fitted transformer (e.g. SelectKBest)...

1

I agree with @CarlosMougan that the answer to your question "How should I deal with this?" may well be "There is no problem to deal with." This is essentially allowing your feature selection method to lump categories into the baseline. However, some folks seem to prefer categoricals' dummy variables to be kept together. I know of three ways to try to do ...

1

I would say the KMeans algo is doing exactly what it's supposed to do. I would be much more surprised if it DIDN'T do what you told it to do. I was also skeptical the first time I saw plots of my own KMeans calculations. Maybe plotting the data in a 3D chart would be more useful/practical. Here is some sample code that you should be able to adapt to your ...

0

It looks like an error given by the fact you are estimating your regression on the transposed dataset.

Top 50 recent answers are included