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
1 answer
568 views

scikit-learn SVC with custom precomputed kernel matrix uses too much memory

I need to implement a custom kernel for the sklearn.svm.SVC learner. My custom kernel consists in multiplying every element of the kernel matrix except the main ...
df342's user avatar
  • 11
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 ...
Federico Gentile's user avatar
0 votes
0 answers
17 views

Why does this code use MinMaxScaler to preprocess S&P 500 index data? [duplicate]

scaler = MinMaxScaler() sp500_scaled = pd.Series(scaler.fit_transform(sp500).squeeze(), index=sp500.index) sp500_scaled.describe() This ...
user900476's user avatar
2 votes
0 answers
334 views

Why does precision_recall_curve() return similar but not equal values than confusion matrix?

INTRO: I wrote a very simple machine learning project which classifies numbers based on the minst dataset: ...
Federico Gentile's user avatar
4 votes
1 answer
460 views

Why using StandardScaler from sklearn before LogisticRegression increase avg cross_val_score? Standarization should only help in faster convergece

I am using UC Irvine ML Glass Identification dataset mentioned in a book "Applied Predictive Modelling". I tried rudimentary logistic regression models using sklearn with and without the ...
Himanshu's user avatar
3 votes
0 answers
41 views

Cluster Algorithm for multidimensional data

My goal is to cluster data (20000 samples with a range from 0.0 to 1.0, and 14 dimensions/features). Since I don't know the number of clusters, I tried using MeanShift and DBSCAN. My problem with ...
Flitschi's user avatar
1 vote
1 answer
96 views

What are the differences between a Chi-squared test of independence and sklearn feature_importances_?

If I use a Chi-squared test to determine the independence of one of the categorical features from my dataset against the label set, and the test determines statistical significance, i.e. the label is ...
Jay Ekosanmi's user avatar
1 vote
1 answer
886 views

How to perform a regression with categorical variables as input and numerical output?

I am a chemist and I am currently working on a machine learning/statistical learning based project. This question is related to a previous question that I asked before, but is more about the learning ...
S R Maiti's user avatar
  • 163
1 vote
3 answers
704 views

How to compare two random forests in scikit-learn?

With most learning algorithms, one can compare the models resulting from applying the algorithm on samples of data by the parameters of the models. For example, one can compare two logistic regression ...
synack's user avatar
  • 13
0 votes
0 answers
318 views

Which is the correct ROC metric type to use for Imbalanced Dataset (macro,micro, weighted) for multiclass classification?

I am working on a classification task where I have more than 350 classes with HUGE data imbalance. I want to check my model performance but I am confused which metric to use. So I Googled some ...
Deshwal's user avatar
  • 244
1 vote
1 answer
3k views

How to interpret the feature importances for 'eli5.show_weights()' for regression?

I am trying to understand how the interpret the values yielded by eli5's show_weights variable after feature importance. I have used this for several regression models, e.g. multiple linear regression,...
Clarius333's user avatar
1 vote
0 answers
198 views

How the split points are chosen for continuous features in Decision Tree Classifiers

