random-forest

Make available .best_params_ after pipeline

Make available .best_params_ after pipeline Question: How to go about making available the clf.best_params_ after carrying a pipeline? For the code I have below, I get an: AttributeError: ‘GridSearchCV’ object has no attribute ‘best_params_‘ Here is my code: from sklearn.datasets import make_classification import numpy as np from sklearn import metrics from sklearn.metrics import accuracy_score from …

Total answers: 1

Converting a pandas Interval into a string (and back again)

Converting a pandas Interval into a string (and back again) Question: I’m relatively new to Python and am trying to get some data prepped to train a RandomForest. For various reasons, we want the data to be discrete, so there are a few continuous variables that need to be discretized. I found qcut in pandas, …

Total answers: 3

Python OpenCV RTrees does not load properly

Python OpenCV RTrees does not load properly Question: I have a trained RTrees model using OpenCV version 3.3.1 which I have saved and need to later load for prediction. I am attempting to use OpenCV’s RTrees to create a random forest classifier. However, I am not able to successfully load a model saved using the …

Total answers: 1

pipeline for RandomOversampler, RandomForestClassifier & GridSearchCV

pipeline for RandomOversampler, RandomForestClassifier & GridSearchCV Question: I am working on a binary text classification problem. As the classes are highly imbalanced, I am using sampling techniques like RandomOversampler(). Then for classification I would use RandomForestClassifier() whose parameters need to be tuned using GridSearchCV(). I am trying to create a pipeline to do these in …

Total answers: 2

How to compute precision,recall and f1 score of an imbalanced dataset for K fold cross validation?

How to compute precision,recall and f1 score of an imbalanced dataset for K fold cross validation? Question: I have an imbalanced dataset containing a binary classification problem. I have built Random Forest Classifier and used k-fold cross-validation with 10 folds. kfold = model_selection.KFold(n_splits=10, random_state=42) model=RandomForestClassifier(n_estimators=50) I got the results of the 10 folds results = …

Total answers: 2

Random Forest Feature Importance Chart using Python

Random Forest Feature Importance Chart using Python Question: I am working with RandomForestRegressor in python and I want to create a chart that will illustrate the ranking of feature importance. This is the code I used: from sklearn.ensemble import RandomForestRegressor MT= pd.read_csv(“MT_reduced.csv”) df = MT.reset_index(drop = False) columns2 = df.columns.tolist() # Filter the columns to …

Total answers: 8

How to tune parameters in Random Forest, using Scikit Learn?

How to tune parameters in Random Forest, using Scikit Learn? Question: class sklearn.ensemble.RandomForestClassifier(n_estimators=10, criterion=’gini’, max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=’auto’, max_leaf_nodes=None, bootstrap=True, oob_score=False, n_jobs=1, random_state=None, verbose=0, warm_start=False, class_weight=None) I’m using a random forest model with 9 samples and about 7000 attributes. Of these samples, there are 3 categories that my classifier recognizes. I know this is …

Total answers: 4

Is there easy way to grid search without cross validation in python?

Is there easy way to grid search without cross validation in python? Question: There is absolutely helpful class GridSearchCV in scikit-learn to do grid search and cross validation, but I don’t want to do cross validataion. I want to do grid search without cross validation and use whole data to train. To be more specific, …

Total answers: 4

How do you access tree depth in Python's scikit-learn?

How do you access tree depth in Python's scikit-learn? Question: I’m using scikit-learn to create a Random Forest. However, I want to find the individual depths of each tree. It seems like a simple attribute to have but according to the documentation, (http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html) there is no way of accessing it. If this isn’t possible, is …

Total answers: 1

Got continuous is not supported error in RandomForestRegressor

Got continuous is not supported error in RandomForestRegressor Question: I’m just trying to do a simple RandomForestRegressor example. But while testing the accuracy I get this error /Users/noppanit/anaconda/lib/python2.7/site-packages/sklearn/metrics/classification.pyc in accuracy_score(y_true, y_pred, normalize, sample_weight) 177 178 # Compute accuracy for each possible representation –> 179 y_type, y_true, y_pred = _check_targets(y_true, y_pred) 180 if y_type.startswith(‘multilabel’): 181 differing_labels …

Total answers: 3