Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [scikit-learn]

scikit-learn is a machine-learning library for Python that provides simple and efficient tools for data analysis and data mining, with a focus on machine learning. It is accessible to everybody and reusable in various contexts. It is built on NumPy and SciPy. The project is open source and commercially usable (BSD license).

0
votes
1answer
43 views

Sklearn 'Seed' Not Working Properly In a Section of Code [on hold]

I have written an ensemble using Scikit Learn VotingClassifier. I have set a seed in the cross validation section. However, it does not appear to 'hold'. Meaning,...
0
votes
0answers
10 views

Imbalanced Dataset - Poor Evaluation

My dataset has about ~75,000 records with 39 features. Most of the features are categorical, so I have one-hot encoded them. About 14% are minority with label 0 and the rest 86% with label 1. I have ...
1
vote
0answers
15 views

Understanding the log-likelihood (score) in scikit-learn GMM

I have been training a GMM (Gaussian Mixture, clustering / unsupervised) on two version of the same dataset: one training with all its features and one training after a PCA truncated to its 2 first ...
0
votes
0answers
10 views

Classification of sample with only unseen words

I'm doing text classification (Product Name) where one example belongs to one class. "Some Product Name" -> MODEL -> {CLASS_1 | CLASS_2 | CLASS_3 | CLASS_4} ...
0
votes
1answer
40 views

SVD matrixes do not coincide with Eigen decomposition for covariance matrix [duplicate]

I am comparing the output from the singular value decomposition with the eigendecomposition of the covariance matrix (symmetric matrix). I am expecting that the Eigenvector and a non-diagonal matrix ...
0
votes
0answers
8 views

Dropping One-hot-encoded columns in Pandas/Sklearn

When one-hot-encoding categorial features in python with pandas or sklearn, when should I drop one of the resulting columns? I recall something about having all columns present being a problem for ...
2
votes
0answers
41 views

Principal Components' relation with variables having lower variance

This is a philosophical question about PCA, and not a direct coding question. I understand that PCA is a dimensionality reduction technique which results in a certain set of PCs, each PC being a ...
0
votes
1answer
27 views

Fixing the maximum distance within a cluster

I am trying to cluster geographical locations in such a way that all the locations inside each cluster are at max within 25 miles of each other. For this, I am using Agglomerative clustering. I am ...
1
vote
0answers
25 views

why is this decision tree always getting 100% accuracy [closed]

I am beginner in machine learning and doing the UD120 course ..I was doing the feature selection exercise ...
1
vote
1answer
23 views

how to build multiple independent binary logistic regression classifiers?

