Questions tagged [scikit-learn]

A machine-learning library for Python. Use this tag for any on-topic question that (a) involves scikit-learn either as a critical part of the question or expected answer, & (b) is not just about how to use scikit-learn.

Filter by
Sorted by
Tagged with
0 votes
2 answers
14 views

Why does X @ coef_ + intercept_ does not equal Y_pred for sklearn PLSRegression?

I performed partial least squares regression using Python's sklearn.cross_decomposition.PLSRegression using the example data in the sklearn docs. I am surprised that X @ coef_ + intercept_ does not ...
0 votes
0 answers
11 views

What is the proper order of preprocessing steps in a dataframe containing categorical and numerical variables? [closed]

I have a dataframe where X is comprised of categorical (nominal and ordinal) and numerical variables, and y is numerical (continuous). Sort out X's nominal, ordinal and numerical variables. Ordinal ...
4 votes
1 answer
60 views

How to motivate the definition of $R^2$ in `sklearn.metrics.r2_score`?

TLDR: What motivates the definition of $R^2$ in the Python function sklearn.metrics.r2_score? DETAILS The Python machine learning package ...
  • 35.7k
1 vote
1 answer
18 views

OneClassSVM performs better when trained on pure data (inliers only)

I have a dataset which has some outliers and majority of the class is inliers (not anomalous). I am trying to train a OneClassSVM/...
0 votes
0 answers
6 views

Centroid in sklearn cosine similarity

What is the centroid of the unit sphere that is assumed in the sklearn cosine similarity function?
  • 1,269
0 votes
0 answers
31 views

ConvergenceWarning while running MLPClassifier [closed]

Code: mlpc = MLPClassifier(hidden_layer_sizes = (11,11,11), max_iter = 500) mlpc.fit(X_train, y_train) pred_mlpc = mlpc.predict(X_test) Warning Received: C:\...
user avatar
0 votes
0 answers
13 views

Why is the following dataset giving me a negative R squared value? [duplicate]

This is my code, I calculated R square using Scikit learn : y =[0, 10, 20, 30, 40] f =[0, 1, 2, 3, 4] r2 = r2_score(y, f) print('r2 score for perfect model is', r2) ...
  • 1
0 votes
0 answers
10 views

What is the variable v in this case? Is it standard deviation or variance?

The code below is from an example on the scikit-learn website for plotting the Gaussians of a GMM as ellipses. However, I don't know whether the final definition of the variable ...
  • 111
2 votes
1 answer
28 views

add more data to training set

I am using the LinearSVC() available on scikit learn to classify texts into a max of 7 seven labels. So, it is a multilabel classification problem. I am training on a small amount of data and testing ...
1 vote
1 answer
28 views

Why does SKLearn's Logistic Regression model have the same coefficients as my own model for 1 class but have different coefficients for other classes

I am currently implementing logistic regression from scratch and I'm comparing my model with SKLearn's logistic regression. Since this is just an exercise, I decided to use toy data, specifically ...
  • 11
0 votes
0 answers
24 views

Can I use cross-validation to make predictions?

Hi I am a beginner and I am confused about whether I can make predictions with the models produced during kfold. For example in the code below, the model produced in each kfold was used to make ...
  • 1
2 votes
1 answer
43 views

Anomaly detection, LOF vs IsolationForest

I have a training dataset with 140 000 instances with 140 features. Due to the scale of the dataset I'm experiment with letting a model do the anomaly detection and have tried LocalOutlierFactor and ...
  • 149
1 vote
0 answers
15 views

Clarity needed on SVM concepts

I've been reading up on articles and forums to understand how soft margin affects the classification of new data points, but I still couldn't connect the dots on how soft margin affects the outcome of ...
  • 11
0 votes
0 answers
16 views

Passive Aggressive Classifiers for incremental learning, iterating multiple times over new data or set C higher

I am trying to understand the PassiveAgressiveClassifier from scikit-learn and wondered if there is an advantage in choosing the aggressiveness parameter C (page 5) smaller but iterating more times ...
  • 1
0 votes
0 answers
14 views

Domain generalization for Random forest

I have recently been thinking about domain generalization. It is well known that domain generalization aims to learn a model from one or several different but related domains that will generalize well ...
1 vote
0 answers
20 views

Finding Probability that data is taken from a Gaussian Mixture Model

