Questions tagged [scikit-learn]

Scikit-learn is a Python module comprising of simple and efficient tool for machine learning, data mining and data analysis. It is built on NumPy, SciPy, and matplotlib. It is distributed under the 3-Clause BSD license.

Filter by
Sorted by
Tagged with
189
votes
9answers
242k 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. ...
131
votes
3answers
78k views

When to use One Hot Encoding vs LabelEncoder vs DictVectorizor?

I have been building models with categorical data for a while now and when in this situation I basically default to using scikit-learn's LabelEncoder function to transform this data prior to building ...
34
votes
2answers
166k views

train_test_split() error: Found input variables with inconsistent numbers of samples

Fairly new to Python but building out my first RF model based on some classification data. I've converted all of the labels into int64 numerical data and loaded into X and Y as a numpy array, but I am ...
46
votes
6answers
78k views

Does scikit-learn have forward selection/stepwise regression algorithm?

I'm working on the problem with too many features and training my models takes way too long. I implemented forward selection algorithm to choose features. However, I was wondering does scikit-learn ...
27
votes
3answers
26k views

StandardScaler before and after splitting data

When I was reading about using StandardScaler, most of the recommendations were saying that you should use StandardScaler before ...
12
votes
2answers
36k views

How to adjust the hyperparameters of MLP classifier to get more perfect performance

I am just getting touch with Multi-layer Perceptron. And, I got this accuracy when classifying the DEAP data with MLP. However, I have no idea how to adjust the hyperparameters for improving the ...
14
votes
2answers
7k views

How to train model to predict events 30 minutes prior, from multi-dimensionnal timeseries

Experts in my field are capable of predicting the likelyhood an event (binary spike in yellow) 30 minutes before it occurs. Frequency here is 1 sec, this view represents a few hours worth of data, i ...
8
votes
2answers
9k views

How to plot cost versus number of iterations in scikit learn?

One of the recommendations in the Coursera Machine Learning course when working with gradient descent based algorithms is: Debugging gradient descent. Make a plot with number of iterations on the x-...
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) ...
4
votes
1answer
4k views

Is it possible to customize the activation function in scikit-learn's MLPClassifier?

Scikit-learn lists these as the implemented activation functions for it's multi-layer perceptron classifier: ...
1
vote
1answer
688 views

String handling by OneHotEncoder

I am reading everywhere on new questions and blogs that since version 0.20, OneHotEncoder is able to handle string features. Moreover, the documentation is what looks more ambiguous. Here are the ...
19
votes
1answer
16k views

RandomForestClassifier OOB scoring method

Is the random forest implementation in scikit-learn using mean accuracy as its scoring method to estimate generalization error with out-of-bag samples? This is not mentioned in the documentation, but ...
40
votes
4answers
27k views

How to force weights to be non-negative in Linear regression

I am using a standard linear regression using scikit-learn in python. However, I would like to force the weights to be all positive for every feature (not negative), is there any way I can accomplish ...
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 ...
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 ...
24
votes
3answers
10k views

Difference between OrdinalEncoder and LabelEncoder

I was going through the official documentation of scikit-learn learn after going through a book on ML and came across the following thing: In the Documentation it is given about ...
11
votes
3answers
49k views

How can I fit categorical data types for random forest classification?

I need to find the accuracy of a training dataset by applying Random Forest Algorithm. But my the type of my data set are both categorical and numeric. When I tried to fit those data, I get an error. ...
4
votes
2answers
18k views

ValueError: Input contains NaN, infinity or a value too large for dtype('float64') [duplicate]

I am trying to fit my data into my model which takes numpy as input, so I feed the model with the dataframe values ...
6
votes
1answer
9k 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 ...
0
votes
2answers
121 views

What happens when scikit-learn does a Lasso Model?

I have started an MLS course. As a beginner and non-mathematician it has been hard. I am trying to understand the exercise about Lasso Models. I have done Lasso models on R-cran, but this is my first ...
0
votes
3answers
9k views

Sklearn ValueError: X has 2 features per sample; expecting 11

I try to visualizing multiple logistic regression but I get the above error. I'm practicing on red wine quality data set from kaggle. Here is a full traceback: ...
75
votes
6answers
103k views

strings as features in decision tree/random forest

I am doing some problems on an application of decision tree/random forest. I am trying to fit a problem which has numbers as well as strings (such as country name) as features. Now the library, scikit-...
99
votes
12answers
167k views

Train/Test/Validation Set Splitting in Sklearn

How could I split randomly a data matrix and the corresponding label vector into a X_train, X_test, X_val, y_train, y_test, y_val with Sklearn? As far as I know, ...
10
votes
4answers
22k views

Clustering for mixed numeric and nominal discrete data

My data includes survey responses that are binary (numeric) and nominal / categorical. All responses are discrete and at individual level. Data is of shape (n=7219, p=105). Couple things: I am ...
12
votes
1answer
4k views

Feature importance with high-cardinality categorical features for regression (numerical depdendent variable)

