New answers tagged

0

I'm not sure it's possible to "transfer" the feature importances from model to model in a Random Forest Classifier. Although I think there are two work-arounds you may be able to use. The first is the "warm-start" parameter. According to the sklearn random forest docs (https://scikit-learn.org/stable/modules/generated/sklearn.ensemble....


0

You can extract the feature importance with importances = classifier.feature_importances_ ìmportances is a numpy array in with sum equal to one. Warning: impurity-based feature importances can be misleading for high cardinality features (many unique values). Check sklearn.inspection.permutation_importance as an alternative. All information in the answer in ...


0

You don't want your model to learn anything from the test dataset. You just want to apply the learnings from your trained dataset. So, we only apply transform operation on test dataset and fit_transform operation on the train dataset.


0

Were your rescaled MSE and RMSE appear larger at the end? Should they be equal to the values before applying inverse transform?


1

You are asking about multioutput regression. The class you talked about sklearn.linear_model.LinearRegression supports this out of the box. import numpy as np from sklearn.linear_model import LinearRegression # features A = 10 # number of values to predict B = 15 # number of rows in dataset m = 100 x = np.ones((m, A)) y = np.ones((m, B)) model = ...


0

I Highly recommend using Pipelines In the words of Andreas C. Muller Itself... "If you are not using pipelines, you maybe are doing it wrong. So in your case, this would be: import pandas as pd from sklearn.pipeline import Pipeline from sklearn.decomposition import PCA from sklearn.impute import SimpleImputer feom sklearn.preprocesing import ...


0

Just do one thing From sklearn import * The problem will be fixed


0

You are trying to scale just one record, so you need to save the Scaler fitted on the training data sc = StandardScaler() sc.fit(x) x = sc.transform(x) y_pred = regressor.predict(sc.transform(np.array([[6.5]])) Make sure that the number of features is same in both cases otherwise you will get other errors. A Working example from sklearn.preprocessing ...


0

Additionally, in case I upweight my classes with compute_class_weight(), I assume that no further class distribution should be taken into consideration downstream (so when I use RandomForestClassifier(), class_weight hyperparameter shouldn't be ='balanced', again, because this would further distort the weights proportionality that is already set before. Is ...


1

It doesn't, the workflow when training a model is like that: Create 10 evenly distributed splits from the dataset using stratified shuffle train set = 8 splits; validation set = 1 split; test set = 1 split Shuffle the train set and the validation set and create minibatches from them Train for one epoch using the batches Repeat from step 3 until all epochs ...


0

You can either validate your results on the test set or if you want to use KFold then you could first concatenate the train and test set first and then use KFold splitting to evaluate your results. Hope it helps!


0

Yes, you can. Instead of using lda.fit(...)or lda.fit_transfrom(...) you basically just need to call lda.partial_fit(...). Here you take a mini-batch to update your model. See this link for more information.


0

It seems that your self.clf points to your Method. At the end, you are probably printing the features importance of a unique classifier. Maybe you should copy it: from sklearn.base import clone class NoCVMethod: [...] self.clf = clone(Method) # only copy the estimator # OR self.clf = deepcopy(Method) # if you want to also copy the data ...


0

You could use a memmap import numpy as np from tempfile import mkdtemp import os.path as path filename = path.join(mkdtemp(), 'newfile.dat') # or you could use another dat file that already constains your dataset # supposing your data is loaded in a variable named "data" fp = np.memmap(filename, dtype='float32', mode='w+', shape=data.shape) fp[:] ...


0

Based on the doc you provide, orientation is in radians, ranging from -pi/2 to pi/2 counter-clockwise: orientation : float. Angle between the 0th axis (rows) and the major axis of the ellipse that has the same second moments as the region, ranging from -pi/2 to pi/2 counter-clockwise. Moreover, as it is said in the regionpropos doc, since 0.16.0, they use &...


0

You have to create labels for each of the images and then split it into train and test. I believe you have 20,000 images - so you have to also have 1 label for each image not jus the 4 categories alone in an array. One of the most important steps in training a DNN model to do image classification (as is your case) or any image related task is creating labels ...


0

The simplest way I can think of is using streamlit as the framework to develop the app (which is based on Python scripts, really simple) which is very focused on displaying data, graphs and showing flexibility to play with several parameters values + Heroku as the deployment service provider, also via simple commands.


0

this can be done in multiple ways i am not one hundred percent understand the question because it is badly worded but there are 3 ways! if you are doing this for a neural network you can use keras embedding layer and to create the sequence to feed to this embedding layer you can use one hot and padding from the preprocessing packages of course the sequence ...


0

I understand you must have researched before opting the regression model.But I want to highlight one thing here that since that data is time series one,we have to be more careful here and use the models which takes the account of moving average and other time series factors. Also,cross validation is different for timeseries analysis. Having said that please ...


0

It is a correct approach to standardize on your training features. In that way, you ensure not to give any information from the testing set to the training set. About features scaling, if you have too many samples to fit your scaler at once, you could use the partial_fit (see here) method of StandardScaler in sklearn. Load sequentially your training features ...


0

Pre-pruning is handled by a variety of parameters: max_depth, min_samples_split, min_samples_leaf, min_weight_fraction_leaf, max_leaf_nodes, and min_impurity_decrease. Post-pruning is relatively new to sklearn, and is accomplished with minimal cost-complexity pruning, parameter ccp_alpha.


0

If you use label binarization function from scikit learn for encoding the labels before training then it has a built in inverse_transform function Please go through this link /https://scikit-learn.org/stable/modules/preprocessing_targets.html/


0

If you are using ordinal data Use this to encode from sklearn.preprocessing import OrdinalEncoder oe=OrdinalEncoder() social['Gender']=oe.fit_transform(social[['Gender']]) Use this to decode social['Gender']=oe.inverse_transform(social[['Gender']]) If you are using nominal variables Use this to encode from sklearn.preprocessing import OneHotEncoder ...


0

One thing you can do is browse your prediction vector, get the indexes of "1" responses, and then check those indexes in y_test. if your y_test[index] is also a "1" class, then select the row by index in X_test I tested this, it works for me. In my case, my X and y are pandas.DataFrame. import pandas as pd from sklearn....


0

Just like all other Class, you have different methods i.e.fit, transform, fit_transform fit(self, X[, y]) Fit the model with X. fit_transform(self, X[, y]) - Fit the model with X and apply the dimensionality reduction on X. transform(self, X) - Apply dimensionality reduction to X. X is projected on the first principal components previously extracted from a ...


0

You want to know the nearest neighbor of you unlabeled data in you labeled cluster. Using sklearn, you can fit a NearestNeighbors() class with a giving metric, algorithm (Ball-tree, KD-tree,...) and all other parameters (see here). Then get the labeled nearest neighbor from your unlabeled datapoint and its distance by using kneighbors() method. Here is a ...


0

Usually learning rate would be between 0.0 to 1.0 , please go ahead by specifying values in those range. This thread would be definitely helpful for your further research and reference Thanks, Durga


0

Some ML algorithms require standardisation of data and some work better with standardisation. In the case of neural nets (NN), standardisation often improves performance since NN can have a hard time dealing with "very different" scales. What you can do is to standardise each $x$ column to have mean 0 and standard deviation (sd) 1 (substract mean ...


0

In short: Scaling is indeed desired. Standardizing and normalizing should both be fine. And reasonable scaling should be good. Of course you do need to scale your test set, but you do not "train" (i.e. fit) your scaler on the test data - you scale them using a scaler fitted on the train data (it's very natural to do in SKLearn). For example, if ...


0

My first comment would be that you have to remember that Tree-based models are not scale-sensitive and therefore scaling should not affect model's performance, so as you well mention it should a problem with the feature itself. If anyway you want to scale all your features you could use MinMaxScaler with the min and max values, being the min and max fo the ...


1

I see two solutions: either you pass a list of dictionnaries to param_grid avoiding irrelevant combinations or you use a single variable in your pipeline for feature_selector__feature__selector_k and classifier__input_shape First solution: you can generate the right list of combinations using something close to this: param_grid = [ { '...


4

One option would be to feed an array of both variables to the stratify parameter which accepts multidimensional arrays too. Here's the description from the scikit documentation: stratify array-like, default=None If not None, data is split in a stratified fashion, using this as the class labels. Here is an example: import numpy as np import pandas as pd ...


0

After digging down too much and some help from sklearn2pmml creator, I managed to filter the final columns to be passed to the classifier. Note : Here recorder is DataFrameMapper object. 1.Getting categorical column indexes. cat_cols = [recorder.transformed_names_.index(c) for c in categoricalCols if c in recorder.transformed_names_] 2.Adding ...


0

Thanks to suggestions from @BenReiniger I reduced the inverse regularisation strength from C = 1e5 to C = 1e2. This allowed the model to converge, maximise (based on C value) accuracy in the test set with only a max_iter increase from 100 -> 350 iterations. The learning curve below still shows very high (not quite 1) training accuracy, however my research ...


1

First, I generally agree that encoding unordered categories as consecutive integers is not a great approach: you are adding a ton of additional relationships that aren't present in the data. CART First, let me point out (because I nearly forgot) that there are two main types of decision tree: CART and the Quinlan family. For the Quinlan family, categorical ...


0

This works the way you would want out of the box. pipeline takes standard scaler class No, pipelines get initialized with estimator instances, not the classes. (This is why you need the parentheses in the steps, e.g. StandardScaler().) That is, the following works: from sklearn.datasets import load_breast_cancer from sklearn.preprocessing import ...


1

Your data looks logarithmic. Try using the scipy.optimize curve_fit() function to find the approximate log coefficients. I tried several built-in python functions, but couldn't get a good fit on any of them, but they can be used as a starting point. Finally, I ran the curve_fit() function on the data you posted, and after making a few adjustments, I was able ...


0

is it true that Label Encoding will be misinterpreted as a numeric scale by scikit-learn trees? Yes, SciKit-Learn treats it as Numeric value. Hence, it will impact the depth of Tree and result in different Tree structure. On results - Definitely, different hyperparameter tuning will be required for different methods but I am not sure about the fact that ...


0

As mentioned in its documentation, it is advisable to use a power of 2 as the number of features; otherwise, the features will not be mapped evenly to the columns. Also, it is suggested to leave the number of features as its default value of 2 ** 20 for a real-world setting. Select a lower value such as 2 ** 18 when memory or downstream model size is an ...


1

I've often had LogisticRegression "not converge" yet be quite stable (meaning the coefficients don't change much between iterations). Maybe there's some multicolinearity that's leading to coefficients that change substantially without actually affecting many predictions/scores. Another possibility (that seems to be the case, thanks for testing ...


0

Feature selection or Feature engineering is more of an Art than just applying readily available techniques. I will suggest you to do/learn intelligent EDA and try to eliminate/create/merge features. - Kaggle has many kernels/discussions on this topic. - For an enriched intuition, please read this book esp. chapter#04. Feature Engineering and Selection. ...


0

It is fine to apply feature selection technique on one hot encoded variables. Because if one particular segment of that variable is correlated with your target, then it is a good news. Your model will understand the scenario better. Or, You can label encode your categorical variable first so that you still have 30 variables (29 numerical + 1 label-encoded ...


0

As you've mentioned you can use the function by sklearn, I don't see the problem using it (perhaps I'm missing something) import pandas as pd from sklearn.datasets import dump_svmlight_file def df_to_libsvm(df: pd.DataFrame): x = df.drop('label', axis=1) y = df['label'] dump_svmlight_file(X=x, y=y, f='libsvm.dat', zero_based=True) Regarding the ...


0

I suggest trying the sklearn module KNNImputer. KNN will use clustering to calculate the null/missing values based on the data that is available (non-null). It should handle numerical and categorical data. You may need to do some encoding on the non-null values first. You can also look at creating and modelling with multiple imputed datasets using different ...


0

df.columns is incorrect because after One-hot-encoding you have more columns with different names. In your example instead of Sex you have two columns for the actual values and instead of Embarked you have three. The whole point of the pipeline is to create those additional columns so why do you want to drop them? I do not know where you define df.columns ...


0

For your specific case I would recommend the "grouped mode" because that would be the value you are interested in imputing (I did the same for this kaggle challenge). On more general terms we have to understand the scale of each variable. We often talk about categorical data but in more detail we have to differentiate between "nominal data&...


0

When ever you fit the model (let say regression ) model.fit(x,y) To get model parameters you can try model.params_ This gives the values of b0,b1 in y=b0+b1*x


1

Try plotting log of your residual instead, then you can get a clearer picture on how large your residuals are. With the gigantic outlier in your current plot, it is hard to see how large other residuals are. And some of yours are really large.


0

model.predict(img) requires a batch axis, i.e. img needs to have a shape of (BS, H, W, C). Try model.predict(np.expand_dims(img,0)).


1

Use selector.get_support (Documentation). This will give you a mask of the features that were selected and features that were discarded. >>> selector.get_support() array([False, True, True, False]) And here is how you get your selected features indices >>> [ i for i, f in enumerate(selector.get_support()) if f ] [1, 2]


Top 50 recent answers are included