I'm using scikit's Gaussian Mixture to obtain a 2 component mixture model for some 1-D data. Having obtained a model, I want to test how well a different data set matches this mixture model, or more ...
  • 33
1 vote
2 answers
40 views

Can SVM overfit even with cross-validation?

I am using SVM regressor models to fit some chemical data related to spectroscopy (I cannot say exactly what data because it is an ongoing research in my group). To combat overfitting, I have used 5-...
  • 163
0 votes
0 answers
23 views

What's a good rule of thumb for choosing a sufficient number of quantiles in quantile transformation?

I'm a currently developing a regression model based on the Choquet Integral. To tackle outliers I am using the Quantile Transformer, provided by scikit-learn. I was wondering how the quantile number ...
1 vote
1 answer
43 views

Data preparation (preprocessing and data cleaning) before or after train-test split with scikit learn?

I have been practicing Data Science/Machine Learning, and I am confused about when to complete the following tasks when using train-test split in scikit learn: EDA Filling in missing data Removing ...
  • 11
1 vote
0 answers
8 views

Standardization on production dataset

Say I trained a Logistic regression model on a training dataset (sample = 2000), using Standardization. I than test the model on a test dataset (sample = 400) using the Standardization parameter ...
  • 11
8 votes
4 answers
749 views

Is it required to train the model in entire data after cross validation?

I have a model trained as follows. ...
  • 203
0 votes
0 answers
37 views

How can I add information about historical rates of occurrences to class probabilities?

first some introduction: I have a trained a probabilistic softmax model using the sklearn multinomial logistic regression which predicts the class probabilities (class $A, ~B$ or $~C$) of any object ...
2 votes
1 answer
19 views

Understanding Stacked Generalization

I am trying to figure out how stacked generalization works? I think we train n models on the same dataset and get their class probabilities. Then these class probabilities are fed into another model. ...
0 votes
1 answer
23 views

Reconstruct IR Spectra Based on PLS Model

I am currently using the scikit-learn package in python to setup PLS models (sklearn.cross_decomposition.PLSRegression) to predict the concentration of different substances based on IR spectra. In ...
0 votes
1 answer
58 views

F2 score or the Area under the Precision-Recall-Curve as a scoring metric

I have a dataset with which I want to perform binary classification. The distribution of the target class is imbalanced: 20% positive labels, 80% negative labels. The positive class is more important ...
  • 135
0 votes
1 answer
79 views

What are the main difference between a QQ plot and a probability plot for measuring nomality? [duplicate]

I am trying to evaluate the normality of the distribution of my model's residuals. I have been using statsmodels.api.qqplot and ...
  • 95
2 votes
1 answer
71 views

Scikit-learn QuantileRegressor memory allocation error. No issue with statsmodel QuantReg with the same data

I'm trying to fit a quantile regression model to my input data. I would like to use sklearn, but I am getting a memory allocation error when I try to fit the model. The same data with the statsmodels ...
  • 95
0 votes
1 answer
32 views

How to properly impute values on the test set using imputer (missForest)

I'm trying to impute some missing values on my dataset $X$. So first I shuffle and split data to obatin the train set X_train and the test set ...
  • 279
1 vote
1 answer
35 views

How to transform prediction std of gaussian process back to origin

I am looking for a way of rescaling the predictions of my Gaussian Process Model back to the original scale. The data is scaled for training using a ...
2 votes
1 answer
41 views

What does it mean having 1 as best k parameter in K-NN?

I'm working with a large dataset (761 rows and about 57k-60k features) and after doing a feature selection to select the best 10 features I'm using different ML algorithms to classify some cases. In ...
  • 23
0 votes
1 answer
25 views

Hyperparameter tunning in SelectKBest feature selector

I am working with a pretty large dataset containing 760 rows and arround 58k-60k features and I'd like to perform a feature selection to reduce the dimensionality of those. After stardardising the ...
  • 23
1 vote
2 answers
50 views

Why are sklearn's cross_val_score values not increasing with the size of the training set?

I am working on a lithology identification project similar to the one described here. The idea is to train a model using well log data collected at a handful of drillholes, in order to predict the &...
  • 113
0 votes
0 answers
71 views

Combinatorial Cross-Validation Embargo and Purged

There is a library on GitHub called timeseriescv which implements Combinatorial CV. I am trying to use it in conjunction with GridSearchCV. However, unlike normal sklearn cross validators which have a ...
2 votes
1 answer
25 views

Different precisions in predicting two classes with logistic regression