I have to build a logistic regression classifier to predict $\mathbf{y}$ given $\mathbf{x}$ where $\mathbf{x} \in \Re^{n}$ is an image and $\mathbf{y} \in \Re^{m}$ is a binary attribute vector (of $m$ ...
1
vote
0answers
21 views

Possible error in evaluating kernel gradient in scikit-learn's GPR

Perhaps I am missing something very obvious, but in the standard kernels associated with scikit-learn's Gaussian process regression framework, the radial basis function (RBF), $$f = e^{-x^2/2l^2},$$ ...
1
vote
2answers
29 views

Score of importance from feature selection techniques

Can I get the score of importance for each feature in feature selection methos such as Chi2, Information Gain (IG), or Recursive Feature Elimination (RFE)? Or they just provide a list of important ...
0
votes
0answers
18 views

Do you need to adjust the probability if you use the 'class_weight' parameter in LogisticRegression-sklearn?

I have a imbalanced dataset and I want the the output as probabilities and not labels. Hence using Logistic Regression seemed to be the obvious choice. However the classsifer started predicting all ...
0
votes
1answer
9 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 ...
1
vote
0answers
18 views

Train model on “bootstrapped” target?

Question I'd like to train a model in scikit-learn with the following input. Instead of having (X, y), I have (X, dy) where <...
0
votes
1answer
12 views

What is the formula for calculation of `R_ij` in `numpy.corrcoef(x, y, rowvar = False)`?

The manual does not provide the formula if we pass x and y. I do not understand the matrix I get. Here is my code: ...
0
votes
0answers
12 views

Scikit-learn: converting multiclass classifiers to binary classifiers while dealing with sampling bias

Scikit-learn has LabelBinarizer to convert multiclass labels to binary ones. But, how does Scikit-learn deal with the bias introduced (under-representation) when one converts a multiclass classifier ...
4
votes
2answers
39 views

Train classifier on balanced dataset and apply on imbalanced dataset?

I have a labelled training dataset DS1 with 1000 entries. The targets (True/False) are nearly balanced. With sklearn, I have tried several algorithms, of which the GradientBoostingClassifier works ...
0
votes
1answer
19 views

Avoiding information leakage in CV folds with scaling

Chapter 6 (Algorithm Chains and Pipelines) in the book Introduction to ML with Python made me aware of a common mistake when scaling data for cross validation: leaking information into the test set by ...
0
votes
0answers
12 views

How to keep the numeric scale for PCA?

I'm doing a 1-component PCAs on individual groups of correlated values with sklearn. mapping=PCA(n_components=1) X_mapped = mapping.fit_tranform(X_group) For ...
1
vote
1answer
20 views

Memory considerations with sklearn classfier

I am trying to fit a sklearn.ensemble.RandomForestClassifier. The [docs] explain that a matrix (rows - observations, columns - features). My observations are 700 ...
0
votes
0answers
18 views

Classifying matching object pairs with Python / sklearn

I have a ground truth dataset of around 600,000 objects. Each object has 100 features, and for each pairwise combination of objects, I have a 0-1 relationship ("equal" / "not equal"). What is the best ...
0
votes
1answer
45 views

Is it possible to apply a monotonicity constraint on a Gaussian process regression fit?

Below is a code using scikit-learn where I simply apply Gaussian process regression (GPR) on a set of observed data to produce an expected fit. I know physically that this curve should be ...
1
vote
1answer
34 views

Why doScikit Learn's regression coefficients only match formal equation with standardized data?

I was playing around with LinearRegression in Scikit Learn and I found a peculiarity that I'm trying to make sense out of. If you compare values from the coef_ ...
0
votes
0answers
12 views

Calculating sklearn's average precision by hand

I'm trying to understand how sklearn's average_precision metric works. The reason I want to compute this by hand is to understand the details better, and to figure ...
0
votes
0answers
9 views

How to print labels and column names for Confusion Matrix? [migrated]

I get the confusion matrix but since my actual data set has lot of classification categories, it's difficult to understand. Example - ...
1
vote
1answer
27 views

Is it valid to compare the likelihood of different models in Gaussian process regression?

When applying different kernel's through scikit-learn's Gaussian process regression, I observe certain instances with positive log-likelihood outputs which indicate a likelihood that is greater than 1....
1
vote
1answer
20 views

Display Confusion Matrix properly -

I am trying to print the confusion matrix, but it is getting wrapped after few columns (or characters). I have tried several settings but didn't help: ...
0
votes
1answer
30 views

What are “good” features for feature selection?

I use sklearn's random forest for classification (two categories). The following code is used for "good" feature selection. ...
1
vote
0answers
22 views

What kind of regression should I run on data that looks like this (multiple lines in scatterplot)

I am sure my terminology is a bit off here, this is my first such analysis. I have a dataframe with quite a few columns, and I am trying to understand what are the major coefficients for a model that ...
0
votes
1answer
29 views

Splitting into train and test sets keeping class proportions

I have a dataset for a binary classification task which has 90 percent 'yes' and 10 percent 'no'. Let's say I want to take 25 percent of the data as the test set (which the model will not see). How ...
0
votes
1answer
36 views

What is difference between accuracy_score() and cross_val_score()?

The problem I'm working on is a multiclass-classification. Have been reading through lot of articles and documentation, but not able to figure out which of Accuracy_Score or Cross_Val_Score should be ...
0
votes
0answers
30 views

Dendrogram y-axis labeling confusion

I have a large (106x106) correlation matrix in pandas with the following structure: ...
0
votes
2answers
21 views

In Linear regression is it possible to have same sign coefficients for dummies coming from the same variable?

So I have a categorical variable color which can take the values white, black, red. I created dummy variables for each of those ...
0
votes
0answers
12 views

How do we actually calculate the feature importance in stacking

I tried implementing stacking using Scikit learn but I need to know how they are finding the feature importance. Let me know if you need more info.
1
vote
1answer
44 views

Regarding pre-processing function StandardScaler in scikit-learn library. How to save the scaler variable for predicting new data [closed]

Please help me. I am trying to give maximum information related to my query. I have a query regarding pre-processing function in scikit-learn library. My data set are divided into 3 parts train, test,...
0
votes
0answers
43 views

Sklearn BaggingRegressor does not work with LightGBMRegressor & MAE objective

I'm trying to use BaggingRegressor from scikit-learn together with LightGBMRegressor and Mean Absolute Error objective and I'm receiving nan outputs. I reproduced ...
0
votes
1answer
20 views

Non-negative Orthogonal Matching Pursuit

For my research with stocks, I want to construct a synthetic stock (from a linear-combination of other stocks). I want to use OMP from sklearn: https://scikit-learn.org/stable/modules/generated/...
1
vote
1answer
35 views

Why is cross_val_score substantially lower than .score or roc_auc_score?

I have a trained model, a GradientBoostingClassifier. My dataset is 60 thousand something rows of data that I've split into 66/33 train/test sets. Scoring the model via the ...
4
votes
1answer
112 views

Is it wrong to choose a regressor based on MSE?

I see many people on the web assuming that R² is not an appropriate metric to select a regressor instead of another, suggesting AIC or BIC to do so. From my view, it means that its almost preferable ...
1
vote
1answer
32 views

LogisticRegression (sklearn) - why does 'predict_proba' yield better results?

I'm practicing my machinelearning / sklearn skills with a kaggle playground and I'm having trouble why a suggested change made by a fellow user yields better results. The challenge involves binary ...
2
votes
0answers
29 views

Implausible variable importance for GBM survival: constant difference in importance [closed]

I have a question about a GBM survival analysis. I'm trying to quantify variable importances for my variables (n=453), in a data set of 3614 individuals. The resulting graph wi th variable importances ...
1
vote
1answer
37 views

PCA with SVD give me differents results compare to manually computed

I am trying to do PCA using the SVD method manually and compare the results with the results computed by PCA on sklearn. Let's say that our matrix is A = [[3 0],[0 -2]] Following the SVD method, I ...
0
votes
0answers
9 views

Which performance metric to use for stratified data? [duplicate]

I'm trying to classify a data into 3 classes (supervised), one of which is heavily underrepresented in the data set. In order to combat this imbalance, I decided to stratify the data. Now I want to ...
1
vote
1answer
39 views

Training r-squared decreases after adding higher degree polynomial terms to regression model

I was playing around with some examples to get some experience using the PolyFeatures tool from Scikit-Learn, and I ran into something strange. I iteratively added ...
12
votes
2answers
996 views

Is decision threshold a hyperparameter in logistic regression?

Predicted classes from (binary) logistic regression are determined by using a threshold on the class membership probabilities generated by the model. As I understand it, typically 0.5 is used by ...
0
votes
1answer
56 views

PCA principal components in sklearn not matching eigen-vectors of covariance calculated by numpy

I was trying to replicate PCA in sklearn's PCA API using numpy using PCA in numpy and sklearn produces different results. I noticed that: eigenvalues are same as the PCA object's explained_variance_ ...
0
votes
1answer
75 views

Determine thresholds for test from ROC-curve

I'm trying to determine the threshold from my original variable from an ROC curve. I have generated the curve using the variable and outcome, and I have generated threshold data from sklearns ROC ...
0
votes
0answers
45 views

dual formulation for logistic regression in scikit-learn

I am trying to understand how to use dual formulation for logistic regression in scikit-learn. I have a dataset containing 500 data points and 19 variables. 15 of these variables were categorical ...
0
votes
1answer
25 views

Anyway i can improve this multi class classification result?

I am building a multi class classification model using SVM to predict the grade for essays. What can I do to improve the result especially for class 1 and class 3? Their precision and recall are ...