Using the Iris data set, where the feature variables used are sepal_width(x1) and petal_width(x2), scikit learn Decision Tree Classifier outputs the following tree - clf = DecisionTreeClassifier(...
Arnab's user avatar
  • 11
1 vote
0 answers
175 views

Which kernel to use Gaussian Process Regression on hockey-stick data

I need to create a fit using Gaussian Process Regression for data that looks like a hockey-stick (has a fast decay for x=0 to x=10 and for x>50 it converges to some value). I tried with all the ...
Ken Grimes's user avatar
2 votes
0 answers
42 views

Help interpreting image prediction

Could someone tell me why my predicted result ("Predicted Heatmap") has "ghost layers" and gray background? What can I do to improve my model? **What I've done to the images ** ...
Ida's user avatar
  • 21
0 votes
0 answers
148 views

Negative KL divergence for train_test_split in sklearn for y_train and y_val

So, I am trying to understand if I have fair split of my train and val sets using train_test_split of sklearn, so I decided to run the KL divergence and JS div tests and I get the following results. ...
Mona Jalal's user avatar
0 votes
1 answer
282 views

Silhouette was not returning a valid number on scikit-learn on iris data. Is this wrong?

I was testing some clustering validity indexes with Iris Dataset and I got something odd with scikit learn. The silhouette index is giving a better index for 2 clusters instead of 3 clusters (the real ...
Josir's user avatar
  • 101
0 votes
0 answers
74 views

Very low score in binary classification score

I was wondering how to interpret and tweak a model with 10% accuracy, in binary classification. With common feature engineering, I get something around 65% accuracy. When I do some transformation on ...
Nabat Farsi's user avatar
2 votes
1 answer
232 views

Scikit-learn permutation importance is higher than 1 with R-squared scoring

I'm using Scikit-learn permutation_importance to compute the feature importance for a regression problem according to multiple models. I use $R^2$ as the scoring. ...
Miranda's user avatar
  • 166
0 votes
0 answers
58 views

How to interpret result of kMeans scores if I have encoded the data with OneHotEncoder?

I am working on the AdventureWorks database and I have extracted some demographic data from the person scheme as follow. My aim ...
Nikolaev's user avatar
1 vote
2 answers
413 views

Cannot manually reproduce CCA loadings

For my current project I am using sklearn.cross_decomposition.CCA. On several wepages (e.g. https://stats.idre.ucla.edu/r/dae/canonical-correlation-analysis/ or ...
Johannes Wiesner's user avatar
2 votes
1 answer
116 views

Is it important to convert numeric features to object if they have no ordinal or mathematical meaning?

For example a column containing numeric values for phone area code or a postal code. In case it matters, I am preprocessing data for use in a tree-based ensemble classifier.
gsm113's user avatar
  • 29
7 votes
2 answers
16k views

What is the role of 'shuffle' in train_test_split()?

Wondering what shuffle does if I set it to True when splitting a dataset into train and test splits. Can I use shuffle on a dataset which is ordered by dates? ...
Abhiram's user avatar
  • 171
2 votes
1 answer
132 views

Obtain a between-class similarity. And is the way to do it through PCA valid?

Context: I have a dataset containing instances labeled into different classes, and for all the classes, I have the same set of features. My research question is to identify classes that are more ...
revy's user avatar
  • 129
0 votes
0 answers
251 views

Finding the maximum point in a linear regression model

I have a set of data points that I used to train a linear model (with polynomial interpolation as described here. In my understanding, the linear model can be described as a response function ...
x-tof's user avatar
  • 1
0 votes
1 answer
24 views

Why do the roc_auc scores for train_test_split and for cross-validation differ so much? [closed]

When I used scikit-learn pipeline and cross-validation, I got an average cv roc_auc score of about 0.78. But when I used train_test_split, I got a test roc_auc score of only 0.54. The difference is so ...
Goldfish's user avatar
1 vote
0 answers
133 views

Tuning parameters for multiple regression models [closed]

I am trying to compare multiple regression algorithms to estimate biomass (dependant variable) : KNeighborsRegressor, GaussianProcessRegressor, LinearRegression, BayesianRidge, Ridge, SGDRegressor, ...
Ashraf.R's user avatar
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 ...
Data Man's user avatar
2 votes
2 answers
250 views

Pearson chi2 tests of independence: differences between Scipy and Scikit-learn

Scipy and Scikit-learn both implement Pearson's $\chi^2$ test of independence, but they give different results. The former matches what you might expect when computing this test "by hand", ...
shadowtalker's user avatar
  • 11.7k
0 votes
0 answers
41 views

why is using a small vocabulary for topic modelling bad?

i am trying to classify texts into topics. for example, let's say one of the topics is cooperation. so in the vocab param of the sklearn api. so some of the prevalent words (or "tokens" are ...
yishairasowsky's user avatar
1 vote
2 answers
807 views

Why are my elastic net and lasso r-squared measures negative?

I'm using sklearn.linear_model.Lasso and sklearn.linear_model.ElasticNet on a model that includes a constant. I don't expect a model with a constant to perform worse than the average of the data, ie ...
John Vandivier's user avatar
3 votes
2 answers
970 views

How to compute a 'pair confusion matrix'?

I don't really understand how the pair confusion matrix (used for example in comparing of clusterings) is calculated... ...
yliu's user avatar
  • 33
1 vote
1 answer
196 views

Tuning the regression hyperparameters

I am trying to find the hyperparameters of a gaussian process regression algorithm using sklearn. The book (Rasmussen), says I should to maximize the log marginal likelihood given by $$\log(\mathbf{y}|...
noesis's user avatar
  • 13
0 votes
0 answers
232 views

PCA whitening and centering in inference/test samples

[cross-posted from SO] I'm working on speaker identification. I need to take the speaker embeddings from a neural network and apply a few transformations to finally generate the score for verification....
Zabir Al Nazi's user avatar
0 votes
0 answers
41 views

Is this problem a multi-label or multi-class multi-output classification?

I have a dataset whose input data include some numbers like x1, x2, ..., xn. I have n target columns each of which represents a binary vector including m elements. For example, a simple instance of a ...
User's user avatar
  • 111
1 vote
0 answers
1k views

Precision-Recall curves with multiclass classifier

I would like to plot the PR curves for a multiclass classifier (e.g. 3 classes). In the documentation it states that multiclass is not supported, and instead a series of one vs all classifiers are ...
John S's user avatar
  • 11
1 vote
0 answers
68 views

How does cost_complexity_pruning_path in sklearn calculate effective alphas when pruning a decision tree?

I know when pruing DecisionTreeRegressor, we can leverage cost_complexity_pruning_path method to get a list of effective alphas. ...
Alice Wang's user avatar
0 votes
1 answer
493 views

Positive train score and negative test score in sklearn [duplicate]

I am doing a regression model using kfold cross validation using a dataset with ~200 data and noticed my r2 score on train data is positive(average 0.7) and my r2 test score is negative. What does it ...
Fuustack's user avatar
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. ...
Imen F's user avatar
  • 1
0 votes
1 answer
317 views

Random Forest Parameter Settings for Big Data

I have a big data set (with more than 9,000,000 rows) with 7 features and 1 label. The label is ordinal data. I would like to run a random forest regression. I'm fairly new to random forests so I have ...
LCheng's user avatar
  • 179
0 votes
1 answer
261 views

Prediction of Adaboost Classifier between 0 and 1

I have to use an Adaboost classifier to predict if the data is a signal (1) or a background (0) event. But since the output is expected to be 1 or 0 the ...
Wolfmercury's user avatar
0 votes
1 answer
282 views

Transform target/label variable into classes but classes are data-dependent: How to approach this correctly?

I was redirected from StackOverflow because my question is more about theory. I have a usual set-up with a pandas dataframe with some features and a numeric target variable (financial returns for ...
alphaH's user avatar
  • 37
0 votes
0 answers
739 views

LDA Feature Importantance Extraction - sklearn Python

I have run LDA from sklearn on a dataset and I have gotten pretty good separation between classes. Typically I can extract feature importance to determine which contributing factor is most important. ...
user334505's user avatar
0 votes
1 answer
153 views

How best to deal with missing event data

I have a data set which contains values like "last_foo" containing the number of days since the last time foo occurred. Naturally this feature contains NaNs for examples that have never foo'...
samtregar's user avatar
  • 101
0 votes
1 answer
3k views

max_depth vs. max_leaf_nodes in scikit-learn's RandomForestClassifier

What's the difference, if any at all, between max_depth and max_leaf_nodes in sklearn's RandomForestClassifier for a simple ...
Jingwei Yu's user avatar
1 vote
0 answers
187 views

lambda scaling in elastic net regression with glmnet vs sklearn

I am trying to get results to agree between glmnet and sklearn elastic net regression for a specific case where I can't normalise the response variable y. I know that for ridge regression (alpha = 0) ...
cno's user avatar
  • 111
1 vote
1 answer
159 views

Stop criterion is Infinitive in Perceptron in Sklearn

I read code in book "Hand-on Machine Learning in Sklearn and TensorFlow" by Aurelien Geron ...
Tan Phan's user avatar
  • 113
4 votes
0 answers
45 views

What is scikit-learn's LinearRegression doing when there are more features than observations? [duplicate]

I'm trying to understand what sklearn's LinearRegression (which should be using ordinary least squares) is doing when there are more features than observations. ...
dseok's user avatar
  • 41
0 votes
1 answer
492 views

Polynomial regression interaction features

In polynomial regression input vector $[a,b,c]$ is transformed into $[1, a, b, c, a^2, b^2, c^2, ab, ac, bc]$ before linear regression is applied. At least this is how ...
Kasia's user avatar
  • 3
1 vote
0 answers
87 views

What are the calculations or maths behind least-squares-minimizing in linear regression used by sklearn [duplicate]

I'm relatively new in the ML field, and this question came up when working with linear regression from sklearn library. After a bit of looking up in the documentation, it states Compute least-squares ...
Lifeng Qiu's user avatar
3 votes
2 answers
512 views

Why in the stacking of scikit-learn the estimators are fitted on the whole training data?

In chapter 7 of "Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow", the first step of stacking method is spliting the train data into two subsets. The first subset is used ...
wutao's user avatar
  • 33

1
3 4
5
6 7
36