Questions tagged [scikit-learn]

scikit-learn is a popular machine learning package for Python that has simple and efficient tools for predictive data analysis. Topics include classification, regression, clustering, dimensionality reduction, model selection, and preprocessing.

Filter by
Sorted by
Tagged with
7
votes
2answers
179 views

migrating to python from R: specific questions

I have been using R and RStudio for prototyping and model building and due to some persisting problems (which would only be applicable to the environment that I am using in) we have decided to use ...
7
votes
1answer
4k views

sklearn: SGDClassifier yields lower accuracy than LogisticRegression

I'm participating in the kaggle Iceberg Classifier Challenge, where the idea is to classify whether an object present in a radar image is an iceberg or a ship. I am currently trying to implement ...
7
votes
1answer
1k views

Custom metrics for unbalanced classes problem in RandomForest or SVM

My dataset has highly unbalanced classes ‒ foreground of 30 classes with tens of samples against background set of >100k samples. Classifying foreground class as background is quite OK, while ...
7
votes
1answer
2k views

Extracting individual emails from an email thread

Most of the open source datasets are well formatted i.e each email message is separated well like the enron email dataset. But out in the real world it is highly difficult to separate a top email ...
6
votes
3answers
17k views

Poisson regression options in python

I want to predict count data. In my understanding both standard classification and regression are not well suited for this. A poisson or binomial regression algorithm seems to do the trick. I am ...
6
votes
5answers
789 views

Decision tree with final decision being a linear regression

Question: I want to implement a decision tree with each leaf being a linear regression, does such a model exist (preferable in sklearn)? Example case 1: Mockup data is generated using the formula: <...
6
votes
5answers
19k views

issue with oneHotEncoding

So i have a PandasDataFrame with categorical variables in a column which i want to one hot encode i've used the following code from an ML udemy course ...
6
votes
1answer
268 views

What are your thoughts on SKLearn's dismissal of GPUs for machine learning?

SKLearn has this broad claim in its FAQs: Outside of neural networks, GPUs don’t play a large role in machine learning today, and much larger gains in speed can often be achieved by a careful ...
6
votes
2answers
10k views

Is there a R implementation of isolation forest for anomaly detection?

Is there a R implementation of isolation forest for anomaly detection? Similar to the implementation from sklearn.
6
votes
2answers
678 views

Does using unimportant features hurt accuracy?

I'm using the scikit-learn gradient boosting classifier found here. If I run the classifier on the same data without seeding the random number generator, I get different feature importances, and ...
6
votes
1answer
884 views

Why Scikit and statsmodel provide different Coefficient of determination?

First of all, I know there is a similar question, however, I didn't find it so much helpful. My issue is concerning simple Linear regression and the outcome of R-Squared. I founded that results can ...
6
votes
1answer
401 views

Why you shouldn't upsample before cross validation

I have an imbalanced dataset and I am trying different methods to address the data imbalance. I found this article that explains the correct way to cross validate when oversampling data using SMOTE ...
6
votes
2answers
2k views

RandomForest and tree feature importance in scikit-learn

What is the difference between model.feature_importances_ and tree.feature_importances_ in the following code: ...
6
votes
3answers
5k views

RandomForest - Reasons for memory usage / consumption?

Which factors influence the memory consumption? Is it the number of trees (n_estimators) or rather the number of data records of the training data or something other?
6
votes
2answers
13k views

Obtaining a confidence interval for the prediction of a linear regression

The data I am working with is being used to predict the duration of a trip between two points. There are about 100 different trips in the data and ~90k observations. I am using the standard pattern: ...
6
votes
1answer
35k views

Number of features of the model must match the input. Model n_features is `N` and input n_features is `X`.

