People who code: we want your input. Take the Survey

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
10
votes
2answers
15k views

Parameters in GridSearchCV in scikit-learn

I am trying to build a model in scikit-learn. I used RandomForestClassifier as my method for classification. In order to improve the score and efficiency of my ...
1
vote
1answer
8k views

Error in model.fit() method in Keras

I was building a model for a classification problem in Keras for which I used the KerasClassifier, the wrapper scikit-learn. Below is the code for the same. ...
3
votes
1answer
357 views

Missing Categorical Features - no imputation

I've been reading about how to approach missing categorical features in test data, and the most common approach is to use imputation - for example using the last known value or getting the majority ...
1
vote
1answer
3k views

Sklearn randomforest online learning

Can I do online learning with random forests? I have a few million datapoints and the classifier fails to finish on the cross validation step. Can i break it up in chunks sequentially? Current code: ...
9
votes
3answers
9k views

Nested cross-validation and selecting the best regression model - is this the right SKLearn process?

If I understand correctly, nested-CV can help me evaluate what model and hyperparameter tuning process is best. The inner loop (GridSearchCV) finds the best ...
23
votes
1answer
21k views

RandomForestClassifier OOB scoring method

Does the random forest implementation in scikit-learn use mean accuracy as its scoring method to estimate generalization error with out-of-bag samples? This is not mentioned in the documentation, but ...
3
votes
1answer
3k views

Sklearn StratifiedKFold code explanation

While going through the following blog I came across the following code snippet ...
0
votes
1answer
302 views

How to reduce pipeline footprint in scikit-learn?

I had a post on stackoverflow. As it is related to scikit-learn, I am hoping that I can obtain some assistance from data scientists in this forum. https://stackoverflow.com/questions/38640815/python-...
0
votes
1answer
418 views

Using Scorer Object for Classifier Score Method for scikit-learn

I have written my custom scorer object which is necessary for my problem and which I've called "p_value_scoring_object". For the function sklearn.cross_validation.cross_val_score one of the ...
0
votes
2answers
5k views

Applying random forest model to a dataframe with multiple types of data [closed]

I am trying to solve the following classification problem: one has a large (~2-10 GB) .csv file containing a data frame of various types. In particular, there are columns containing numeric floats as ...
1
vote
1answer
4k views

Scikit Learn OneHotEncoded Features causing error in classifier

I’m trying to prepare data for input to a Decision Tree and Multinomial Naïve Bayes Classifier. This is what my data looks like (pandas dataframe): ...
2
votes
2answers
7k views

Clustering users based on buying behaviour

I have a set of data which indicates purchase transaction of users (~1 million records). User can have more than 1 purchase across time. Data is spread over 6-7 months. Attributes that I have are ...
4
votes
1answer
807 views

Sklearn Linear Regression examples

Could someone give an example of the application of Tf-idf with sparse data (lots of zeros) in sklearn? I am not quite sure where to insert the weight of Tf-idf and how to rightly obtain the weight. ...
0
votes
3answers
1k views

Multi-label Text Classification

I am trying to build a multi-label classifier for suggesting tags on blog posts. The textual data is full of noise. The approach I have been following until now was a BOW approach with Tf-idf ...
19
votes
3answers
31k views

Pandas Dataframe to DMatrix

I am trying to run xgboost in scikit learn. And I am only using Pandas to load the data into a dataframe. How am I supposed to use pandas df with xgboost? I am confused by the DMatrix routine ...
4
votes
4answers
3k views

Scikit Learn Missing Data - Categorical values

I have a dataset containing categorical features, which has 4 labels, and 4 features. (It is a meta classifier, so outputs from base classifier serve as input into this classifier) ...
0
votes
1answer
1k views

Sklearn feature selection stopping criterion (SelectFromModel)

Sklearn has several functions for feature selection that lets the user determine the size of the chosen subset. An example of this is SelectKBest where the user determines the value of "k", which is ...
1
vote
0answers
872 views

Average F1 Scores - scikit learn

I know there is f1_score metric to get all types of F1 scores(micro, macro and weighted). But I want to be able to print micro averaged F1 score using classification_report of sklearn. By default, it ...
0
votes
2answers
500 views

location of the resampled data from SMOTE

I am using SMOTE in Python to perform oversampling of the minor class in an unbalanced dataset. I would like to know the way SMOTE formats its output, that is, whether SMOTE concatenates the newly ...
2
votes
1answer
5k views

Date prediction - periodic recurrence

