New answers tagged

0

Without a target variable, you cannot do supervised machine learning. After all, you don't know whether any of these people would shop at the store or not, so any prediction your model produces will be a complete guess, and you won't have any way to tell whether it's right or not. If you just want to do a toy problem, you could build a synthetic target ...


1

What you describe, while somewhat unusual it is not unexpected if we do not optimise our XGBoost routine adequately. Your intuition though is correct: "results should not change". When we change the scale of the sample weights, the sample weights change the deviance residuals associated with each data point; i.e. the use of different sample weights' scale, ...


0

You need to preprocess the data the same way you did the training data. In the context of scaling, that means scaling using the same parameters as used on the training data. You can do that by hand, but sklearn's preprocessors are set up to do this pretty easily. Assign the preprocessor to a variable, then use the transform method on the new data. scaler ...


1

the inverse transform of the standard deviation is wrong. Mean and standard variation have to be transformed differently. Here's a brief explanation: Transform Let's assume random variable $Y$ with mean $\mu_Y$ and variance $\sigma^2_Y.$ The "Scaler" subtracts some constant $a$ and divides the result by a factor $b.$ The transformed variable equals $Z = \...


0

Intuition might tell you that adding more variables should make the model better, and to some degree it is true, but after a certain number of variables this does not hold anymore and adding more variables only increases the complexity of the model. Finding the right combination of variables which minimizes your loss functions (such as RMSE) and minimizes ...


0

What tripped me up: disable sklearn regularization LogisticRegression(C=1e9) add statsmodels intercept sm.Logit(y,sm.add_constant(X)) OR disable sklearn intercept LogisticRegression(C=1e9,fit_intercept=False) sklearn returns probability for each class so model_sklearn.predict_proba(X)[:,1] == model_statsmodel.predict(X) Use of predict fucntion ...


1

To add gunes' excellent answer, you may also use several scoring functions following: scoring = {'accuracy': make_scorer(accuracy_score), 'precision': make_scorer(precision_score, average = 'macro'), 'recall': make_scorer(recall_score, average = 'macro'), 'f1_macro': make_scorer(f1_score, average = 'macro', '...


1

The issue is that you are calling fit_transform on both the training data and the test data. In other words, you are retraining the transformer on both the training and the test data, whereas to prevent data leakage (which is quite minor in this case, but in general is important to avoid) you would only want to fit the transformer on the train data. In this ...


2

If it were standardisation or normalisation or any other type of transformation that actually learns some parameters from the data and applies it to the next/incoming data, you'd have to first split into train/test, fit your transformation with training set and apply it to the test set, so that you don't learn parameters from the test set. However, yours (i....


0

You can run RandomizedSearchCV multiple times with different seeds and check if the score is better than the best you found previously. The code would look like if not os.path.exists('res.pkl'): best_score, seed = -1, -1 # initialize else: with open('res.pkl', 'r') as fd: best_score, _, seed = pickle.load(fd) # or get the best score so far ...


1

There isn't such an initialization strategy. One simple reason is that if you select a large-enough value for $k$, there will definitely be some centroids with few samples assigned to them. One solution could be to remove centroids with a small number of samples assigned to them, after the algorithm has finished. This technique is similar to pruning in ...


0

You could encode your categorical variables using subsets of categories to reduce the sparsity. For example if the categories of a variable are A, B, C and D, you can create new binary variables "is A or C", "is A or B or D", "is C", etc. The question is then how to come up with relevant subsets. A simple heuristic could be to create random subsets of fixed ...


0

LassoCV simply finds the "best" alpha among a pre-determined set using cross-validation. If you know that it should be around 1e-7, you can use a grid such as np.geomspace(1e-8, 1e-6, 10) as alphas. On the other hand, LassoLarsCV will find "relevant" values of alpha automatically, meaning those at which the number of non-zero coefficients changes for the ...


1

$c$ is the intercept, often denoted $\beta_0$. It is not minimized but the loss function is minimized with $\mathbf{w}$ and $c$ as parameters.


0

You can use any metric you want. The best metric to use depends on the data you have. You can consider using the F1 score. Depending on the averaging technique you use, you can nudge things towards reducing false negatives. If you are using python/sklearn, you can pick your averaging method in the argument (https://scikit-learn.org/stable/modules/generated/...


1

You must use custom scorers via scoring option provided in cross_validate. Here is an example: from sklearn.metrics import mean_squared_error, make_scorer import numpy as np def relu(x): return np.maximum(0, x) def custom_error(y, y_pred): return mean_squared_error(relu(y), relu(y_pred)) scoring = make_scorer(custom_error, greater_is_better = False) ...


0

I resolved this problem some time ago and thought I would present the answer for those who are looking. In short, the Sklearn SVM does not perform in a typical one-vs-rest implementation. Instead it uses a wrapper to develop a decision function that combines the decision functions of several one-vs-other classifiers to perform its classification. This ...


Top 50 recent answers are included