People who code: we want your input. Take the Survey

Tag Info

5

A pipeline is almost like an algorithm, but at a higher level, in that it lists the steps of a process. People use it to describe the main stages of project. This could include everything from gathering data and pre-processing it, right through to post-analysis of predictions. The pipeline is essentially a large chain of modules, which can be individually ...

4

The most common approach is a combination of these two strategies: Domain expertise - Given knowledge about the dataset and the goal of the model, choose the order that best manipulates the data to accomplish the goal of the project. Empirical evidence - Permutation the order and benchmark results. Pick the permutation that has the highest performance on ...

4

To include this logic into a pipeline you have to create a custom transformer. You need to ask yourself: [INIT] Are there any parameters in my logic? The variable you want to impute and the category you want this imputation to be based on. [FIT] What part of the logic is related to computing what the transformation will be? When you compute the median()...

3

With unpenalized linear models, there is no difference. The coefficients will just scale to counteract the new scale of the variables, and the intercept will shift to compensate for the centering. With penalized linear models though, there will be a difference. Since the standard deviation of a binary variable is at most $1/2$, you'll be increasing the ...

3

Sklearn has pipeline. If you have fit and transform attributes iteratively, you can make them pipeline by Pipeline class in sklearn.pipeline. Read the docs: https://scikit-learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html Additionally you can save and load a pipeline object by joblib.dump and joblib.load.

3

I figured out how to do that by monkey patching ParameterGrid.__iter__ and GridSearchCV._run_search methods. ParameterGrid.__iter__ iterates over all possible combinations of hyerparameters (dict of param_name: value). so i modified what it yields (one configuration of hyperparameters params) by adding "km__nbr_features" equal to 'tfidf__max_features': ...

2

I've tried this with an sklearn builtin dataset rather than yours, but the only difference appears to be the order of the columns. Switching the order of the elements in the transformer lists produces the same results. (In both cases, the numeric columns and categorical one-hot encoded columns are separated from each other, but are placed in the order that ...

2

For larger projects snakemake is a way to go for Python (it extends Python syntax, valid Python is valid snakemake). It originates in bioinformatics and even has its own publication; it is widley adopted and used by many projects (see the literature list in the first link or the citations for the linked article). For Jupyter notebook based projects, I made ...

2

One option is scikit-learn's ColumnTransformer applied to mixed types. ColumnTransformer is designed for the purpose of applying different preprocessing and feature extraction pipelines to different subsets of the features.

2

I'll agree with @BrianSpiering on general approaches, and with you that this is a no-free-lunch situation. But... Oversampling seems reasonably to fit in just about anywhere. It may depend on what kind of oversampling you're doing. I could see the new points messing up the distributions and thus affecting everything else, but it could potentially also ...

2

By default, GridSearchCV provides a score of nan when fitting the model fails. You can change that behavior and raise an error by setting the parameter error_score="raise", or you can try fitting a single model to get the error. You can then use the traceback to help figure out where the problem is. For the LogisticRegression, I can identify the ...

1

