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
1 vote
0 answers
9 views

What does ICA using only one component return?

I understand that with multiple components, the result will be coefficients that lead to maximally independent series. When requesting only one component I'm unclear if it actually does optimization ...
0 votes
0 answers
10 views

Different results from np.SVD and sklearn.PCA

I have a small dataset and computed the singular values of the covariance in 2 ways. But they produced different results of the singular values and the percentage of variance explained by the 1st PC. <...
9 votes
2 answers
687 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 ...
0 votes
0 answers
7 views

Multi-class classification, KBestFeatures, different scores best for different labels - intelligent way to approach?

So I have a dataset with about 6x features as I have samples, which are balanced across 8 classes. I set out to figure out which features are important for each label. I've been approaching this using ...
0 votes
1 answer
235 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 ...
0 votes
0 answers
7 views

Standardize agglomerative feature clustering across samples or features?

I know that typically, one has a feature matrix of n samples by m features. Let's say I have a matrix X in this format. If I was going to perform hierarchical clustering on the samples, I know I ...
0 votes
1 answer
23 views

Are there any difference using scores or probabilities for roc_auc_score and precision_recall_curve functions?

I'm working with a GNN model for link prediction and using precision_recall_curve and roc_auc_score from the ...
1 vote
1 answer
245 views

How to fully evaluate a multiclass classification problem?

When you have a multiclass classification problem, what is the right way to evaluate it's performance? What I usually do is to display the confusion matrix and the ...
1 vote
1 answer
266 views

How can I standarize/normalize my categorical, factorized features in outliers detection problem?

I'm working on anomaly detection in CTU-13 dataset. Records are labeled and there are a few categorical features with many categories (for example one of the features "State" has over 250 possible, ...
0 votes
1 answer
8 views

Classification criteria equation of decision trees

Can someone explain what does the term I(y=k) stand for in the equation for p_mk ?
0 votes
0 answers
12 views

Spark Pipeline - Chain Regressors Together

I'm running this on databricks, using python, spark, pipeline, mlflow, etc. Can use whichever library I need to though I have a simple Linear Regression script. I separately have a Random Forest ...
1 vote
0 answers
26 views

SPSS and Scikit-learn giving different PCA eigenvectors coefficients

The Python code used, printed are the eigenvector coefficients and the relative eigenvalues, the data is the same for both SPSS and Python: ...
2 votes
1 answer
232 views

Is there any background for constraining covariances on fitting GMM?

On clustering data using GMM model, I often see the option to constrain covariances of each clustered GMM. For example, http://scikit-learn.org/0.16/auto_examples/mixture/plot_gmm_classifier.html ...
1 vote
1 answer
266 views

Correct way to interpret sklearn's calibration error and generate a numeric calibration loss/score

I have been using sklearn's CalibrationDisplay and think it is pretty cool. One thing I am wondering, though, is how I could potentially take that curve and make it an interpretable score. For example,...
0 votes
0 answers
17 views

Feature Selection: Select top best features based on feature scores produced by different algorithms

I like to do feature selection and I am using multiple feature selection algorithms provided by sklearn. What I have done is, use a bunch of feature selection algos and get the score for each feature. ...
0 votes
0 answers
15 views

K-folds vs 'all possible k-folds'

I'm using scikit learn's 'KFoldStratified' for a classification task where I have 64 samples, evenly split across 8 labels. I notice the folds are as follows: Test 0, 8, 16... Train 1...7, 9... 15 ...
1 vote
2 answers
352 views

How to get the threshold from PrecisionRecallDisplay?

My goal is to tune the Classifier with probability predict_proba() < threshold. Therefore, I need to get the threshold. The problem is ...
2 votes
1 answer
277 views

What does it mean to have 'R^2 larger than chance' (from sklearn docs)

See the following: From : https://scikit-learn.org/stable/modules/permutation_importance.html The part I'm unsure about is: Its validation performance, measured via the score, is significantly ...
0 votes
1 answer
647 views