I am new to data science and trying get some results. I'm applying Decision Tree Classifier. When my train and test datasets' size are not equal I get an error `...
6
votes
2answers
8k views

Predicting probability from scikit-learn SVC decision_function with decision_function_shape='ovo'

I have a multiclass SVM classifier with labels 'A', 'B', 'C', 'D'. This is the code I'm running: ...
6
votes
2answers
13k views

How to determine feature importance while using xgboost in pipeline?

How to determine feature importance while using xgboost (XGBclassifier or XGBregressor) in pipeline? ...
6
votes
3answers
4k views

How to combine GridSearchCV with Early Stopping?

I'm a beginner in machine learning and want to train a CNN (for image recognition) with optimized hyperparameter like dropout rate, learning rate and number of epochs. The optimal hyperparameter I ...
6
votes
2answers
5k views

Naive Bayes: Divide by Zero error

OK this is my first time in ML and for starter I am implementing Naive Bayes. I have Cricket(sports) data in which I have to check whether the team will win or lost based on Toss Won|Lost and Bat ...
6
votes
3answers
5k views

What cost function and penalty are suitable for imbalanced datasets?

For an imbalanced data set, is it better to choose an L1 or L2 regularization? Is there a cost function more suitable for imbalanced datasets to improve the model score (...
6
votes
2answers
967 views

Retrieve dropped column names from `sklearn.impute.SimpleImputer`

The SimpleImputer class takes pandas dataframes and returns unlabeled numpy arrays. Which means that the SimpleImputer drops ...
6
votes
1answer
1k views

Is it valid to include your validation data in your vocabulary for NLP?

At the moment, I am following best practices and creating a "bag of words" vector with a vocabulary from the training data. My cross validation (and test) datasets are transformed using this model, ...
6
votes
2answers
3k views

Varying results when calculating scatter matrices for LDA

I'm following a Linear Discriminant Analysis tutorial from here for dimensionality reduction. After working through the tutorial (did the PCA part, too), I shortened the code using sklearn modules ...
6
votes
3answers
3k views

Linear kernel in SVM performing much worse than RBF or Poly

When trying to train a SVM on some Kaggle data, I have encountered a situation where the linear kernel fails to give any results. This doesn't make sense to me because the RBF kernel works just fine, ...
6
votes
3answers
2k views

Classifier and Technique to use for large number of categories

I am designing a scikit learn classifier for a sequence labelling task which has 5000+ categories and training data is at least 80 million and may grow upto an additional 100 million each year. I have ...
6
votes
3answers
4k views

Question about sklearn's StratifiedShuffleSplit

I'm reading through the book Hands-On Machine Learning with Scikit-Learn and Tensorflow by Aurélien Géron. In a regression project on California Housing Prices, he goes over the concept of stratified ...
6
votes
3answers
3k views

using sklearn class weight to increase number of positive guesses in extremely unbalanced data set?

Hi I have a poorly correlated and unbalanced data set I have to work with. The set is 2 classes, 0 has 96,000 values and 1 has about 200. When I run random forest or other methods I get an output like:...
6
votes
1answer
125 views

Why would a fake feature with random numbers get selected in feature importance?

I'm using a sklearn.ensemble.RandomForestClassifier(n_estimators=100) to work on this challenge: https://kaggle.com/c/two-sigma-financial-news I've plotted my ...
6
votes
3answers
5k views

Anyway to know all details of trees grown using RandomForestClassifier in scikit-learn?

I am building a standard RandomForest classifier (named model, see the code below) using scikit-learn package. Now, I want to get all parameters of one Randomforest classifier (including its trees (...
6
votes
2answers
2k views

Binary text classification with TfidfVectorizer gives ValueError: setting an array element with a sequence

I am using pandas and scikti-learn to do binary text classification using text features encoded using TfidfVectorizer on a DataFrame. Here is some dummy code that illustrates what I'm doing: ...
6
votes
1answer
999 views

How to use machine learning to extract product info from the titles of eBay listings

Reposting here because someone correctly pointed out it is better suited for here. So I have a bunch of titles of eBay listings. I want to extract product information from each title, so I can ...
6
votes
2answers
5k views

Is there any way to get samples in under each leaf of a decision tree in Sklearn ?

I have trained decision tree . I also have a graph of the tree ( ) . Now i want to see which samples (red circled ones ) are under which leafs . I am using sklearn's implantation . Is there any way ...
6
votes
1answer
7k views

How to customise cost function in Scikit learn's model?

For example, when I have a problem that false negative should be penalised more, how can I incorporate that requirement in the algorithm such as SVM?
6
votes
1answer
3k views

Isolation forest sklearn contamination param

I'm working on an unsupervised anomaly detection task on time series using isolation forest algorithm. I'm developing in Python, more in detail using sklearn. I found out a lot of examples on this, ...
6
votes
1answer
11k views

'RandomForestClassifier' object has no attribute 'oob_score_ in python

I am getting: AttributeError: 'RandomForestClassifier' object has no attribute 'oob_score_'. But I can see the attribute ...
6
votes
2answers
7k views

How to calculate KL-divergence between matrices

Given there are two matrices of dimensionality 100x2 with absolute values ranging from -50 to +50. Is it possible to determine the kl-divergence by applying the entropy algorithm from scipy.stats to ...
6
votes
2answers
495 views

Best way to scale across different datasets

I have come across a peculiar situation when preprocessing data. Let's say I have a dataset A. I split the dataset into A_train ...
5
votes
3answers
1k views

How to normalize data without knowing the min and max values?

I have a Lending club dataset from Kaggle; it contains many different columns: there are for example dummy variables, years, amount of the loan...ect I want to normalize the data in the training and ...
5
votes
1answer
3k views

What is GridSearchCV doing after it finishes evaluating the performance of parameter combinations that takes so long?

I'm running GridSearchCV to tune some parameters. For example: ...
5
votes
3answers
11k views

How to use sklearn train_test_split to stratify data for multi-label classification?

I am attempting to mirror a machine learning program by Ahmed Besbes, but scaled up for multi-label classification. It seems that any attempt to stratify the data returns the following error: ...
5
votes
1answer
4k views

How do I interpret the length-scale parameter of the RBF kernel?

According to the Scikit-Learn documentation for the RBF kernel: The length scale of the kernel. If a float, an isotropic kernel is used. If an array, an anisotropic kernel is used where each dimension ...
5
votes
3answers
148 views

Problem with basic understanding of polynomial regression

I have an understanding of simple linear regression. Clear that results in a fitted line like this: However, studying polynomial regression is a bit of a challenge having some questions about the ...
5
votes
1answer
6k views

Does increasing the n_estimators parameter in decision trees always increase accuracy

I'm using some ML algorithms (from sklearn lib) and on most of them there is a parameter n_estimators which is (if I understood well) the number of used trees. Intuitevely I would say that the more ...
5
votes
2answers
2k views

How can I use variable length inputs to train a regression model?

I'm working predicting a value $y \in \mathbb{R}$ from the value of $x_{n+1}$, where $n$ is the number of samples ($x_{i \in [1,n]}$) used for training. Each training sample $x_{i}$ is a time series ...
5
votes
1answer
2k views

Gaussian Mixture Models as a classifier?

I'm learning the GMM clustering algorithm. I don't understand how it can used as a classifier. Here are my thought: 1) GMM is an unsupervised ML algorithm. At least that's how ...
5
votes
2answers
1k views

SGDClassifier fit and partial_fit functions

I wanted to know what is the correct way to train the SGDClassier model on new data observations? Should I use the fit function or the ...
5
votes
1answer
2k views

Is shuffling training data beneficial for machine learning?

I was curious to know if shuffling ML training data is beneficial to better results? Sorry not a lot of wisdom here, but I have been reading a post from pythonprogramming.net for this topic. I ...
5
votes
1answer
3k views

How can l get 50 % examples in training set and 50% in test set for each class when splitting data?

l have a dataset of 200 examples with 10 classes. l would like to split the dataset into training set 50% and test set 50%. for each class, l have 20 examples. Hence, l would like to get for each ...
5
votes
1answer
3k views

Difference between RFE and SelectFromModel in Scikit-Learn

What is the difference between Recursive Feature Elimination (RFE) function and SelectFromModel in Scikit-Learn? Both seems exactly similar.

1 2
3
4 5
37