When you want to do sequential transformations, you should use Pipeline. imp_std = Pipeline( steps=[ ('impute', SimpleImputer(strategy='median')), ('scale', StandardScaler()), ] ) ColumnTransformer( remainder='passthrough', transformers=[ ('imp_std', imp_std, ['feat_1', 'feat_2']), ('std', StandardScaler(), ['...

1

The purpose of the pipeline is to assemble several steps that can be cross-validated together while setting different parameters. For this, it enables setting parameters of the various steps using their names Check the docs For your requirement, you will have to create multiple pipelines, you cannot do it via single pipeline.

1

The problem seems to be that your pipeline uses a fresh instance of RandomForestRegressor, so your param_grid is using nonexistent variables of the pipeline. There are two choices (I tend to prefer the second): Use rfr in the pipeline instead of a fresh RandomForestRegressor, and change your parameter_grid accordingly (rfr__n_estimators). Change ...

1

You are on the right path. It appears you might have analysis paralysis. You should start building, then see what works and what does not work. Here is code to get you started: from sklearn.ensemble import RandomForestRegressor from sklearn.feature_selection import VarianceThreshold from sklearn.model_selection import GridSearchCV from ...

1

It makes no sense to standardize one-hot encoded features. One-hot encoding implies the level of the measurement for a feature is nominal / categorial. Standardization implies the level of measure for a features is at least interval. For example, if the feature is country of origin. Since that feature is categorical, one-hot encoding makes sense. A person is ...

1

I solved the problem by creating a wrapper around pd.cut, which then applies pd.cut using the apply method of DataFrame: if isinstance(x, pd.Series): return pd.cut(x, bins_final, labels=labels, **kwargs) elif isinstance(x, pd.DataFrame): return x.apply(pd.cut, args=(bins_final,), axis=0, labels=labels, **kwargs)

1

1

You generally shouldn't apply resampling to the test set (although there are some differing opinions on whether to do so on various levels of validation data). imblearn has its own version of the pipeline to accomplish this; in particular, the pipeline docs say: The samplers are only applied during fit.

1

All(?) the sklearn transformers do a check on input data (check_X_y), which includes a check for an empty dataframe. You could probably monkey-patch out that check, but that seems like overkill. Instead, ColumnTransformer seems the way to go. Its main purpose fits your situation. It deals with an empty columns selector gracefully, by just not calling fit ...

1

Approach 1: create features before transforming If you want to create a categorical variable based on a numerical variable and then treat it in cat_pipeline, you need to do create it before the column transformer. Implement a transformer (called "bucketer" ?) that takes p variables and transforms it into p+1 (if you want to add the categorical ...

1

Your assumption is correct. Usually after column Transformation columns lose their names and get default values corresponding to their orders. Additional Info: You may try Eli5 from eli5 import show_weights,show_prediction show_weights(model) show_prediction(model,data_point) The later function shows the impact of every features for predicting a ...

1

TData science pipelines are designed to manage the end-to-end data lifecycle (e.g., clean data, fit model, and serve model). CI/CD pipelines are more general purpose software engineering tools around the automation of common tasks (e.g., running a testing suite). The advantage of using data science pipelines is that the pipelines have already primitives for ...

1

In this line: ("impute_stage", Imputer(missing_values=np.nan, strategy="median")) Because your input type is string, you shouldn't fill the null value to median (we cannot average string value). From the document, you can fill null value with a string constant like: Imputer(missing_values=None, strategy="constant", fill_value="NULL") to represent null ...

1

After a lot of research, I came to the conclusion that this is doable, but would require a lot of work. Essentially, the steps to achieve such a transformation are as follows: Use this version of the model exporter (or any other solution) to re-export the savedmodel with its variables (by default, the Model Zoo does not give the variables, only an ...

1

When you run your grid search, the clf step of the pipeline is replaced by each of RandomForestClassifier, LinearSVC, GaussianNB; you never actually use the MultiOutputClassifier. You should be able to just wrap the two offending classifiers with a MultiOutputClassifier. You'll need to prefix your hyperparameters with estimator__ to get through the MOC into ...

1

The imblearn package contains a lot of different samplers for easy over- or under-sampling of data. These samplers can not be placed in a standard sklearn pipeline. To allow for using a pipeline with these samplers, the imblearn package also implements an extended pipeline. This pipeline is very similar to the sklearn one with the addition of allowing ...

1

A pyspark.ml.PipelineModel is the result of calling the .fit() method of a pyspark.ml.Pipeline. This estimator is a sequence of Transformers and/or Estimators, all of which have a .transform() method. When you call the .transform() method of the pyspark.ml.PipelineModel-- say, when you want to make predictions using the trained model-- the .transform() ...

1

You might looking for sklearn.ensemble.VotingRegressor which takes the mean of two regression models. Here is an example to get you started: from sklearn.datasets import make_regression from sklearn.decomposition import PCA from sklearn.ensemble import GradientBoostingRegressor, RandomForestRegressor, VotingRegressor from sklearn....

1

As you said in your question, there is no way to do that with the baseline algorithms provided in MLLib. Two ways you could do that is by either : Creating a function to generate a Pipeline Creating a Meta Estimator that would take your base learners and the forking column. The first one is what you have stated in your question and the second one has been ...

Only top voted, non community-wiki answers of a minimum length are eligible