GridsearchCV() gives optimum criterion for Decision Tree should be entropy, but why am I getting better accuracy with Gini?

I ran this code ...
0 votes
1 answer
747 views

Question regarding log marginal likelihood in SKLearn

I'm trying to understand the hyperparameter optimization implemented in SKLearn. I'm using the basic example presented here with an alternative data set of 100 observations of Rastrigin test function (...
0 votes
0 answers
21 views

Inverse Weighted Average F1-Score

I am dealing with a binary classification problem (class 0/1) with class imbalance. Given the vector of predictions, I would like to compute: F1-Score for class 0 F1-Score for class 1 Weighted ...
1 vote
1 answer
340 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 ...
1 vote
0 answers
9 views

shuffling data change OPTICS outlier results

I am trying to use sklearn.cluster.OPTICS to identify outliers, but found an issue: I use 2 examples with exactly the same data but different orders. They give different results: 1st example /////////...
2 votes
2 answers
612 views

How do I model seasonal patterns for underprediction?

I want to predict sales in food-vending machines (to ultimately prevent food waste). I work with scikit learn. My current models are not too bad, but they show ...
0 votes
0 answers
9 views

Inconsistencies with OneClassSVM model training

In the literature, for a binary classification problem, I have come across examples where a One-ClassSVM model is trained using the data for only one of the two training labels and sometimes using ...
80 votes
3 answers
82k views

One-hot vs dummy encoding in Scikit-learn

There are two different ways to encoding categorical variables. Say, one categorical variable has n values. One-hot encoding converts it into n variables, while dummy encoding converts it into n-1 ...
2 votes
3 answers
1k views

what to do with 0.5 class probabilities ? [closed]

I am currently training a random forest regressor (scikit learn) on the Titanic dataset. My question is related to this issue (https://stackoverflow.com/questions/19984957/scikit-predict-default-...
3 votes
1 answer
268 views

scikit learn: add lasso or ridge penalty only on subset of parameters

Is there a way of using the linear model api to add the lasso penalty for a subset of the parameters I am regressing? For example, consider a linear separable decomposition that I want to fit to some ...
10 votes
3 answers
2k views

Lasso penalty only applied to subset of regressors

This question has been asked before but there were no responses, so I thought I might ask again. I'm interested in applying a Lasso penalty to some subset of the regressors, i.e. with objective ...
1 vote
1 answer
336 views

Adjusting precision recall curve for oversampling

I built a model for a binary target using oversampled data. The population target prevalence is 0.25. I oversampled to 0.5 by keeping the entirety of the minority class and sampling a portion of the ...
0 votes
1 answer
480 views

Low Feature Importance Scores but High Precision/Recall?

I am running a heterogeneous classification model with numeric, categorical, and unstructured text data to predict a binary response. The data suffers from class imbalance hence I decided to perform ...
1 vote
1 answer
487 views

How is the threshold parameter practically selected for Scikit learn's decision tree algorithm and how to determine depth of tree?

I am referring to the so-called optimized CART algorithm that is explained on Scikit learn's website: https://scikit-learn.org/stable/modules/tree.html#mathematical-formulation I would appreciate if ...
0 votes
0 answers
21 views

Why does sklearn's Chi2 test return different results when a feature is present or absent?

I am doing text classifcation and using SciKit Learn's Chi-square test to select features. Reading about the Chi-square test, a word being present in a text should be just as predictive of a class as ...
1 vote
1 answer
61 views

Sign of Overfitting from a Confusion Matrix

I have used RandomForestClassifier from Sklearn to solve a multiclass classification problem (12 classes in total). I get my x ...
0 votes
0 answers
11 views

Z-scoring (or alternatives) while not creating artifacts

So I'm running into an issue I can illustrate as follows. Lets say you have a shipment of fruit, of various kinds. You want to compare across shipments. You, for some reason, decide to Z-score these ...
0 votes
1 answer
378 views

AUC measure for Local outlier detection in python?

I'm using Local outlier factor algorithm provided by Scikit-learn for outlier detection. For the evaluation i want to use auc measure. ...
1 vote
1 answer
237 views

Validity of BIC for Dirichlet process mixture models

I am implementing clustering using Dirichlet process mixture models via scikit learn's Variational Bayesian Gaussian Mixture model. I arrived at the appropriate priors iteratively, and I am able to ...
2 votes
2 answers
3k views

F1-Score in a multilabel classification paper: is macro, weighted or micro F1-used?

I read this paper on a multilabel classification task. The authors evaluate their models on F1-Score but the do not mention if this is the macro, micro or weighted F1-Score. They only mention: We ...
7 votes
2 answers
648 views

Cross Validation in StackingClassifier Scikit-Learn

In Scikit-Learn StackingClassifier documentation it's written: Note that estimators_ are fitted on the full ...
1 vote
0 answers
23 views

Increased training time during gridsearch for Support Vector Regression

I have a set of 5000 samples with 24 features, and I'm runing a Gridsearch using scikit-learn to find optimal values for C, epsilon and gamma in SVR. In total I'm testing 90 different hyperparameter ...
3 votes
2 answers
94 views

How to adjust the classification thresholds in a multiclass classification problem?

I am facing a multiclass classification problem where I have 4 classes and one of them dominates over the others. I use a KNN classification model and the majority of the instances are being ...
2 votes
1 answer
87 views

Gaussian process mean function in scikit-learn

Scikit learn allows us to fit Gaussian processes $GP(0,K(.,.))$ such that $K:T\times T \to \mathbb{R}$ is a covariance function (kernel), however it doesn't let us specify a mean function $m: T\times \...
1 vote
0 answers
15 views

Logistic regression for probability of action in next n days

I've built a Logistic Regression model in Python for the likelihood of an individual doing an action in the next n days. I am not very experienced at this! My data comprises one row per individual. I ...
2 votes
1 answer
763 views

How does KernelDensity.fit() do the fitting in scikit-learn

How does sklearn.neighbors.KernelDensity.fit() fit the dataset with a probability density distribution? The bandwidth is a parameter that we are already providing; ...
2 votes
0 answers
2k views

χ² (chi-squared) statistic of scipy.stats.chi2_contingency vs sklearn.feature_selection.chi2 [duplicate]

It appears from reading Scikit-learn χ² (chi-squared) statistic and corresponding contingency table that sklearn does not perform a standard contingency table analysis when calculating the χ² ...
2 votes
1 answer
624 views

Find most similar sentence from one list of sentences to another

I have two lists of short sentences (List A and List B). For each short sentence in List A, I am trying to find the most similar short sentence in List B. Each list has a different count of elements ...
2 votes
1 answer
670 views

How to define a classification loss function for discrete ordinal values

Assume multi class classification task where we have 5 labels: 1, 2, 3, 4, 5. For simplicity, let's assume it is the rating of movies, number of stars. I am after a ...
0 votes
2 answers
365 views

Does Chi-square test for independence (sklearn.feature_selection.SelectKBest) produce incorect results?

When looking for correlation between features (for feature selection), I found that sklearn implementation of Chi2 test of independence produce significantly different results from scipy.stats ...
17 votes
4 answers
33k views

Using BIC to estimate the number of k in KMEANS

I am currently trying to compute the BIC for my toy data set (ofc iris (: ). I want to reproduce the results as shown here (Fig. 5). That paper is also my source for the BIC formulas. I have 2 ...
0 votes
1 answer
559 views

Multiclassification: precision-recall from scratch vs sklearn

I would like to know if there´s any issue behind using sklearn's precision/recall metric functions and coding up from scratch in ...

1
2 3 4 5
36