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

How to split train/test datasets having equal classes proportion

I would like to know how I can split in an equal number the following Target 0 1586 1 318 in order to have the same proportion of 0 and 1 classes in a ...
3
votes
2answers
2k 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
3answers
203 views

ML algorithm for Music Features

I am a newbie in machine learning topic and I need to create model from music data. It contains features of the songs but it is not labeled. How can I create a model from that ? Do I need to use ...
3
votes
1answer
22k 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
4answers
4k views

How to interpret FPR and TPR in ROC curve?

I am playing with ROC and trying to draw some curves. I am using example from this scikit page. I do not understand one thing: when I print out the content of tpr and fpr, I see two arrays of numbers (...
3
votes
2answers
3k 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
2k views

Handling categorical features in Factorization Machines algorithm - Feature Hashing vs. One-Hot encoding

For solving a prediction problem I'm willing to use the Factorization Machines, a model that in addition to learning linear weights on features, learn a vector space for each feature to learn pairing ...
3
votes
1answer
115 views

Calibration using predict_proba vs class_weight

I am making a Random Forest Classifier to determine whether a sentence is "positive" (1), "negative"(-1) or "neutral"(0). However, I prefer having false negative than ...
3
votes
1answer
114 views

How to classify a new email as spam/not spam?

I am working on a small exercise for determining if an email is spam or not. My dataset is the following: ...
3
votes
1answer
305 views

How to get feature importance from RandomForest using scikit-multilearn library?

I am working on multi-label classification problem, binary case. As a target variable there are five columns with 0-1 values. For a model training I use scikit-multilearn library. Below is my code ...
3
votes
2answers
56 views

How to interpret ANOVA results?

I am trying to identify what attributes are not relevant in my dataset to remove them before fitting a classifier. The target is a categorical variable with three different values. I also have a lot ...
3
votes
2answers
228 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
3k 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
3k views

model.score and r2_score giving different values for a regression model

I am build a linear regression model and a decision tree model using sklearn. I want to compare the performance of these two models, I have calculated the r2_score for both the models. I have ...
3
votes
3answers
6k 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
23k 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
996 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
234 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
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 ...
3
votes
1answer
293 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
2answers
103 views

List of samples that each tree in a random forest is trained on in Scikit-Learn

In Scikit-learn's random forest, you can set bootstrap=True and each tree would select a subset of samples to train on. Is there a way to see which samples are used in each tree? I went through the ...
3
votes
1answer
28 views

Selecting a boundary on a binary classifier to optimal precision and recall

I have a logistic regression classifier that shows differing levels of performance for precision and recall at different probability boundaries as follows: The default threshold for the classifier to ...
3
votes
1answer
145 views

Confusion matrix in sklearn

If you look at this: ...
3
votes
2answers
440 views

How to Set the Same Categorical Codes to Train and Test data? Python-Pandas

NOTE: If someone else it's wondering about this topic, I understand you're getting deeper in the Data Analysis world, so I did this question before to learn that: You encode categorical values as ...
3
votes
1answer
4k views

Iterate over multiple dataframe rows at the same time

I have 16 different dataframes with the same number of rows/columns and another 2 separate dataframes with that same shape that i'm using to compare with the 16 dataframe values. I need to loop over ...
3
votes
2answers
86 views

How can I perform categorical encoding when the dataset is too large for memory?

I generally do preprocessing before fitting estimators using Scikit-Learn. My latest project is using significantly more data than I have used in the past, and whilst I know I can use online learning ...
3
votes
2answers
67 views

(Newbie) Decision Tree Classifier Splitting precedure

I have a dataset with 4 categorical features (Cholesterol, Systolic Blood pressure, diastolic blood pressure, and smoking rate). I use a decision tree classifier to find the probability of stroke. I ...
3
votes
1answer
166 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
91 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
1answer
3k views

Keras: How to connect a CNN model with a decision tree

I want to train a model to predict one's emotion from the physical signals. I have a physical signal and using it as input feature; ecg(Electrocardiography) I want to use the CNN architecture to ...
3
votes
1answer
940 views

Checkpoints in Sklearn

Is there a way to save the current state of your experiment so that you can pick up from where you left off in Sklearn similar to checkpoints in Keras?
3
votes
3answers
241 views

how does splitting occur at a node in a decision-tree with non-categorical data?

According to a website (:http://dataaspirant.com/2017/01/30/how-decision-tree-algorithm-works/) , these values are chosen randomly: I don't think this is the case with any optimized way of creating ...
3
votes
1answer
459 views

How to force weights to add to $1$ in Linear regression

I am using a linear regression using scikit-learn in python. However, I would like to force the weights to add to $1$. Is there a way to do this? I know that I need to add a constraint but am not able ...
3
votes
2answers
7k views

How to transform a folder of images in a csv file

I have a folder with a lot of images that I want to use to bild a classificator using a SVM model in python with sklearn. I've always used csv file as train/test set with sklearn, how can I make it? (...
3
votes
2answers
7k views

Create a binary-classification dataset (python: sklearn.datasets.make_classification)

I would like to create a dataset, however I need a little help. The dataset is completely fictional - everything is something I just made up. Since the dataset is for a school project, it should be ...
3
votes
2answers
9k views

How to find AUC metric value for keras model?

I have wanted to find AUC metric for my Keras model. Keras doesn't have any inbuilt function to measure AUC metric. So I found that write a function which calculates AUC metric and call this function ...
3
votes
1answer
12k 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
2answers
7k views

Class weight ineffective in sklearn

I'm dealing with an imbalanced dataset and as usual it's very easy to obtain a high accuracy, but the recall on the less frequent class is very low. I would like to improve on the false negative of ...
3
votes
1answer
2k 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
14k 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
922 views

SVM prediction time increase with number of test cases

I am using scikit-learn's SVM for the MNIST digit classification dataset. In order to improve the performance I extended the dataset by adding rotated samples. I was aware that SVM takes O(N^3) time ...
3
votes
1answer
143 views

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

I am trying to analyze soccer's data set: ...
3
votes
2answers
134 views

Preprocessing: StandardScaler() Do we really need mean to be zero?

For instance, many elements used in the objective function of a learning algorithm (such as the RBF kernel of Support Vector Machines or the l1 and l2 regularizers of linear models) assume that all ...
3
votes
1answer
49 views

IterativeImputer - Returning -0 and other wierd results

I am using IterativeImputer to impute my dataset. ...
3
votes
1answer
49 views

Any advantage of sklearn wrappers for xgboost over python API?

Are there any advantages of using the XGBoost sklearn wrappers XGBRegressor or XGBClassifier over using the Python API with the <...
3
votes
2answers
248 views

How to use hashing trick with field-aware factorization machines

Field-aware factorization machines (FFM) have proved to be useful in click-through rate prediction tasks. One of their strengths comes from the hashing trick (feature hashing). When one uses hashing ...
3
votes
3answers
75 views

Why does my KNeighborsClassifier graph look like this?

I'm new to data science/ml and working on using the sklearn libraries to classify data. I'm currently using the KNeighborsClassifier with 5 fold cross validation whilst tweaking the k value but its ...
3
votes
1answer
98 views

Is there any optimal way on feature selection for more than one classification algorithms?

I have a wine dataset with 13 features that indicates 3 different wine classes (target), and k-NN, SVM with linear kernel and SVM with rbf kernel algorithms to be tried with this dataset. My goal is ...
3
votes
1answer
120 views

Data sets that have strings and numerical data all in one column [closed]

Here's a code I wrote for pre-processing a data set. It works ...

1
5 6
7
8 9
38