I was trying to use feature importances from Random Forests to perform some empirical feature selection for a regression problem where all the features are categorical and a lot of them have many ...
23
votes
2answers
40k views

Can you explain the difference between SVC and LinearSVC in scikit-learn?

I've recently started learning to work with sklearn and have just come across this peculiar result. I used the digits dataset ...
12
votes
1answer
16k views

Feature selection using feature importances in random forests with scikit-learn

I have plotted the feature importances in random forests with scikit-learn. In order to improve the prediction using random forests, how can I use the plot information to remove features? I.e. how to ...
23
votes
5answers
11k views

Improve the speed of t-sne implementation in python for huge data

I would like to do dimensionality reduction on nearly 1 million vectors each with 200 dimensions(doc2vec). I am using TSNE ...
9
votes
4answers
15k views

Interpreting Decision Tree in context of feature importances

I'm trying to understand how to fully understand the decision process of a decision tree classification model built with sklearn. The 2 main aspect I'm looking at are a graphviz representation of the ...
15
votes
3answers
3k views

Predict the best time of call

I have a dataset including a set of customers in different cities of California, time of calling for each customer, and the status of call (True if customer answers the call and False if customer does ...
5
votes
2answers
10k views

Xgboost predict probabilities

When using the python / sklearn API of xgboost are the probabilities obtained via the predict_proba method "real probabilities" or do I have to use ...
25
votes
3answers
74k views

How to get p-value and confident interval in LogisticRegression with sklearn?

I am building a multinomial logistic regression with sklearn (LogisticRegression). But after it finishes, how can I get a p-value and confident interval of my model? It only appears that sklearn only ...
15
votes
2answers
58k views

How does SelectKBest work?

I am looking at this tutorial: https://www.dataquest.io/mission/75/improving-your-submission At section 8, finding the best features, it shows the following code. ...
16
votes
2answers
22k views

How to calculate the fold number (k-fold) in cross validation?

I am confused about how I choose the number of folds (in k-fold CV) when I apply cross validation to check the model. Is it dependent on data size or other parameters?
7
votes
1answer
2k views

Naive Bayes Should generate prediction given missing features (scikit learn)

Seeing that Naive Bayes uses probability to make a prediction, and treats features as being conditionally independent of each other, then it makes sense that the model can still make a prediction ...
7
votes
1answer
936 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 ...
4
votes
5answers
2k views

GridSearch without CV

I create a Random Forest and Gradient Boosting Regressor by using GridSearchCV. For the Gradient Boosting Regressor it takes too long for me. But i need to know which are the best Parameter for the ...
3
votes
1answer
3k views

Extract the “path” of a data point through a decision tree in sklearn

I'm working with decision trees in python's scikit learn. Unlike many use cases for this, I'm not so much interested in the accuracy of the classifier at this point so much as I am extracting the ...
2
votes
1answer
224 views

ML - Service Desk classification

I'm trying to explore an use-case in ML but stuck at a point. May i please request your advise please. Have a service desk web application for logging tickets, which is essentially a form having ...
1
vote
2answers
648 views

What is the formula to calculate the precision, recall, f-measure with macro, micro, none for multi-label classification in sklearn metrics?

I am working in the problem of multi-label classification tasks. But I would not able to understand the formula for calculating the precision, recall, and f-measure with macro, micro, and none. ...
13
votes
1answer
22k views

scikit-learn n_jobs parameter on CPU usage & memory

In most estimators on scikit-learn, there is an n_jobs parameter in fit/predict methods for ...
10
votes
2answers
14k 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 ...
9
votes
2answers
9k views

How to use Cohen's Kappa as the evaluation metric in GridSearchCV in Scikit Learn?

I have class imbalance in the ratio 1:15 i.e. very low event rate. So to select tuning parameters of GBM in scikit learn I want to use Kappa instead of F1 score. My understanding is Kappa is a better ...
8
votes
2answers
636 views

Is over fitting okay if test accuracy is high enough? [duplicate]

I am trying to build a binary classifier. I have tried deep neural networks with various different structures and parameters and I was not able to get anything better than ...
6
votes
2answers
6k 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: ...
5
votes
2answers
8k views

How to plot learning curve and validation curve while using pipeline

I would appreciate if you could let me know in the following example code: ...
4
votes
3answers
347 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 ...
4
votes
1answer
2k views

Machine learning - 'train_test_split' function in scikit-learn: should I repeat it several times?

I am a beginner in machine learning, and I hope someone can help me. In Python's 'scikit-learn' library, the function 'train_test_split' splits the dataset into training and test sets. This is done ...
4
votes
2answers
120 views

scikit-learn RandomForestClassifier always hits 100% test accuracy

I have been playing with a toy problem to compare the performance and behavior of several scikit-learn classifiers. Brief, I have one continuous variable X (which contains two samples of size N, each ...
3
votes
2answers
41k views

Could not convert string to float error on KDDCup99 dataset

I am trying to perform a comparison between 5 algorithms against the KDD Cup 99 dataset and the NSL-KDD datasets using Python and I am having an issue when trying to build and evaluate the models ...