# Tag Info

0

Slice Dataframe using loc or iloc. Here it will be iloc. Replace with X.iloc[:,1:3] at both the places

1

One option is to use xLearn, a scikit-learn compatible package for FFM, which handles that issue automatically. If you require feature hashing, you can write a custom feature hashing function: import hashlib def hash_str(string: str, n_bins: int) -> int: return int(hashlib.md5(string.encode('utf8')).hexdigest(), 16) % (n_bins-1) + 1

0

There is a way to measure the accuracy of a regression task. That is to transform it into a classification task. The first approach is to make the model output prediction interval instead of a number. This is especially possible with decision trees, but it's better to use Quantile Decision Trees. Then you could have, say, a 95% prediction interval for each ...

1

It seems good. (Understanding that you are not getting any error) You are fitting your model in some data, then evaluating on other (basic validation). Now you have to find data that have the same format and similar distribution and predict there. You can have a look at the random forest documentation to see what else you can do https://scikit-learn.org/...

0

There are a few approaches that allow you to do basic ML modelling using a GPU. First of all, in the code as you presented it, the tensorflow MirroredStrategy unfortunately has no effect. It will only work with tensorflow models themselves, not those from sklearn. In fact, sklearn does not offer any GPU support at all. 1. CUML An Nvidia library that ...

0

