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
5
votes
1answer
2k 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, ...
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
2answers
3k 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
3answers
1k views

How to Deploy a Scikit-learn Model into the Cloud?

I have generated a common Sklearn model for text classification which I want to make accessible in the cloud (there is no provider preference) as an API. So far the closest solution that I managed to ...
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 ...
4
votes
3answers
179 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
287 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
335 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
3answers
260 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
121 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
11k views

How to determine feature importance while using xgboost in pipeline?

How to determine feature importance while using xgboost (XGBclassifier or XGBregressor) in pipeline? ...
4
votes
2answers
285 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
2k views

Difference between learning_curve and validation_curve

What is the difference between these two curves: learning_curve and validation_curve ?
4
votes
3answers
6k 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: ...
4
votes
1answer
1k 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
59k views

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

I have trained and saved a model : ...
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
2answers
95 views

ExtraTreesRegressor criterion

As I understand, ExtraTreesRegressor from sklearn works by doing random splits instead of minimizing a metric like gini for ...
4
votes
3answers
323 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
2answers
6k 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
6k views

Sklearn: unsupervised knn vs k-means

Sklearn has an unsupervised version of knn and also it provides an implementation of k-means. If I am right, kmeans is done exactly by identifying "neighbors" (at ...
4
votes
2answers
712 views

Naive Bayes for SA in Scikit Learn - how does it work

Okay so i scrape data from the web on movie reviews. I also have already got my own 'dictionary' or 'lexicon' with words and their labels (1-poor, 2-ok, 3-good, 4-very good, 5-excellent). SO the ...
4
votes
1answer
534 views

Compute parameters of a PDF (probability density function) for which no closed form expression is available

I would like to compute parameters such as mean, variance, quantiles, etc. for a PDF which is only given as a piece of code. That is, it can only be evaluated numerically at given points; no closed-...
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
1answer
19k 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
18k 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
1answer
984 views

Using machine learning specifically for feature analysis, not predictions

I'm new to machine learning and have spent the last couple months having a blast using Sci-Kit Learn to try to understand the basics of building feature sets and predictive models. Now I'm trying to ...
4
votes
1answer
2k views

Scikit Learn Logistic Regression Memory Leak

I'm curious if anyone else has run into this. I have a data set with about 350k samples, each with 4k sparse features. The sparse fill rate is about 0.5%. The data is stored in a ...
4
votes
2answers
70 views

The impact of using different scaling strategy with Clustering

I'm currently learning about clustering. To practice clustering, I am using this dataset. After running K-means clustering for multiple values of k and plotting the results, I can see that scaling is ...
4
votes
1answer
362 views

How to balance class weights correct for a CNN in Keras, given an unbalanced data set?

I want to use class weights for training a CNN with a imbalanced data set. The question arise if the sum of the weights of all examples have to stays the same? My previous plan was to use the ...
4
votes
3answers
191 views

Unexpected results from scikit learn regression decision tree

Apologies for this newbie question. I have a scikit learn DecisionTreeRegressor with muti-variable output. If the output is in the format [ output_var1, ...
4
votes
3answers
2k 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 ...
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
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
11k 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 ...
4
votes
3answers
4k 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 (...
4
votes
2answers
124 views

Extremely high MSE/MAE for Ridge Regression(sklearn) when the label is directly calculated from the features

Edit: Removing TransformedTargetRegressor and adding more info as requested. Edit2: There were 18K rows where the relation did not hold. I'm sorry :(. After ...
4
votes
1answer
378 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 ...
4
votes
2answers
259 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 ...
4
votes
2answers
118 views

Hierarchical Clustering: Extract observations from large heatmap

I'm currently trying to visualize a large data set as heat map. That in itself works smoothly but I struggle with gaining insights from interestingly looking clusters. Specifically, I have two ...
4
votes
1answer
569 views

how to pass parameters over sklearn pipeline's stages?

I'm working on a deep neural model for text classification using Keras. To fine tune some hyperparameters i'm using Keras Wrappers for the Scikit-Learn API. So I builded a Sklearn Pipeline for that: <...
4
votes
1answer
3k views

Multi-label compute class weight - unhashable type

Working in a multi-label classification problem with 13 possibles outputs in my neural network with Keras, sklearn, etc... Each output can be an array like [0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1 ,0]. I ...
4
votes
1answer
516 views

Does Gradient Boosting detect non-linear relationships?

I wish to train some data using the the Gradient Boosting Regressor of Scikit-Learn. My questions are: 1) Is the algorithm able to capture non-linear relationships? For example, in the case of y=x^2,...
4
votes
2answers
3k views

Kmeans using silhouette_score

I am using silhouette_score to find the optimal k value. So I am running a for loop with a range of possible k values. I have added my code below. this program takes a very long time to run. Could you ...
4
votes
1answer
1k views

Product classification in e-commerce using attribute keywords

I am working on a product classification problem (E-Commerce) in which I have to identify product category based on keywords. Say for example, if input is given as 'Samsung Galaxy On Nxt 3 GB RAM 16 ...
4
votes
2answers
15k views

How to prevent/tell if Decision Tree is overfitting?

In SKLearn's documentation on Decision Trees, they say we should pay special attention not to overfit the tree. How can we do this? I am aware that using random forests may prevent it, but how do I ...
4
votes
1answer
373 views

Creating dummy variables to match fitted model at inference

I have built a machine learning classifier using Sklearn and pandas as my main tools. Now, one of the input features to the model is country (to letter country code such as US). I have fit a model ...
4
votes
2answers
730 views

Performance difference between decision trees and logistic regression when one of the features is a string

I have a set of features, one of which is a string. I convert the string to an integer by treating the string as a base 36 number (I only use the first 13 characters). Then I can use DecisionTrees ...

1 2 3
4
5
32