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
3
votes
2answers
216 views

Why do we choose principal components based on maximum variance explained?

I've seen many people choose # of principal components for PCA based on maximum variance explained. So my question is do we always have to choose principal components based on maximum variance ...
3
votes
2answers
6k 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?
3
votes
2answers
37k 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 ...
3
votes
2answers
232 views

Need machine learning algorithm to fill in time-series data

I am currently dealing with a time-series data set with cyclical gaps every 30 minutes (30 minutes of data, 30 minutes of no data). Is there a relatively simple way of using scikit-learn (or some ...
3
votes
2answers
2k views

sklearn.neighbors.NearestNeighbors - knn for unsupervised learning?

From basic theory I know that knn is a supervised algorithm while for example k-means is an unsupervised algorithm. However, at Sklearn there are is an implementation of KNN for unsupervised learning ...
3
votes
1answer
2k 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 ...
3
votes
1answer
13k views

tree.DecisionTree.feature_importances_ Numbers correspond to how features?

clf = tree.DecisionTreeClassifier(random_state = 0) clf = clf.fit(X_train, y_train) importances = clf.feature_importances_ ...
3
votes
2answers
2k views

How to use different classes of words in CountVectorizer()

Suppose I have a piece of writing and I want to assign probabilities to different genres (classes) based on its contents. For example Text #1 : Comedy 10%, Horror 50%, Romance 1% Text #2 : ...
3
votes
1answer
73 views

sklearn SimpleImputer too slow for categorical data represented as string values

I have a data set with categorical features represented as string values and I want to fill-in missing values in it. I’ve tried to use sklearn’s SimpleImputer but ...
3
votes
2answers
27 views

What is meaning of zip(kfold.split(X, Y) in sklearn

What is meaning of zip(kfold.split(X, Y) in sklearn? for (train, test)in zip(kfold.split(X, Y)):
3
votes
1answer
277 views

Difference between learning_curve and validation_curve

What is the difference between these two curves: learning_curve and validation_curve ?
3
votes
2answers
42 views

Decision Trees Should We Discard Low Importance Features?

I just started to work with feature selection. Let's say I have a decision tree model. I get its feature importances by tree.feature_importances_. In my model out ...
3
votes
2answers
215 views

Is it OK to use the testing sample to compare algorithms?

I'm working on a little project where my dataset have 6k lines and around 300 features, with a simple binary outcome. Since I'm still learning ML, I want to try all the algorithms I can manage to ...
3
votes
2answers
1k views

sklearn and pandas in AWS Lambda

I made a front end where I would like to make REST calls to an AWS Lambda interfaced with AWS API Gateway. I dumped my model as a pickle file (and so my encoders) which I initially trained locally. ...
3
votes
1answer
2k views

AUC ROC in keras is different when using tensorflow or scikit functions.

Two solutions for using AUC-ROC to train keras models, proposed here worked for me. But using tensorflow or scikit rocauc functions I get different results. ...
3
votes
1answer
3k views

Predict the accuracy of Linear Regression

How do I test if the predicted values in Linear Regression model are matching with the actuals? I tried using - Confusion matrix, but I get this error - ...
3
votes
1answer
2k views

How does sklearn KNeighborsClassifier compute class probabilites?

The KNeighborsClassifier has a method for predicting class probabilities. However, I cannot find any documentation describing how these probabilities are computed. ...
3
votes
2answers
793 views

Softmax: Different output scikit-learn and TensorFlow

I'm trying to learn a simple linear softmax model on some data. The LogisticRegression in scikit-learn seems to work fine, and now I am trying to port the code to TensorFlow, but I'm not getting the ...
3
votes
2answers
893 views

ROC curve for different hyperparameters of `RandomForestClassifier`?

I'm currently trying to train a RandomForestClassifier on a dataset consisting of 5000 instances with 12 (now) encoded features and a binary target label. Through <...
3
votes
2answers
160 views

Best ML technique to suggest predictor variables

In the following dataset, the first 4 columns are predictor variables and the engine running index is the response variable. ...
3
votes
1answer
247 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 ...
3
votes
1answer
271 views

Document Categorization Problem

I'm very new to data science in general, and have been tasked with a big challenge. My organization has a lot of documents that are all sorted on document type (not binary format, but a subjectively ...
3
votes
1answer
33 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 ...
3
votes
3answers
67 views

GridSearchCV vs RandomSearchCV and How it works?

GridSearchCV vs RandomSearchCV Can somebody explain in-detailed differences between GridSearchCV and RandomSearchCV? And how the algorithms work under the hood? As per my understanding from the ...
3
votes
1answer
42 views

Is the distance in Nearest Neighbors a good measure of similarity?

Let's train a Nearest Neighbor model with just one sample in it: In [48]: nn = NearestNeighbors().fit([[0, 1, 0, 0]]) So this one sample has just one significant ...
3
votes
1answer
88 views

Model comparison with CV using standard error

Discovering the ML world with sklearn, I'm testing a large panel of models onto my dataset. This is for learning purpose but also for work so I want the final model ...
3
votes
2answers
294 views

What does a negative coefficient of determination mean for evaluating ridge regression?

Judging by the negative result being displayed from my ridge.score() I am guessing that I am doing something wrong. Maybe someone could point me in the right direction? ...
3
votes
3answers
1k 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 ...
3
votes
1answer
106 views

K-nearest neighbors complexity

Why does the complexity of KNearest Neighbors increase with lower value of k? And when does the plot for k-nearest neighbor have smooth or complex decision boundary? Please explain in detail. And ...
3
votes
3answers
2k views

Sklearn SVM - how to get a list of the wrong predictions?

I am not an expert user. I know that I can obtain the confusion matrix, but I would like to obtain a list of the rows that have been classified in a wrong way in order to study them after ...
3
votes
1answer
1k 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 ...
3
votes
2answers
9k views

StratifiedKFold: ValueError: Supported target types are: ('binary', 'multiclass'). Got 'multilabel-indicator' instead

Working with Sklearn stratified kfold split, and when I attempt to split using multi-class, I received on error (see below). When I tried and split using binary, it ...
3
votes
2answers
10k 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 ...
3
votes
1answer
7k views

How does KNN handle categorical features

For a K nearest neighbors algorithm using a Euclidean distance metric, how does the algorithm compute euclidean distances when one(or all) of the features are categorical? Or does it just go by the ...
3
votes
1answer
1k views

python sklearn decision tree classifier feature_importances_ with feature names when using continuous values [closed]

I'm using sklearn Decision Tree Classifier with some continuous features. When I run export_graphviz I see the same features in more than one nodes and with different values. Example: I would like to ...
3
votes
1answer
313 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 ...
3
votes
1answer
138 views

How should I convert Logistic Regression's coefs into action strategy?

I am trying to analyze soccer's data set: ...
3
votes
1answer
112 views

Validation Curve Interpretations for Decision Tree

I'm working on a machine learning class, and we're using supervised learning right now, starting with decision trees. I'm using the UCI Credit Card dataset (whether or not certain people will default ...
3
votes
1answer
60 views

Machine Learning: Balanced training set but highly unbalanced prediction set? How to adjust?

I am trying to train a model to detect gender in a dataset of CEO speeches. Here are the datasets that I have: Final Dataset: 20K CEO voices analyzed (around 95% male) Testing dataset (?): 1K CEO ...
3
votes
1answer
29 views

Is it possible for a neural net to score as high as a different form of supervised learning?

I've been working with the Adult Census Income dataset from UCI http://archive.ics.uci.edu/ml/datasets/adult I've created two different models, one using a gradient boosted classifier with sklearn, ...
3
votes
1answer
102 views

Multilabel classifcation in sklearn with soft (fuzzy) labels

I have a model which is trained in sklearn on a 5-way classification problem, which performs relatively well (there are kNN and SVM versions, and both reproduce a test set with high accuracy). When ...
3
votes
1answer
67 views

How to prefer no choice instead of bad choice with sklearn decision tree

I'm using sklearn decision trees to classify documents in two possible types "type1" and "type2". I've isolated few features that seem pertinent and tried to combine them manually to evaluate the ...
3
votes
1answer
247 views

Implemented early stopping but came across the error SGDClassifier: Not fitted error in sklearn

Below is the simpler implementation of early stopping which i came across the book and wanted to try it. ...
3
votes
1answer
3k 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 ...
3
votes
1answer
2k views

Irregular Precision-Recall Curve

I'd expect that for a precision-recall curve, precision decreases while recall increases monotonically. I have a plot that is not smooth and looks funny. I used scikit learn the values for plotting ...
3
votes
1answer
3k views

How to use precomputed distance matrix and min_sample for DBSCAN clustering method?

I want to perform DBSCAN on my datapoints, but I don't have access to the data, I just have the pairwise distance of datapoints. Additionally, I have no idea about the number of clusters but I do want ...
3
votes
2answers
5k views

Large mean squared error in sklearn regressors

I'm a beginner in machine learning and I want to build a model to predict the price of houses. I prepared a dataset by crawling a local housing website and it consists 1000 samples and only 4 features ...
3
votes
1answer
9k views

MinMaxScaler broadcast shapes

I use a neural network with 3 inputs and 1 output with Keras. I'm using MinMaxScaler from sklearn to normalize my inputs in the range [0,1] my input shape is (XX,3) my output shape is (XX,1) I don't ...
3
votes
1answer
1k views

How to force DecisionTreeRegressor to use polyfit equation instead of mse at leaf level in python SKlearn

I am using python SKlearn DecisionTreeRegressor for my data. As DecisionTreeRegressor defines constant data at leaf node, my prediction is looking like a step, instead I wanted to force polyfit ...
3
votes
1answer
207 views

Ensemble Techniques for multilabel data

I observed that Adaboost or Bagging ensemble classifiers present in sklearn only work for single label training data. How do I use these for multilabel data?