import pandas as pd import numpy as np from sklearn.preprocessing import StandardScaler from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split data = pd.read_csv("http://www.statsci.org/data/general/uscrime.txt", sep="\t") x = data.loc[:, data.columns != 'Crime'].to_numpy() y = np.squeeze(data.loc[:,'Crime']....

1

All problems due to "a very imbalanced dataset". Please look at the definition of recall and precision. Based on your score I could say that you a very small set of values labeled as positive, which are classified correctly($precision=\frac{TP}{TP+FP}$). But you have a very big set of values labeled as negative, which have influence on $recall=\frac{TP}{TP+... 0 It will depend completely on your feature engineering so I can think that in this case your model is maybe only predicting the mean or median of your target. Also, it might help try using other kinds of models since you are trying to predict the counts of an event on a determined period of time, so it might be useful to use Poisson models that are in ... 0 Rule base approach is always good starting point for initially as you might not have good amount of records to build classifier but be ready for certain false positive results. Let's understand the false positive situation in case of rule base. In your conversational dialogue you have put keywords like dinner, home, evening. But in certain news case like ... 0 In the regression case, the best option would be to use$R^2$or Adjusted$R^2$. Also, you can use Other techniques to see if the model is behaving sensibly are related to the analysis of the residuals (the difference between actual y-value and predicted y-value) of the data points used to build the model such as Mean Squared Error(MSE), Root-Mean-Squared-... 2 Accuracy in ML vocabulary is used mostly for Classification problem i.e. Count of correct prediction out of total. In a common speaking language, it will mean the predictive correctness of the model esp. on test data. My understanding is that it's same as Score which can be calculated simply asregressor.score(X_test, Y_test) I am assuming that you are ... 0 Majorly 3 types of machine learning model are present clustering, classification and regression. Each of them have different way of calculating accuracy. In case of regression following are the metrics available in scikit learn package. For more metrics check this LINK mean_absolute_error mean_squared_error mean_squared_log_error median_absolute_error ... 0 Since you want to save the training min/max and use those to replace inf's in the test set, you need a custom transformer. To build a robust transformer, you should use some of sklearn's validation functions. And it's best to work in numpy, since as you point out an earlier transformer in a pipeline will have already converted an input dataframe to an ... 0 I assume you are trying to find a suitable distance metric based on features of different areas (although spatial distances might also easily be plugged in). In that case, I would first try to make sure the different features are correctly scaled, for example, to zero mean and unit variance. If the result does not seem right, I would also try looking at ... 0 It depends on which kind of task you want to perform at the end. From what I understood from your question, you have emails with same pattern occurring in the beginning as well as at the end. You want to perform a classification tasks on the emails based on the real sense of email excluding subject and conclusion. There are multiple ways you can do this, for ... 0 If they are highly correlated, probably you can not easily tell which feature leads to a happy country. My suggestion is to perform multicollinearity test before fitting any model to remove highly correlated features. After that, there a chance that you be able to get more insights about the pattern in your data. 2 It depends exactly on which kind of patterns you are talking about. Are they deterministic? That is, they are all the same, so you want to get everything after Dear, or before Att / Best Regards, you can explore regular expression patterns. In python, you can use re library: https://docs.python.org/3/library/re.html There are books about regular ... 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. 0 # train pred = model.fit(X_train, y_train) Here you are juts fitting the model, not making any predictions. accuracy_score(X_test,pred) Here you are supposed to pass y_test, and y_predict, since its the output you are comparing not the input data. Try this- pred = model.predict(X_test) accuracy_score(X_test,pred) -1 The purpose of a model will always be to minimize loss. not increase accuracy. so parameters of any model using any optimizer like adam optimizer(a common optimizer), will try to gain momentum towards parameter values where the loss is least, in other words "minimum deviation". models can overfit when: data is small Train to Test ratio imbalance model has ... 1 So order here means how many possible combinations of labels you want to compare (e.g., order=1 would by how often does each label appear, order=2 would be how often any two combinations of labels appear with values like 5,5 meaning "rows that only have a label in index 5 and no other label, and where the max order should be the number of labels you have --> ... 18 If you properly isolate your test set such that it doesn't affect training, you should only look at the test set accuracy. Here are some of my remarks: Having your model being really good on the train set is not a bad thing in itself. On the contrary, if the test accuracy is identical, you want to pick the model with the better train accuracy. You want to ... 0 Having profiled and stepped through sklearn´s code, I´ve got some answers. The summary: Contrary to what has been suggested, sklearn's ElasticNetCV()'s poor scalability to n_jobs is not due to: the overhead of launching threads or processes. SequentialBackend always being used irrespective of n_jobs. (I cannot reproduce this problem as stated in n1tk's ... 0 You should definitely not use one hot encoding with values which represent numbers, as this removes the natural order between your intervals. So these values should be represented as numbers: Either with the average of the limits indeed Or a simple integer encoding of the intervals, e.g. tumor sizes 0-4, 5-9, 10-14,... would be represented as 0,1,2,... 0 Scikit-learn v0.23 now has PoissonRegressor: https://scikit-learn.org/0.23/auto_examples/release_highlights/plot_release_highlights_0_23_0.html#generalized-linear-models-and-poisson-loss-for-gradient-boosting 2 The best option for encoding - OneHot, because if you use Label encoding you indicate that categorical values are comparable(for example label 1 < label 2), which most probably it's not true. One hot encoding create columns for each specific value in the column, moreover, these columns are linearly independent, so you don't create fake order between ... 1 If you carry out grid search cross validation on your X data (containing 800k samples), you do not need to make another train_test_split before fitting your model, since the grid search CV strategy already makes several splits (as many as the 'cv' parameter value, check it out here), and then you validate with data never seen before by the model (i.e. the ... 1 Your hyperparameters are chosen based on the whole set of examples, and thus there is a leakage of information of the test set into the model. The validation will, therefore, be too optimistic (as you suspected). What could be fixed is instead of: clf.fit(X, y) just use clf.fit(x_train, y_train) As you suggested yourself already. After that line, ... 1 The description says- ".................the features generated by each transformer will be concatenated to form a single feature space" Based on this I would not expect it to "reduce" the number of columns. On top of my mind, another pipeline which computes on dates column and feeds its output to numeric column transformation in columnTransformation. 8 See the docs: You need to add an intercept to statsmodels manually, while it is added automatically in sklearn. import altair as alt import numpy as np import pandas as pd from sklearn.linear_model import LinearRegression import statsmodels.api as sm np.random.seed(0) data = pd.DataFrame({ 'Date': pd.date_range('1990-01-01', freq='D', periods=50), 'NDVI': ... 1 You could use class KerasClassifier from keras.wrappers.scikit_learn, which wraps a Keras model in a scikit-learn interface, so that it can be used like other scikit-learn models and then you could evaluate it with scikit-learn's scoring functions, e.g.: from keras.wrappers.scikit_learn import KerasClassifier from sklearn.metrics import roc_curve, auc ... 1 The error is self-explanatory. You provide the model with only 3 features whereas it needs 12 features. In model.py you select 3 features from the dataset, indeed. However, you apply one-hot encoding that creates new columns. Each new column describes only one category and contains values 0 and 1: whether this category is observed in a sample or not. And the ... 0 Classification report gives a perspective of your model performance. The 1st row shows the scores for class 0. The column 'support' displays how many object of class 0 were in the test set. The 2nd row provides info on the model performance for class 1. Recall for each class is calculated as follows: True Positives/(True Positives + False Negatives) E.g., ... 3 Yes. With y being a 1d array of integers (as after LabelEncoder), sklearn treats it as a multiclass classification problem. With y being a 2d binary array (as after LabelBinarizer), sklearn treats it as a multilabel problem. Presumably, the multilabel model is predicting no labels for some of the rows. (With your actual data not being multilabel, the sum ... 1 As per the documentation, whenever the transformer expects a 1D array as input, the columns were specified as a string ("xxx"). For the transformers which expects 2D data, we need to specify the column as a list of strings (["xxx"]). so the code below will work. ## Important: i have passed the columns a string to CV and list of columns to OHE transformer=... 0 Feature hashing just applies a fixed hash function to its input strings; it doesn't need to have seen any data. Note the docstring for the fit method: No-op. This method doesn’t do anything. It exists purely for compatibility with the scikit-learn transformer API. There may be collisions, and you won't know it with unseen data; your model will be ... 1 LabelEncoder is meant for the labels (target, dependent variable), not for the features. OrdinalEncoder can be used for features, and so can take a 2d array rather than the 1d array LabelEncoder requires, and so you can use a single transformer for all your categorical columns. (You can use a ColumnTransformer to select those categorical columns, if you ... 2 Would try to answer based on experience and understandings of parallel computing in production for DS/ML models: Answer to your questions as high level: Does the simple program above give you better performance with increasing n_jobs when you run it? answer: Yes and can be seen bellow in results. On what OS / setup? answer: OS:ubuntu, 2xCPUsx16Cores+... 0 After trying to recreate the issue with random numbers (and failing initially), I figured out that the problem comes from the fact that the x_train data that I'm using contains columns that have a very small, near-zero values. To recreate, the first section is only run once: scale = 0.0001 # making this larger eliminates the issue x_train = np.random.... 2 When I ran your script, I got the same impression, that n_jobs was hurting you performance. However, you have to consider that parallelizing the cross-validation would only benefit if you have more data samples. With few data, the communication overhead indeed is more expensive than the processing cost involved on the task. I tried your script with more ... 0 Take a look at this: https://stats.stackexchange.com/questions/335936/choosing-the-correct-seed-for-reproducible-research-results?fbclid=IwAR1i1-WjSYxCQrV5GU5-LHD6rU7VYfoE_X-xg3J7zmQa2o2Obnf27CDfwuY there is a very thorough answer that might be of use. 1 In terms of evaluation, the best you can do with a very small amount of data is repeating$k$-fold cross-validation many times (i.e. very large$k\$), and consider the whole distribution of scores as the performance (in particular take into account the variance across folds). It's going to be difficult anyway to obtain a reliable measure of performance with ...

1

I've done a bit of searching and have actually found a solution to this using tsfresh. You can find the sklearn transformers here: https://tsfresh.readthedocs.io/en/latest/text/sklearn_transformers.html Here is the code snippet from the example. pipeline = Pipeline( [ ('augmenter', RelevantFeatureAugmenter(column_id='id', column_sort='time')), ...

2

value represents the number of items in each class. If you look at the top node, you should view it as: There are: 35100 samples of class 0 16288 samples of class 1 which sums up to 51388 samples total

0

SimpleImputer drops columns consisting entirely of missing values. It is indeed unpleasant when trying to associate original columns; the sklearn devs have been discussing this: https://github.com/scikit-learn/scikit-learn/issues/16426 Vincent's answer is good, if you are working directly: just detect and remove the offending all-missing columns, since ...

3

I've got the same issue today, and it's a shame your post got no answers. I think this question is not well addressed in the sklearn documentation. I can show you my workaround to this issue: headers = X.columns.values X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2) empty_train_columns = [] for col in X_train.columns.values: # ...

1

Your dataset is extremely unbalanced, and most of the models would just ignore these 37 samples. After all, failing 0.7% of any test seems to be an extremely good result! There are several ways to address the imbalanced dataset. I suggest two options: (1) Assign a very high penalty on misclassification of positive samples -- your loss function would be ...

0

Transformation So you have text, DateTime, categorical and numerical data. text data can be transformed into numerical data, using sklearn.feature_extraction.text module for instance ; datetime-string can be transformed using pandas.to_datetime, then using dt.dayofweek ; categorical data can be one-hot-encoded ; numerical data stay like that or you can bin ...

0

Neural nets are only one of many different possible solutions. Another possible solution that a lot of times work better than neural networks is using Gradient Boosted Trees. (Usually they are better when the input does not contain structural relationships, e.g. when the input features do not need to be ordered) There are countless machine learning methods ...

1

A fundamentally linear model like logistic regression will never work well, because its assumptions are not at all true for your data set. It presumes that probability (OK, really, log odds) of being positive or negative changes linearly in each input, but, it alternates with each integer value in your input. KNN's assumption likewise does not match. For ...

Top 50 recent answers are included