I am using the kaggle's stroke dataset trying to predict the stroke target feature, according to multiple predictive features. https://www.kaggle.com/datasets/...
2 votes
0 answers
59 views

Train-Test Split with nested groups and multiple balancing factors

I have a large (~15,000) sample of data from individuals nested within families (with about half the data points sharing a family). I want to split the sample in to a training and test set so I can ...
2 votes
1 answer
105 views

sklearn's permutation_importance returns surprising result

I have simulated normally distributed data (x_1 = np.random.normal(0, 1, size=1000)) and used it to create a dependent variable with a linear combination of the ...
  • 63
1 vote
0 answers
63 views

Defining a spatiotemporal (time-varying) kernel using GaussianProcessRegressor [closed]

(I edit the question to make it more specific and clear) High-level idea I want to implement the idea of capturing the correlation between two data points $x$ and $x'$ that can be different at two ...
  • 11
2 votes
1 answer
64 views

Question about the output results of Scikit-learn's adjusted rand index

There is a problem that the calculation of ARI using the Adjusted_rand_score function in Scikit-learn does not match the results of the ARI calculation based on the paper proposed by Hubert et al1. ...
  • 21
0 votes
0 answers
12 views

Is there a stochastic AdaBoost?

In sklearn, the AdaBoostClassifier and AdaBoostRegressor classes do not have the subsample and max_features parameters, which are responsible for the stochastic approach to building a boosting model. ...
2 votes
2 answers
293 views

XGBRegressor score (R2) vs. eval_metric (RMSE)

According to the API Reference, XGBRegressor().score() returns R2. However, according to the XGBoost Paramters page, the default ...
  • 21
3 votes
1 answer
136 views

Why does univariate Mahalanobis distance not match z-score?

I am using Mahalanobis distance for outlier detection. Sometimes my dataset only has 1 feature, sometimes many more. I believe the univariate Mahalanobis distance should be equal to the z-score of the ...
  • 284
2 votes
1 answer
62 views

Random Forest Generating Bad Predictions: What might the issue be?

I'm using sklearn's RandomForestRegressor to try and model a relationship that involves three Feature variables (x1,x2,x3) and ...
1 vote
0 answers
46 views

Detect exact position of a word or number in a sentence with machine learning

I'm trying to come up with an ML model/s to detect if a sentence has sensitive data(telephone number, IBAN, address, etc.) and also get the position of said sensitive data. For Example "My name ...
0 votes
0 answers
18 views

How to step-into the learning process of support vector machines

OK, with the intention to produce a balanced class distribution for an imbalanced binary problem based on SVC, I created this custom function. Basically, it takes binary imbalance data, fits an ...
  • 231
1 vote
0 answers
90 views

Using curve_fit for Non-Linear, Multi-Variate Models [Python] [closed]

Warning: ML Noob. I have a 3D dataset (data at the bottom) with 2 feature variables and 1 target variable. Polynomial Regression produced unsatisfactory results and it seems that the relationship of ...
1 vote
0 answers
19 views

Why would I get a non-zero value for mutual information for one variable, say x_m (belonging to (x_1, ..., x_n)), to target y, if x_m is a constant?

I have n 'features', (x_1, ..., x_n) and a target variable y. I use sklearn's mutual information score for feature selection to determine which features are the most important for the target y. I get ...
  • 71
0 votes
0 answers
23 views

Non-parametric equivalent of SelectKBest f_classif option

I'm doing a project where I am comparing various feature selection methods to see if they improve performance compared to the original dataset with 747 columns. One I want to try is the ANOVA method, ...
1 vote
1 answer
75 views

XGBoost Regression on a normal distribution variable produces a one sided distribution (only positive values)

I'm running a scikit-learn XGBoostRegressor with an RMSE loss function, on a variable with a distribution that is close to symmetric around 0 (think normal distribution, with a positive mean that ...
  • 131
1 vote
0 answers
89 views

Duality gap calculation in Scikit-learn implementation of Lasso

I am writing a custom variation of Lasso regression, using sklearn's Lasso implementation as a "source of inspiration". And I don't quite understand the very last line in the calculation of ...
0 votes
0 answers
79 views

How to tune hyperparamters and use CalibratedClassifierCV correctly

Let's say that I have a classifier C ( for example a random forest classifier) and a Dataset. From what I understand I can: prefit the classifier on a portion of data and then "calibrate it"...
  • 101

1
2 3 4 5
35