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
5
votes
3answers
3k views

Reg. Pandas factorize()

-Hi Experts- I just read about factorise() function in Pandas. Using this I'm able to encode (enumerate) my string values into numbers. But, now I'm not able to understand what numbers corresponds ...
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.
5
votes
3answers
2k views

Predicting contract churn/cancellation: Great model results does not work in the real world

I'm busy with a supervised machine learning problem where I am predicting contract cancellation. Although a lengthy question, I do hope someone will take the time as I'm convinced it will help others ...
5
votes
1answer
14k views

How to plot/visualize clusters in scikit-learn (sklearn)?

I have done some clustering and I would like to visualize the results. Here is the function I have written to plot my clusters: ...
5
votes
2answers
152 views

How to cluster a link traversal dataset

I'm using Google Analytics on my mobile app to see how different users use the app. I draw a path based on the pages they move to. Given a list of paths for say a 100 users, how do I go about ...
5
votes
1answer
776 views

Calculate confidence score of a neural network prediction

I am using a deep neural network model to make predictions. My problem is a classification(binary) problem. I wish to calculate the confidence score of each prediction. As of now, I use ...
5
votes
2answers
2k views

convert predict_proba results using class_weight in training

As my dataset is unbalanced(class 1: 5%, class 0: 95%) I have used class_weight="balanced" parameter to train a random forest classification model. In this way I penalize the misclassification of a ...
5
votes
1answer
260 views

Sklearn PCA with zero components example

I'm simply trying to repeat a benchmark from the sklearn's docs. The unclear part is: n_components = np.arange(0, n_features, 5). They are applying a PCA transform ...
5
votes
2answers
119 views

Online news classification

I am performing an online news classification. The idea is to recognize group of news of the same topic. My algorithm has these steps: 1) I go through a group of feeds from news sites and I recognize ...
5
votes
3answers
7k views

what should be the order of class names in sklearn tree export function (Beginner question on python sklearn)

I am trying a simple example with sklearn decision tree. I am giving "number,is_power2,is_even" as features and the class is "is_even" (of course this is stupid) Here is the code ...
5
votes
1answer
5k views

High RMSE and MAE and low MAPE

I have used a few regression models on the same dataset and obtained error metrics for them as shown below, The RMSE(Root Mean Squared Error) and MAE(Mean Absolute Error) for model A is lower than ...
5
votes
1answer
301 views

Can you use clustering to pick out signals in noisy data?

As my first project into data science, I would like to pick out the main clusters in noisy data. I think a good example would be trying to pick out certain links on a given StackExchange question that ...
5
votes
1answer
914 views

What's the difference between finding the average Euclidean distance and using inertia_ in KMeans in sklearn?

I've found two different approaches online when using the Elbow Method to determine the optimal number of clusters for K-Means. One approach is to use the following code: ...
5
votes
1answer
345 views

How backpropagation through gradient descent represents the error after each forward pass

In Neural NEtwork Multilayer Perceptron, I understand that the main difference between Stochastic Gradient Descent (SGD) vs Gradient Descent (GD) lies in the way of how many samples are chosen while ...
5
votes
1answer
5k 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: ...
5
votes
2answers
11k 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 ...
5
votes
2answers
157 views

Sklearn: applying cost complexity pruning along with pipeline

I have a data set with categorical variables. I have defined a decision tree algorithm and transformed these columns to numerical equivalent using one hot encoding functionality in sklearn: Create ...
5
votes
2answers
2k views

Columntransformer multiple columns with vector inputs

This is perhaps more of a coding question than data science so apologies if this is not the right platform to ask this. My question is related to the sklearn's <...
5
votes
1answer
2k views

How to avoid resampling part of pipeline on test data (imblearn package, SMOTE)

I am using the imblearn package to resample some data before applying other transformation/prediction techniques. Specfically, I am using SMOTE in a slightly unconventional way, as a data ...
5
votes
2answers
4k views

Sci-kit learn function to select threshold for higher recall than precision