If I have some data regarding the occurence of an event on a certain date and some other variables regarding it (think fe.: I have data on which dates it rained, and some addtitional data like ...
4
votes
1answer
3k views

How does SelectKBest() perform feature selection?

SelectKBest(f_classif, k), where k is the number of features to select, is often used for feature selection, however, I am ...
3
votes
1answer
568 views

Vectorizing Skipgrams in sklearn

I want to try the skipgrams approach on my dataset. But I do not know how to vectorize it. For example, I have my cleaned document for which I got it's skipgrams. Now, how do I know vectorize it so ...
7
votes
2answers
7k views

TF-IDF vectorizer doesn't work better than countvectorizer

I am working on a multilabel text classification problem with 10 labels. The dataset is small, +- 7000 items and +-7500 labels in total. I am using python sci-kit learn and something strange came up ...
3
votes
1answer
265 views

Gaussian Mixture Models EM algorithm use average log likelihood to test convergence

I was investigating scikit-learn's implementation of the EM algorithm for fitting Gaussian Mixture Models and I was wondering how they did come up with using the average log likelihood instead of the ...
1
vote
0answers
560 views

Why initialization of Xgboost DMatrix reducec features number?

I am trying to understand following case: when I create new xgbost DMatrix xgX = xgb.DMatrix(X, label=Y, missing=np.nan) ...
1
vote
1answer
1k views

Feature selection for gene expression dataset

I am searching for a feature selection algorithm which selects features that are: relevant to discriminate groups of samples (for each sample a group label is provided) endowed with high variance ...
0
votes
1answer
8k views

What is the correct way to apply KNN to a time-series using a rolling window?

I have a time-series. The index is weekly dates and the values are a certain indicator that I made. I think I understand how to apply KNN in this situation but I'm not sure how exactly to do it. ...
2
votes
1answer
2k views

Support Vector Classification kernels ‘linear’, ‘poly’, ‘rbf’ has all same score

I build a classification model based on SVM and getting same results after running different kernels. Can you please let me know if is mistake ? also recall for all are identical. Thank you for help. ...
4
votes
1answer
485 views

Why is the number of samples smaller than the number of values in my decision tree?

I'm using scikit-learn RandomForestClassifier for a classification problem. When taking a closer look at one of the trees I noticed that the number of samples at the root was 662, but there were 507 ...
211
votes
10answers
288k views

What's the difference between fit and fit_transform in scikit-learn models?

I'm a newbie to data science, and I do not understand the difference between the fit and fit_transform methods in scikit-learn. ...
2
votes
1answer
1k views

predicting probability distribution for time series

I have time series of several variables. Just in one specific case one variable is linear combination of the rest. I want to predict probability distribution (that is not only best estimate but ...
2
votes
0answers
276 views

MLP batch iteration in python

I'm using the MLPRegressor in sklearn to train a network with approx 1000 inputs and a continuous output variable. Essentially, the issue is one of image classification (1000 pixels) with the ...
-6
votes
1answer
2k views

i want to build a linear regression

i am getting error when i try to run my script. I have stored my data in txt file formar ...
0
votes
1answer
646 views

SelectKBest for text analytics

I have a corpus of data ...
4
votes
3answers
2k views

Find effective feature on machine learning classification task with scikit-learn

I'm tackling a binary classification task using SVM implemented in python scikit-learn. Datasize is around 10,000 and the number of feature is 34. After finding nice parameter set (using ...
6
votes
2answers
719 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
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 ...
2
votes
1answer
1k views

How do I obtain the weight and variance of a k-means cluster?

I am trying to reproduce the results of this paper, but using python and the HMMlearn library instead of matlab. The paper describes a procedure for using HMM (Hidden Markov Model) in order to predict ...
3
votes
1answer
2k views

Decision Tree generating leaves for only one case

I had asked a question regarding predictive analysis for marketing earlier. Prediction model for marketing to prospective customers (using pandas) Still have some doubts about it, but I have a doubt ...
3
votes
1answer
3k views

How would I chi-squared test these simple results from A/B experiment?

I have results from an A/B experiment where users could do one of three things: Watch, Interact, or Nothing My data is like this: ...
1
vote
1answer
1k views

using “OneVsRestClassifier” from sklearn in Python to tune a customized binary classification into a multi-class classification

I have binary classification method name Fclassifier I need to apply it in a multi-class classification problem, this classifier doesn't have any decision_function (or predict_proba) and its core only ...
0
votes
1answer
12k views

How to annotate labels in a 3D matplotlib scatter plot?

I have made a 3x3 PCA matrix with sklearn.decomposition PCA and plotted it to a matplotlib 3D scatter plot. How can I annotate labels near the points/marker? Here ...
1
vote
0answers
58 views

Sklearn linear regression: adding new feature increases training time dramatically

As the title states, when I add another feature to the previous 200+ ones, the algorithm starts to train about 10 minutes, while earlier it trained only for a minute. Can anybody please explain me ...
5
votes
1answer
1k views

Prediction model for marketing to prospective customers (using pandas)

I'm currently working on a part-time project which involves predicting the likelihood of customers going to buy a product using data analytics. The company I'm interning with has given me a customer ...
0
votes
2answers
4k views

Use of cross validation for Polynomial Regression

I've two text files which contains my data. One text file on X axis another text file on Y axis Then using scatter function from python I did the data visualization After that, I used polyfit function ...
4
votes
1answer
13k views

Python : How to use Multinomial Logistic Regression using SKlearn

I have a test dataset and train dataset as below. I have provided sample data with min records, but my data has more than 1000's of record. Here if you see E is my ...
2
votes
1answer
494 views

Can a Gradient Boosting Regressor be tuned on a subset of the data and achieve the same result?

I am working with a large data set (~9M rows with 20+ features). Is it ok to tune via grid search on a fraction of the data (~100k rows) to determine optimal hyperparameters? This is mostly for ...
7
votes
1answer
8k views

KL-divergence returns infinity

Given an original probability distribution P, I want to measure how much an approximation Q differs from the initial distribution. For that I calculate the KL-divergence via ...
3
votes
1answer
3k views

decision trees on mix of categorical and real value parameters

I have about 3,000,000 samples and each sample is described by a list of size about 20. Some elements in this list are categorical, for example name of cities, day of week, etc. (some categories have ...
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 ...