When we care more that there should be no false negatives, as far as possible… ie. higher recall (video is suitable for kid or not), we should use (receiver operating characteristic) ROC (area under ...
5
votes
1answer
101 views

Gridsearch XGBoost for ensemble. Do I include first-level prediction matrix of base learners in train set?

I'm not quite sure how I should go about tuning xgboost before I use it as a meta-learner in ensemble learning. Should I include the prediction matrix (ie. df containing columns of prediction results ...
4
votes
5answers
5k 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 parameters for the ...
4
votes
4answers
6k views

How to save a knn model?

I need to save the results of a fit of the SKlearn NearestNeighbors model: knn = NearestNeighbors(10) knn.fit(my_data) How do you save to disk the traied ...
4
votes
3answers
203 views

Reward negative derivative on linear regression

I'm actually new to Data Science and I'm trying to make a simple linear regression with only one feature X ( which I added the feature log(X) before adding a polynomial features) on a motley dataset ...
4
votes
2answers
367 views

Training a model sample by sample

I'm training a Scikit model but it seems that in all examples, they call the fit method on the entire training set. What I want to do however is call it per sample (...
4
votes
2answers
732 views

Cross Validation - Why does more folds increase variation?

Can someone explain why increasing the number of folds in a cross validation increases the variation (or the standard deviation) of the scores in each fold. I've logged the data below. I'm working on ...
4
votes
2answers
6k views

NLTK Sklearn Genism Text to Topic

I aint no data scientist/machine learner. What Im Lookin for ...
4
votes
1answer
158 views

Follow Up Question - Why use fit when already have fit_transform?

This is a follow up question to: What's the difference between fit and fit_transform in scikit-learn models? I want to know why should we use fit at all when we ...
4
votes
3answers
792 views

Should I use keras or sklearn for PCA?

Recentl I saw that there is some basic overlapping of functionality between keras and sklearn regarding data preprocessing. So I am a bit confused that whether should I introduce a dependency on ...
4
votes
1answer
283 views

What happens if at leaf node both classes have same number of samples?

I analyzed a small dataset which had three features, so I kept max_depth of decision tree to be 3, in doing so I found it something intresting, there was a leaf node which had number of samples of ...
4
votes
2answers
186 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 ...
4
votes
1answer
4k views

Difference between learning_curve and validation_curve

What is the difference between these two curves: learning_curve and validation_curve ?
4
votes
3answers
13k views

How to check for overfitting with SVM and Iris Data?

I am using machine learning predictions for the sample iris dataset. For instance, I am using the support vector machines (SVMs) from scikit-learn in order to predict the accuracy. However, it returns ...
4
votes
1answer
3k views

Sklearn Aggregating Multiple Fitted Models Into A Single Model? (binary classification)

My problem context: dataset too big to fit into memory. binary classification [0,1] 30 csv files in a directory with exactly 30,000 samples (rows) each file contains 15,000 ...
4
votes
2answers
10k views

Learning rate in logistic regression with sklearn

In sklearn, for logistic regression, you can define the penalty, the regularization rate and other variables. Is there a way to set the learning rate?
4
votes
2answers
496 views

Compare Coefficients of Different Regression Models

in my project, I am using asuite of shallow and deep learning models in order to see which has the best performance on my data. However, in the pool of shallow machine learning models, I want to be ...
4
votes
1answer
101 views

For a square matrix of data, I achieve $R^2=1$ for Linear Regression and $R^2=0$ for Lasso. What's the intuition behind?

For a square matrix of random data, N columns and N rows. I am fitting two models, linear regression and Lasso. For the linear regression, I achieve a perfect score in train set, while in the Lasso I ...
4
votes
2answers
10k views

How do I get the feature importace for a MLPClassifier?

I use the MLPClassifier from scikit learn. I have about 20 features. Is there a scikit method to get the feature importance? I found clf.feature_importances_ but it seems that it only exists for ...
4
votes
1answer
2k views

Clustering by common elements in a list

Suppose I have these elements: a = [1, 6, 3, 4, 10, 32, 2, 54] b = [20, 5, 14, 25, 18, 1] c = [54, 3, 6, 12, 41, 1, 9] d = [3, 4, 1] e = [19, 20, 25, 5] Each ...
4
votes
1answer
64k views

AttributeError: 'numpy.ndarray' object has no attribute 'predict'

I have trained and saved a model : ...
4
votes
1answer
24k views

How to implement Python's MLPClassifier with gridsearchCV?

I am trying to implement Python's MLPClassifier with 10 fold cross-validation using gridsearchCV function. Here is a chunk of my code: ...
4
votes
2answers
21k views

Found input variables with inconsistent numbers of samples

I would appreciate if you could let me know how to resolve this error: Code: ...
4
votes
3answers
3k views

Same SVM configuration, same input data gives different output using Matlab and scikit-learn implementation of SVM, in a classification problem

I have a classification problem with 60 data points in a 2-dimensional feature space. The data originally is divided into 2 classes. Earlier I was using Statistics Toolbox of Matlab so it was giving ...
4
votes
1answer
3k views

Is it possible to have stratified train-test split of a set based on two columns?

Consider a dataframe that contains two columns, text and label. I can very easily create a stratified train-test split using ...
4
votes
2answers
195 views

ExtraTreesRegressor criterion

As I understand, ExtraTreesRegressor from sklearn works by doing random splits instead of minimizing a metric like gini for ...
4
votes
2answers
5k views

Incremental Learning with sklearn: warm_start, partial_fit(), fit()

I have built an ML model with the goal of making predictions for targets of the following week. In general, new data will come in and be processed at the end of each week and be in the same data ...
4
votes
1answer
5k views

How does class_weight work in Decision Tree

The scikit-learn implementation of DecisionTreeClassifier has a parameter as class_weight. ...
4
votes
2answers
65k views

AttributeError: 'numpy.ndarray' object has no attribute 'columns'

...
4
votes
3answers
393 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 ...

1 2 3
4
5
37